2 // System.Security.Cryptography.X509Certificates.X509Store class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #if NET_2_0 && SECURITY_DEP
32 using Mono.Security.X509;
34 namespace System.Security.Cryptography.X509Certificates {
36 public sealed class X509Store {
39 private StoreLocation _location;
40 private X509Certificate2Collection _certs;
41 private OpenFlags _flags;
45 // BUG: MY when using this constructor - My when using StoreName.My
47 : this ("MY", StoreLocation.CurrentUser)
51 public X509Store (string storeName)
52 : this (storeName, StoreLocation.CurrentUser)
56 public X509Store (StoreName storeName)
57 : this (StoreNameToString (storeName), StoreLocation.CurrentUser)
61 public X509Store (StoreLocation storeLocation)
62 : this ("MY", storeLocation)
66 public X509Store (StoreName storeName, StoreLocation storeLocation)
67 : this (StoreNameToString (storeName), StoreLocation.CurrentUser)
71 public X509Store (IntPtr storeHandle)
73 // CryptoAPI compatibility (unmanaged handle)
74 throw new NotSupportedException ();
77 [MonoTODO ("call Mono.Security.X509.X509Store*")]
78 public X509Store (string storeName, StoreLocation storeLocation)
80 if (storeName == null)
81 throw new ArgumentNullException ("storeName");
84 _location = storeLocation;
89 public X509Certificate2Collection Certificates {
92 _certs = new X509Certificate2Collection ();
97 public StoreLocation Location {
98 get { return _location; }
102 get { return _name; }
105 private bool ReadOnly {
106 get { return ((_flags & OpenFlags.ReadOnly) != OpenFlags.ReadOnly); }
109 public IntPtr StoreHandle {
110 get { return IntPtr.Zero; }
115 private static string StoreNameToString (StoreName sn)
118 case StoreName.CertificateAuthority:
121 return sn.ToString ();
125 [MonoTODO ("call Mono.Security.X509.X509Store*")]
126 public void Add (X509Certificate2 certificate)
128 if (certificate == null)
129 throw new ArgumentNullException ("certificate");
133 new Mono.Security.X509.X509Certificate (certificate.RawData);
134 // Mono.Security.X509.X509Certificate x = new Mono.Security.X509.X509Certificate (certificate.RawData);
138 throw new CryptographicException ("couldn't add certificate");
143 public void AddRange (X509Certificate2Collection certificates)
145 if (certificates == null)
146 throw new ArgumentNullException ("certificates");
149 foreach (X509Certificate2 certificate in certificates) {
155 [MonoTODO ("call Mono.Security.X509.X509Store*")]
160 [MonoTODO ("call Mono.Security.X509.X509Store*")]
161 public void Open (OpenFlags flags)
164 /*bool readOnly = ((flags & OpenFlags.ReadOnly) == OpenFlags.ReadOnly);
165 bool create = !((flags & OpenFlags.OpenExistingOnly) == OpenFlags.OpenExistingOnly);
166 bool archive = ((flags & OpenFlags.IncludeArchived) == OpenFlags.IncludeArchived);*/
170 [MonoTODO ("call Mono.Security.X509.X509Store*")]
171 public void Remove (X509Certificate2 certificate)
173 if (certificate == null)
174 throw new ArgumentNullException ("certificate");
178 //Mono.Security.X509.X509Certificate x = new Mono.Security.X509.X509Certificate (certificate.RawData);
182 throw new CryptographicException ("couldn't remove certificate");
187 public void RemoveRange (X509Certificate2Collection certificates)
189 if (certificates == null)
190 throw new ArgumentNullException ("certificates");
192 if (!this.ReadOnly) {
193 foreach (X509Certificate2 certificate in certificates) {
194 Remove (certificate);