2 // System.Security.Cryptography.X509Certificates.X509CertificateCollection
5 // Lawrence Pit (loz@cable.a2000.nl)
6 // Sebastien Pouliot (spouliot@motus.com)
8 // Copyright (C) 2004 Novell (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.
33 using System
.Collections
;
34 using System
.Globalization
;
35 using System
.Security
.Cryptography
;
37 namespace System
.Security
.Cryptography
.X509Certificates
{
40 public class X509CertificateCollection
: CollectionBase
, IEnumerable
{
42 public X509CertificateCollection ()
46 public X509CertificateCollection (X509Certificate
[] value)
51 public X509CertificateCollection (X509CertificateCollection
value)
58 public X509Certificate
this [int index
] {
59 get { return (X509Certificate) InnerList [index]; }
60 set { InnerList [index] = value; }
65 public int Add (X509Certificate
value)
68 throw new ArgumentNullException ("value");
70 return InnerList
.Add (value);
73 public void AddRange (X509Certificate
[] value)
76 throw new ArgumentNullException ("value");
78 for (int i
= 0; i
< value.Length
; i
++)
79 InnerList
.Add (value [i
]);
82 public void AddRange (X509CertificateCollection
value)
85 throw new ArgumentNullException ("value");
87 for (int i
= 0; i
< value.InnerList
.Count
; i
++)
88 InnerList
.Add (value [i
]);
91 public bool Contains (X509Certificate
value)
96 byte[] hash
= value.GetCertHash ();
97 for (int i
=0; i
< InnerList
.Count
; i
++) {
98 X509Certificate x509
= (X509Certificate
) InnerList
[i
];
99 if (Compare (x509
.GetCertHash (), hash
))
105 public void CopyTo (X509Certificate
[] array
, int index
)
107 InnerList
.CopyTo (array
, index
);
110 public new X509CertificateEnumerator
GetEnumerator ()
112 return new X509CertificateEnumerator (this);
115 IEnumerator IEnumerable
.GetEnumerator ()
117 return InnerList
.GetEnumerator ();
120 public override int GetHashCode ()
122 return InnerList
.GetHashCode ();
125 public int IndexOf (X509Certificate
value)
127 return InnerList
.IndexOf (value);
130 public void Insert (int index
, X509Certificate
value)
132 InnerList
.Insert (index
, value);
135 public void Remove (X509Certificate
value)
138 throw new ArgumentNullException ("value");
139 if (IndexOf (value) == -1) {
140 throw new ArgumentException ("value",
141 Locale
.GetText ("Not part of the collection."));
144 InnerList
.Remove (value);
149 private bool Compare (byte[] array1
, byte[] array2
)
151 if ((array1
== null) && (array2
== null))
153 if ((array1
== null) || (array2
== null))
155 if (array1
.Length
!= array2
.Length
)
157 for (int i
=0; i
< array1
.Length
; i
++) {
158 if (array1
[i
] != array2
[i
])
166 public class X509CertificateEnumerator
: IEnumerator
{
168 private IEnumerator enumerator
;
172 public X509CertificateEnumerator (X509CertificateCollection mappings
)
174 enumerator
= ((IEnumerable
) mappings
).GetEnumerator ();
179 public X509Certificate Current
{
180 get { return (X509Certificate) enumerator.Current; }
183 object IEnumerator
.Current
{
184 get { return enumerator.Current; }
189 bool IEnumerator
.MoveNext ()
191 return enumerator
.MoveNext ();
194 void IEnumerator
.Reset ()
199 public bool MoveNext ()
201 return enumerator
.MoveNext ();