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
26 class X509Extensions : ICollection, IEnumerable {
28 private ArrayList extensions;
29 private bool readOnly;
31 public X509Extensions ()
33 extensions = new ArrayList ();
36 public X509Extensions (ASN1 asn1) : this ()
42 throw new Exception ("Invalid extensions format");
43 for (int i=0; i < asn1.Count; i++) {
44 X509Extension extension = new X509Extension (asn1 [i]);
45 extensions.Add (extension);
51 get { return extensions.Count; }
55 public bool IsSynchronized {
56 get { return extensions.IsSynchronized; }
60 public object SyncRoot {
61 get { return extensions.SyncRoot; }
65 public void CopyTo (Array array, int index)
67 extensions.CopyTo (array, index);
71 public IEnumerator GetEnumerator ()
73 return extensions.GetEnumerator ();
76 public X509Extension this [int index] {
77 get { return (X509Extension) extensions [index]; }
80 public X509Extension this [string index] {
82 for (int i=0; i < extensions.Count; i++) {
83 X509Extension extension = (X509Extension) extensions [i];
84 if (extension.OID == index)
91 public void Add (X509Extension extension)
94 throw new NotSupportedException ("Extensions are read only");
95 extensions.Add (extension);
98 public byte[] GetBytes ()
100 if (extensions.Count < 1)
102 ASN1 sequence = new ASN1 (0x30);
103 for (int i=0; i < extensions.Count; i++) {
104 X509Extension x = (X509Extension) extensions [i];
105 sequence.Add (x.ASN1);
107 return sequence.GetBytes ();