2 // System.Security.Cryptography.X509Certificates.X509Certificate2Collection class
5 // Sebastien Pouliot <sebastien@ximian.com>
6 // Tim Coleman (tim@timcoleman.com)
8 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
9 // Copyright (C) Tim Coleman, 2004
10 // Copyright (C) 2005 Novell Inc. (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #if NET_2_0 && SECURITY_DEP
34 using System.Collections;
36 namespace System.Security.Cryptography.X509Certificates {
38 public class X509Certificate2Collection : X509CertificateCollection {
42 public X509Certificate2Collection ()
46 public X509Certificate2Collection (X509Certificate2Collection certificates)
48 AddRange (certificates);
51 public X509Certificate2Collection (X509Certificate2 certificate)
56 public X509Certificate2Collection (X509Certificate2[] certificates)
58 AddRange (certificates);
63 public new X509Certificate2 this [int index] {
66 throw new ArgumentOutOfRangeException ("negative index");
67 if (index >= InnerList.Count)
68 throw new ArgumentOutOfRangeException ("index >= Count");
69 return (X509Certificate2) InnerList [index];
71 set { InnerList [index] = value; }
76 public int Add (X509Certificate2 certificate)
78 if (certificate == null)
79 throw new ArgumentNullException ("certificate");
81 return InnerList.Add (certificate);
84 // note: transactional
85 public void AddRange (X509Certificate2[] certificates)
87 if (certificates == null)
88 throw new ArgumentNullException ("certificates");
90 for (int i=0; i < certificates.Length; i++)
91 InnerList.Add (certificates [i]);
94 // note: transactional
95 public void AddRange (X509Certificate2Collection certificates)
97 if (certificates == null)
98 throw new ArgumentNullException ("certificates");
100 InnerList.AddRange (certificates);
103 public bool Contains (X509Certificate2 certificate)
105 if (certificate == null)
106 throw new ArgumentNullException ("certificate");
108 foreach (X509Certificate2 c in InnerList) {
109 if (certificate.Equals (c))
115 public byte[] Export (X509ContentType contentType)
120 public byte[] Export (X509ContentType contentType, string password)
125 public X509Certificate2Collection Find (X509FindType findType, object findValue, bool validOnly)
130 public new X509Certificate2Enumerator GetEnumerator ()
135 public void Import (byte[] rawData)
139 public void Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
143 public void Import (string fileName)
147 public void Import (string fileName, string password, X509KeyStorageFlags keyStorageFlags)
151 public void Insert (int index, X509Certificate2 certificate)
153 if (certificate == null)
154 throw new ArgumentNullException ("certificate");
156 throw new ArgumentOutOfRangeException ("negative index");
157 if (index >= InnerList.Count)
158 throw new ArgumentOutOfRangeException ("index >= Count");
160 InnerList.Insert (index, certificate);
163 public void Remove (X509Certificate2 certificate)
165 if (certificate == null)
166 throw new ArgumentNullException ("certificate");
168 for (int i=0; i < InnerList.Count; i++) {
169 X509Certificate2 c = (X509Certificate2) InnerList [i];
170 if (certificate.Equals (c)) {
171 InnerList.RemoveAt (i);
172 // only first instance is removed
178 // note: transactional
179 public void RemoveRange (X509Certificate2[] certificates)
181 if (certificates == null)
182 throw new ArgumentNullException ("certificate");
185 // note: transactional
186 public void RemoveRange (X509Certificate2Collection certificates)
188 if (certificates == null)
189 throw new ArgumentNullException ("certificate");