2 // X509Store.cs - System.Security.Cryptography.X509Certificates.X509Store
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 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.
34 using Mono
.Security
.X509
;
36 namespace System
.Security
.Cryptography
.X509Certificates
{
38 public sealed class X509Store
{
41 private StoreLocation _location
;
42 private X509CertificateExCollection _certs
;
43 private OpenFlags _flags
;
47 // BUG: MY when using this constructor - My when using StoreName.My
49 : this ("MY", StoreLocation
.CurrentUser
)
53 public X509Store (string storeName
)
54 : this (storeName
, StoreLocation
.CurrentUser
)
58 public X509Store (StoreName storeName
)
59 : this (StoreNameToString (storeName
), StoreLocation
.CurrentUser
)
63 public X509Store (StoreLocation storeLocation
)
64 : this ("MY", storeLocation
)
68 public X509Store (StoreName storeName
, StoreLocation storeLocation
)
69 : this (StoreNameToString (storeName
), StoreLocation
.CurrentUser
)
73 [MonoTODO ("call Mono.Security.X509.X509Store*")]
74 public X509Store (string storeName
, StoreLocation storeLocation
)
76 if (storeName
== null)
77 throw new ArgumentNullException ("storeName");
80 _location
= storeLocation
;
85 public X509CertificateExCollection Certificates
{
88 _certs
= new X509CertificateExCollection ();
93 public StoreLocation Location
{
94 get { return _location; }
101 private bool ReadOnly
{
102 get { return ((_flags & OpenFlags.ReadOnly) != OpenFlags.ReadOnly); }
107 private static string StoreNameToString (StoreName sn
)
110 case StoreName
.CertificateAuthority
:
113 return sn
.ToString ();
117 [MonoTODO ("call Mono.Security.X509.X509Store*")]
118 public void Add (X509CertificateEx certificate
)
120 if (certificate
== null)
121 throw new ArgumentNullException ("certificate");
125 Mono
.Security
.X509
.X509Certificate x
= new Mono
.Security
.X509
.X509Certificate (certificate
.RawData
);
129 throw new CryptographicException ("couldn't add certificate");
134 public void AddRange (X509CertificateExCollection certificates
)
136 if (certificates
== null)
137 throw new ArgumentNullException ("certificates");
140 foreach (X509CertificateEx certificate
in certificates
) {
146 [MonoTODO ("call Mono.Security.X509.X509Store*")]
151 [MonoTODO ("call Mono.Security.X509.X509Store*")]
152 public void Open (OpenFlags flags
)
155 bool readOnly
= ((flags
& OpenFlags
.ReadOnly
) == OpenFlags
.ReadOnly
);
156 bool create
= !((flags
& OpenFlags
.OpenExistingOnly
) == OpenFlags
.OpenExistingOnly
);
157 bool archive
= ((flags
& OpenFlags
.IncludeArchived
) == OpenFlags
.IncludeArchived
);
161 [MonoTODO ("call Mono.Security.X509.X509Store*")]
162 public void Remove (X509CertificateEx certificate
)
164 if (certificate
== null)
165 throw new ArgumentNullException ("certificate");
169 Mono
.Security
.X509
.X509Certificate x
= new Mono
.Security
.X509
.X509Certificate (certificate
.RawData
);
173 throw new CryptographicException ("couldn't remove certificate");
178 public void RemoveRange (X509CertificateExCollection certificates
)
180 if (certificates
== null)
181 throw new ArgumentNullException ("certificates");
183 if (!this.ReadOnly
) {
184 foreach (X509CertificateEx certificate
in certificates
) {
185 Remove (certificate
);