diff options
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/asn1/x509/Extension.java')
-rw-r--r-- | bcprov/src/main/java/org/bouncycastle/asn1/x509/Extension.java | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/asn1/x509/Extension.java b/bcprov/src/main/java/org/bouncycastle/asn1/x509/Extension.java index b8c0473a..50080282 100644 --- a/bcprov/src/main/java/org/bouncycastle/asn1/x509/Extension.java +++ b/bcprov/src/main/java/org/bouncycastle/asn1/x509/Extension.java @@ -183,6 +183,13 @@ public class Extension private boolean critical; private ASN1OctetString value; + /** + * Constructor using an ASN1Boolean and an OCTET STRING for the value. + * + * @param extnId the OID associated with this extension. + * @param critical will evaluate to true if the extension is critical, false otherwise. + * @param value the extension's value wrapped in an OCTET STRING. + */ public Extension( ASN1ObjectIdentifier extnId, ASN1Boolean critical, @@ -191,6 +198,13 @@ public class Extension this(extnId, critical.isTrue(), value); } + /** + * Constructor using a byte[] for the value. + * + * @param extnId the OID associated with this extension. + * @param critical true if the extension is critical, false otherwise. + * @param value the extension's value as a byte[] to be wrapped in an OCTET STRING. + */ public Extension( ASN1ObjectIdentifier extnId, boolean critical, @@ -199,6 +213,13 @@ public class Extension this(extnId, critical, new DEROctetString(value)); } + /** + * Constructor using an OCTET STRING for the value. + * + * @param extnId the OID associated with this extension. + * @param critical true if the extension is critical, false otherwise. + * @param value the extension's value wrapped in an OCTET STRING. + */ public Extension( ASN1ObjectIdentifier extnId, boolean critical, @@ -209,6 +230,24 @@ public class Extension this.value = value; } + /** + * Helper method to create an extension from any ASN.1 encodable object. + * + * @param extnId the OID associated with this extension. + * @param critical true if the extension is critical, false otherwise. + * @param value the value to be encoded into the extension's OCTET STRING. + * @return a new Extension with the encoding of value in the bytes of the extension's OCTET STRING. + * @throws IOException if the value cannot be encoded into bytes. + */ + public static Extension create( + ASN1ObjectIdentifier extnId, + boolean critical, + ASN1Encodable value) + throws IOException + { + return new Extension(extnId, critical, value.toASN1Primitive().getEncoded()); + } + private Extension(ASN1Sequence seq) { if (seq.size() == 2) @@ -290,7 +329,7 @@ public class Extension public ASN1Primitive toASN1Primitive() { - ASN1EncodableVector v = new ASN1EncodableVector(); + ASN1EncodableVector v = new ASN1EncodableVector(3); v.add(extnId); |