added createExtension method.
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 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 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 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 createExtension(
+ ASN1ObjectIdentifier extnId,
+ boolean critical,
+ ASN1Encodable value)
+ throws IOException
+ {
+ return new Extension(extnId, critical, value.toASN1Primitive().getEncoded());
+ }
+
private Extension(ASN1Sequence seq)
{
if (seq.size() == 2)
