2 // Based on System.Security.Cryptography.X509Certificates.X509CertificateCollection
6 // Lawrence Pit (loz@cable.a2000.nl)
7 // Sebastien Pouliot <sebastien@ximian.com>
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System
.Collections
;
36 namespace Mono
.Security
.X509
{
44 class X509CertificateCollection
: CollectionBase
, IEnumerable
{
46 public X509CertificateCollection ()
50 public X509CertificateCollection (X509Certificate
[] value)
55 public X509CertificateCollection (X509CertificateCollection
value)
62 public X509Certificate
this [int index
] {
63 get { return (X509Certificate) InnerList [index]; }
64 set { InnerList [index] = value; }
69 public int Add (X509Certificate
value)
72 throw new ArgumentNullException ("value");
74 return InnerList
.Add (value);
77 public void AddRange (X509Certificate
[] value)
80 throw new ArgumentNullException ("value");
82 for (int i
= 0; i
< value.Length
; i
++)
83 InnerList
.Add (value [i
]);
86 public void AddRange (X509CertificateCollection
value)
89 throw new ArgumentNullException ("value");
91 for (int i
= 0; i
< value.InnerList
.Count
; i
++)
92 InnerList
.Add (value [i
]);
95 public bool Contains (X509Certificate
value)
97 return (IndexOf (value) != -1);
100 public void CopyTo (X509Certificate
[] array
, int index
)
102 InnerList
.CopyTo (array
, index
);
105 public new X509CertificateEnumerator
GetEnumerator ()
107 return new X509CertificateEnumerator (this);
110 IEnumerator IEnumerable
.GetEnumerator ()
112 return InnerList
.GetEnumerator ();
115 public override int GetHashCode ()
117 return InnerList
.GetHashCode ();
120 public int IndexOf (X509Certificate
value)
123 throw new ArgumentNullException ("value");
125 byte[] hash
= value.Hash
;
126 for (int i
=0; i
< InnerList
.Count
; i
++) {
127 X509Certificate x509
= (X509Certificate
) InnerList
[i
];
128 if (Compare (x509
.Hash
, hash
))
134 public void Insert (int index
, X509Certificate
value)
136 InnerList
.Insert (index
, value);
139 public void Remove (X509Certificate
value)
141 InnerList
.Remove (value);
146 private bool Compare (byte[] array1
, byte[] array2
)
148 if ((array1
== null) && (array2
== null))
150 if ((array1
== null) || (array2
== null))
152 if (array1
.Length
!= array2
.Length
)
154 for (int i
=0; i
< array1
.Length
; i
++) {
155 if (array1
[i
] != array2
[i
])
163 public class X509CertificateEnumerator
: IEnumerator
{
165 private IEnumerator enumerator
;
169 public X509CertificateEnumerator (X509CertificateCollection mappings
)
171 enumerator
= ((IEnumerable
) mappings
).GetEnumerator ();
176 public X509Certificate Current
{
177 get { return (X509Certificate) enumerator.Current; }
180 object IEnumerator
.Current
{
181 get { return enumerator.Current; }
186 bool IEnumerator
.MoveNext ()
188 return enumerator
.MoveNext ();
191 void IEnumerator
.Reset ()
196 public bool MoveNext ()
198 return enumerator
.MoveNext ();