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");
109 public static final DERObjectIdentifier ExtendedKeyUsage = new DERObjectIdentifier("2.5.29.37");
111 private Hashtable extensions = new Hashtable();
112 private Vector ordering = new Vector();
114 public static X509Extensions getInstance(
115 ASN1TaggedObject obj,
118 return getInstance(ASN1Sequence.getInstance(obj, explicit));
121 public static X509Extensions getInstance(
124 if (obj == null || obj instanceof X509Extensions)
126 return (X509Extensions)obj;
129 if (obj instanceof ASN1Sequence)
131 return new X509Extensions((ASN1Sequence)obj);
134 if (obj instanceof ASN1TaggedObject)
136 return getInstance(((ASN1TaggedObject)obj).getObject());
139 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
143 * Constructor from DERConstructedSequence.
145 * the extensions are a list of constructed sequences, either with (OID, OctetString) or (OID, Boolean, OctetString)
147 public X509Extensions(
150 Enumeration e = seq.getObjects();
152 while (e.hasMoreElements())
154 ASN1Sequence s = (ASN1Sequence)e.nextElement();
155 Enumeration e1 = s.getObjects();
159 extensions.put(s.getObjectAt(0), new X509Extension((DERBoolean)s.getObjectAt(1), (DEROctetString)s.getObjectAt(2)));
163 extensions.put(s.getObjectAt(0), new X509Extension(false, (DEROctetString)s.getObjectAt(1)));
166 ordering.addElement(s.getObjectAt(0));
171 * constructor from a table of extensions.
173 * it's is assumed the table contains OID/String pairs.
175 public X509Extensions(
176 Hashtable extensions)
178 this(null, extensions);
182 * constructor from a table of extensions with ordering
184 * it's is assumed the table contains OID/String pairs.
186 public X509Extensions(
188 Hashtable extensions)
192 if (ordering == null)
194 e = extensions.keys();
198 e = ordering.elements();
201 while (e.hasMoreElements())
203 this.ordering.addElement(e.nextElement());
206 e = this.ordering.elements();
208 while (e.hasMoreElements())
210 DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
211 X509Extension ext = (X509Extension)extensions.get(oid);
213 this.extensions.put(oid, ext);
218 * return an Enumeration of the extension field's object ids.
220 public Enumeration oids()
222 return ordering.elements();
226 * return the extension represented by the object identifier
229 * @return the extension if it's present, null otherwise.
231 public X509Extension getExtension(
232 DERObjectIdentifier oid)
234 return (X509Extension)extensions.get(oid);
237 public DERObject getDERObject()
239 DEREncodableVector vec = new DEREncodableVector();
240 Enumeration e = ordering.elements();
242 while (e.hasMoreElements())
244 DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
245 X509Extension ext = (X509Extension)extensions.get(oid);
246 DEREncodableVector v = new DEREncodableVector();
250 if (ext.isCritical())
252 v.add(new DERBoolean(true));
255 v.add(ext.getValue());
257 vec.add(new DERSequence(v));
260 return new DERSequence(vec);
263 public int hashCode()
265 Enumeration e = extensions.keys();
268 while (e.hasMoreElements())
270 Object o = e.nextElement();
272 hashCode ^= o.hashCode();
273 hashCode ^= extensions.get(o).hashCode();
279 public boolean equals(
282 if (o == null || !(o instanceof X509Extensions))
287 X509Extensions other = (X509Extensions)o;
289 Enumeration e1 = extensions.keys();
290 Enumeration e2 = other.extensions.keys();
292 while (e1.hasMoreElements() && e2.hasMoreElements())
294 Object o1 = e1.nextElement();
295 Object o2 = e2.nextElement();
303 if (e1.hasMoreElements() || e2.hasMoreElements())