New test.
[mono.git] / mcs / class / System / System.Security.Cryptography.X509Certificates / X509Certificate2Collection.cs
1 //
2 // System.Security.Cryptography.X509Certificates.X509Certificate2Collection class
3 //
4 // Authors:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //      Tim Coleman (tim@timcoleman.com)
7 //
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)
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 #if NET_2_0 && SECURITY_DEP
33
34 using System.Collections;
35
36 namespace System.Security.Cryptography.X509Certificates {
37
38         public class X509Certificate2Collection : X509CertificateCollection {
39
40                 // constructors
41
42                 public X509Certificate2Collection ()
43                 {
44                 }
45
46                 public X509Certificate2Collection (X509Certificate2Collection certificates)
47                 {
48                         AddRange (certificates);
49                 }
50
51                 public X509Certificate2Collection (X509Certificate2 certificate) 
52                 {
53                         Add (certificate);
54                 }
55
56                 public X509Certificate2Collection (X509Certificate2[] certificates) 
57                 {
58                         AddRange (certificates);
59                 }
60
61                 // properties
62
63                 public new X509Certificate2 this [int index] {
64                         get {
65                                 if (index < 0)
66                                         throw new ArgumentOutOfRangeException ("negative index");
67                                 if (index >= InnerList.Count)
68                                         throw new ArgumentOutOfRangeException ("index >= Count");
69                                 return (X509Certificate2) InnerList [index];
70                         }
71                         set { InnerList [index] = value; }
72                 }
73
74                 // methods
75
76                 public int Add (X509Certificate2 certificate)
77                 {
78                         if (certificate == null)
79                                 throw new ArgumentNullException ("certificate");
80
81                         return InnerList.Add (certificate);
82                 }
83
84                 // note: transactional
85                 public void AddRange (X509Certificate2[] certificates) 
86                 {
87                         if (certificates == null)
88                                 throw new ArgumentNullException ("certificates");
89
90                         for (int i=0; i < certificates.Length; i++)
91                                 InnerList.Add (certificates [i]);
92                 }
93
94                 // note: transactional
95                 public void AddRange (X509Certificate2Collection certificates) 
96                 {
97                         if (certificates == null)
98                                 throw new ArgumentNullException ("certificates");
99
100                         InnerList.AddRange (certificates);
101                 }
102
103                 public bool Contains (X509Certificate2 certificate) 
104                 {
105                         if (certificate == null)
106                                 throw new ArgumentNullException ("certificate");
107
108                         foreach (X509Certificate2 c in InnerList) {
109                                 if (certificate.Equals (c))
110                                         return true;
111                         }
112                         return false;
113                 }
114
115                 public byte[] Export (X509ContentType contentType) 
116                 {
117                         return null;
118                 }
119
120                 public byte[] Export (X509ContentType contentType, string password) 
121                 {
122                         return null;
123                 }
124
125                 public X509Certificate2Collection Find (X509FindType findType, object findValue, bool validOnly) 
126                 {
127                         return null;
128                 }
129
130                 public new X509Certificate2Enumerator GetEnumerator () 
131                 {
132                         return null;
133                 }
134
135                 public void Import (byte[] rawData) 
136                 {
137                 }
138
139                 public void Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
140                 {
141                 }
142
143                 public void Import (string fileName) 
144                 {
145                 }
146
147                 public void Import (string fileName, string password, X509KeyStorageFlags keyStorageFlags) 
148                 {
149                 }
150
151                 public void Insert (int index, X509Certificate2 certificate) 
152                 {
153                         if (certificate == null)
154                                 throw new ArgumentNullException ("certificate");
155                         if (index < 0)
156                                 throw new ArgumentOutOfRangeException ("negative index");
157                         if (index >= InnerList.Count)
158                                 throw new ArgumentOutOfRangeException ("index >= Count");
159
160                         InnerList.Insert (index, certificate);
161                 }
162
163                 public void Remove (X509Certificate2 certificate) 
164                 {
165                         if (certificate == null)
166                                 throw new ArgumentNullException ("certificate");
167
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
173                                         return;
174                                 }
175                         }
176                 }
177
178                 // note: transactional
179                 public void RemoveRange (X509Certificate2[] certificates)
180                 {
181                         if (certificates == null)
182                                 throw new ArgumentNullException ("certificate");
183                 }
184
185                 // note: transactional
186                 public void RemoveRange (X509Certificate2Collection certificates) 
187                 {
188                         if (certificates == null)
189                                 throw new ArgumentNullException ("certificate");
190                 }
191         }
192 }
193
194 #endif