2 // Based on System.Security.Cryptography.X509Certificates.X509CertificateCollection
6 // Lawrence Pit (loz@cable.a2000.nl)
7 // Sebastien Pouliot <sebastien@ximian.com>
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Collections
;
34 namespace Mono
.Security
.X509
{
42 class X509CertificateCollection
: CollectionBase
, IEnumerable
{
44 public X509CertificateCollection ()
48 public X509CertificateCollection (X509Certificate
[] value)
53 public X509CertificateCollection (X509CertificateCollection
value)
60 public X509Certificate
this [int index
] {
61 get { return (X509Certificate) InnerList [index]; }
62 set { InnerList [index] = value; }
67 public int Add (X509Certificate
value)
70 throw new ArgumentNullException ("value");
72 return InnerList
.Add (value);
75 public void AddRange (X509Certificate
[] value)
78 throw new ArgumentNullException ("value");
80 for (int i
= 0; i
< value.Length
; i
++)
81 InnerList
.Add (value [i
]);
84 public void AddRange (X509CertificateCollection
value)
87 throw new ArgumentNullException ("value");
89 for (int i
= 0; i
< value.InnerList
.Count
; i
++)
90 InnerList
.Add (value [i
]);
93 public bool Contains (X509Certificate
value)
95 return (IndexOf (value) != -1);
98 public void CopyTo (X509Certificate
[] array
, int index
)
100 InnerList
.CopyTo (array
, index
);
103 public new X509CertificateEnumerator
GetEnumerator ()
105 return new X509CertificateEnumerator (this);
108 IEnumerator IEnumerable
.GetEnumerator ()
110 return InnerList
.GetEnumerator ();
113 public override int GetHashCode ()
115 return InnerList
.GetHashCode ();
118 public int IndexOf (X509Certificate
value)
121 throw new ArgumentNullException ("value");
123 byte[] hash
= value.Hash
;
124 for (int i
=0; i
< InnerList
.Count
; i
++) {
125 X509Certificate x509
= (X509Certificate
) InnerList
[i
];
126 if (Compare (x509
.Hash
, hash
))
132 public void Insert (int index
, X509Certificate
value)
134 InnerList
.Insert (index
, value);
137 public void Remove (X509Certificate
value)
139 InnerList
.Remove (value);
144 private bool Compare (byte[] array1
, byte[] array2
)
146 if ((array1
== null) && (array2
== null))
148 if ((array1
== null) || (array2
== null))
150 if (array1
.Length
!= array2
.Length
)
152 for (int i
=0; i
< array1
.Length
; i
++) {
153 if (array1
[i
] != array2
[i
])
161 public class X509CertificateEnumerator
: IEnumerator
{
163 private IEnumerator enumerator
;
167 public X509CertificateEnumerator (X509CertificateCollection mappings
)
169 enumerator
= ((IEnumerable
) mappings
).GetEnumerator ();
174 public X509Certificate Current
{
175 get { return (X509Certificate) enumerator.Current; }
178 object IEnumerator
.Current
{
179 get { return enumerator.Current; }
184 bool IEnumerator
.MoveNext ()
186 return enumerator
.MoveNext ();
189 void IEnumerator
.Reset ()
194 public bool MoveNext ()
196 return enumerator
.MoveNext ();