Fri Nov 24 18:38:31 CET 2006 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Security.X509 / MemoryCertificateStore.cs
1 //\r
2 // MemoryCertificateStore.cs: Handles an in-memory certificate store.\r
3 //\r
4 // Author:\r
5 //      Sebastien Pouliot (spouliot@motus.com)\r
6 //\r
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)\r
8 //\r
9 \r
10 using System;\r
11 \r
12 namespace Microsoft.Web.Services.Security.X509 {\r
13 \r
14         internal class MemoryCertificateStore : ICertificateStore {\r
15 \r
16                 private string _storeName;\r
17                 private X509CertificateStore.StoreOpenFlags _flags;\r
18                 private X509CertificateStore.StoreLocation _location;\r
19                 private IntPtr _handle;\r
20                 private X509CertificateCollection _coll;\r
21 \r
22                 public MemoryCertificateStore (X509CertificateStore.StoreLocation location, string storeName, X509CertificateStore.StoreOpenFlags flags) \r
23                 {\r
24                         _location = location;\r
25                         _storeName = storeName;\r
26                         _flags = flags;\r
27                         _coll = new X509CertificateCollection ();\r
28                 }\r
29 \r
30                 public void Close () \r
31                 {\r
32                 }\r
33 \r
34                 public IntPtr Handle {\r
35                         get { return (IntPtr) _coll.GetHashCode (); }\r
36                 }\r
37 \r
38                 public X509CertificateCollection GetCollection () \r
39                 {\r
40                         if (_flags == X509CertificateStore.StoreOpenFlags.ReadOnly) {\r
41                                 // return a copy of the collection so changes aren't persisted\r
42                                 X509CertificateCollection copy = new X509CertificateCollection ();\r
43                                 foreach (X509Certificate x in _coll) {\r
44                                         copy.Add (x);\r
45                                 }\r
46                                 return copy;\r
47                         }\r
48                         else\r
49                                 return _coll;\r
50                 }\r
51         }\r
52 }\r