1 package org.bouncycastle.asn1.x509;
6 import org.bouncycastle.asn1.*;
8 public class X509Extensions
9 implements DEREncodable
12 * Subject Key Identifier
14 public static final DERObjectIdentifier SubjectKeyIdentifier = new DERObjectIdentifier("2.5.29.14");
19 public static final DERObjectIdentifier KeyUsage = new DERObjectIdentifier("2.5.29.15");
22 * Private Key Usage Period
24 public static final DERObjectIdentifier PrivateKeyUsagePeriod = new DERObjectIdentifier("2.5.29.16");
27 * Subject Alternative Name
29 public static final DERObjectIdentifier SubjectAlternativeName = new DERObjectIdentifier("2.5.29.17");
32 * Issuer Alternative Name
34 public static final DERObjectIdentifier IssuerAlternativeName = new DERObjectIdentifier("2.5.29.18");
39 public static final DERObjectIdentifier BasicConstraints = new DERObjectIdentifier("2.5.29.19");
44 public static final DERObjectIdentifier CRLNumber = new DERObjectIdentifier("2.5.29.20");
49 public static final DERObjectIdentifier ReasonCode = new DERObjectIdentifier("2.5.29.21");
52 * Hold Instruction Code
54 public static final DERObjectIdentifier InstructionCode = new DERObjectIdentifier("2.5.29.23");
59 public static final DERObjectIdentifier InvalidityDate = new DERObjectIdentifier("2.5.29.24");
64 public static final DERObjectIdentifier DeltaCRLIndicator = new DERObjectIdentifier("2.5.29.27");
67 * Issuing Distribution Point
69 public static final DERObjectIdentifier IssuingDistributionPoint = new DERObjectIdentifier("2.5.29.28");
74 public static final DERObjectIdentifier CertificateIssuer = new DERObjectIdentifier("2.5.29.29");
79 public static final DERObjectIdentifier NameConstraints = new DERObjectIdentifier("2.5.29.30");
82 * CRL Distribution Points
84 public static final DERObjectIdentifier CRLDistributionPoints = new DERObjectIdentifier("2.5.29.31");
87 * Certificate Policies
89 public static final DERObjectIdentifier CertificatePolicies = new DERObjectIdentifier("2.5.29.32");
94 public static final DERObjectIdentifier PolicyMappings = new DERObjectIdentifier("2.5.29.33");
97 * Authority Key Identifier
99 public static final DERObjectIdentifier AuthorityKeyIdentifier = new DERObjectIdentifier("2.5.29.35");
104 public static final DERObjectIdentifier PolicyConstraints = new DERObjectIdentifier("2.5.29.36");
106 private Hashtable extensions = new Hashtable();
107 private Vector ordering = new Vector();
108 private DERConstructedSequence seq;
111 * Constructor from DERConstructedSequence.
113 * the extensions are a list of constructed sequences, either with (OID, OctetString) or (OID, Boolean, OctetString)
115 public X509Extensions(
116 DERConstructedSequence seq)
120 Enumeration e = seq.getObjects();
122 while (e.hasMoreElements())
124 DERConstructedSequence s = (DERConstructedSequence)e.nextElement();
125 Enumeration e1 = s.getObjects();
127 if (s.getSize() == 3)
129 extensions.put(s.getObjectAt(0), new X509Extension((DERBoolean)s.getObjectAt(1), (DEROctetString)s.getObjectAt(2)));
133 extensions.put(s.getObjectAt(0), new X509Extension(false, (DEROctetString)s.getObjectAt(1)));
136 ordering.addElement(s.getObjectAt(0));
141 * constructor from a table of extensions.
143 * it's is assumed the table contains OID/String pairs.
145 public X509Extensions(
146 Hashtable extensions)
148 this(null, extensions);
152 * constructor from a table of extensions with ordering
154 * it's is assumed the table contains OID/String pairs.
156 public X509Extensions(
158 Hashtable extensions)
160 this.seq = new DERConstructedSequence();
162 if (ordering == null)
164 Enumeration e = extensions.keys();
166 ordering = this.ordering;
168 while (e.hasMoreElements())
170 this.ordering.addElement(e.nextElement());
174 Enumeration e = ordering.elements();
176 while (e.hasMoreElements())
178 DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
179 X509Extension ext = (X509Extension)extensions.get(oid);
180 DERConstructedSequence s = new DERConstructedSequence();
184 if (ext.isCritical())
186 s.addObject(new DERBoolean(true));
189 s.addObject(ext.getValue());
196 * return an Enumeration of the extension field's object ids.
198 public Enumeration oids()
200 return ordering.elements();
204 * return the extension represented by the object identifier
207 * @return the extension if it's present, null otherwise.
209 public X509Extension getExtension(
210 DERObjectIdentifier oid)
212 return (X509Extension)extensions.get(oid);
215 public DERObject getDERObject()
220 public int hashCode()
222 Enumeration e = extensions.keys();
225 while (e.hasMoreElements())
227 Object o = e.nextElement();
229 hashCode ^= o.hashCode();
230 hashCode ^= extensions.get(o).hashCode();
236 public boolean equals(
239 if (o == null || !(o instanceof X509Extensions))
244 X509Extensions other = (X509Extensions)o;
246 Enumeration e1 = extensions.keys();
247 Enumeration e2 = other.extensions.keys();
249 while (e1.hasMoreElements() && e2.hasMoreElements())
251 Object o1 = e1.nextElement();
252 Object o2 = e2.nextElement();
260 if (e1.hasMoreElements() || e2.hasMoreElements())