2 // X509Extensions.cs: Handles X.509 extensions.
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
11 using System.Collections;
15 namespace Mono.Security.X509 {
17 * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
19 * Note: 1..MAX -> There shouldn't be 0 Extensions in the ASN1 structure
21 public class X509Extensions : ICollection, IEnumerable {
23 private ArrayList extensions;
24 private bool readOnly;
26 public X509Extensions ()
28 extensions = new ArrayList ();
31 public X509Extensions (ASN1 asn1) : this ()
37 throw new Exception ("Invalid extensions format");
38 for (int i=0; i < asn1.Count; i++) {
39 X509Extension extension = new X509Extension (asn1 [i]);
40 extensions.Add (extension);
46 get { return extensions.Count; }
50 public bool IsSynchronized {
51 get { return extensions.IsSynchronized; }
55 public object SyncRoot {
56 get { return extensions.SyncRoot; }
60 public void CopyTo (Array array, int index)
62 extensions.CopyTo (array, index);
66 public IEnumerator GetEnumerator ()
68 return extensions.GetEnumerator ();
71 public X509Extension this [int index] {
72 get { return (X509Extension) extensions [index]; }
75 public X509Extension this [string index] {
77 for (int i=0; i < extensions.Count; i++) {
78 X509Extension extension = (X509Extension) extensions [i];
79 if (extension.OID == index)
86 public void Add (X509Extension extension)
89 throw new NotSupportedException ("Extensions are read only");
90 extensions.Add (extension);
93 public byte[] GetBytes ()
95 if (extensions.Count < 1)
97 ASN1 sequence = new ASN1 (0x30);
98 for (int i=0; i < extensions.Count; i++) {
99 X509Extension x = (X509Extension) extensions [i];
100 sequence.Add (x.ASN1);
102 return sequence.GetBytes ();