1 module hunt.security.cert.Extension; 2 3 import hunt.stream.Common; 4 5 /** 6 * This interface represents an X.509 extension. 7 * 8 * <p> 9 * Extensions provide a means of associating additional attributes with users 10 * or public keys and for managing a certification hierarchy. The extension 11 * format also allows communities to define private extensions to carry 12 * information unique to those communities. 13 * 14 * <p> 15 * Each extension contains an object identifier, a criticality setting 16 * indicating whether it is a critical or a non-critical extension, and 17 * and an ASN.1 DER-encoded value. Its ASN.1 definition is: 18 * 19 * <pre> 20 * 21 * Extension ::= SEQUENCE { 22 * extnId OBJECT IDENTIFIER, 23 * critical BOOLEAN DEFAULT FALSE, 24 * extnValue OCTET STRING 25 * -- contains a DER encoding of a value 26 * -- of the type registered for use with 27 * -- the extnId object identifier value 28 * } 29 * 30 * </pre> 31 * 32 * <p> 33 * This interface is designed to provide access to a single extension, 34 * unlike {@link java.security.cert.X509Extension} which is more suitable 35 * for accessing a set of extensions. 36 * 37 * @since 1.7 38 */ 39 interface Extension { 40 41 /** 42 * Gets the extensions's object identifier. 43 * 44 * @return the object identifier as a string 45 */ 46 string getId(); 47 48 /** 49 * Gets the extension's criticality setting. 50 * 51 * @return true if this is a critical extension. 52 */ 53 bool isCritical(); 54 55 /** 56 * Gets the extensions's DER-encoded value. Note, this is the bytes 57 * that are encoded as an OCTET STRING. It does not include the OCTET 58 * STRING tag and length. 59 * 60 * @return a copy of the extension's value, or {@code null} if no 61 * extension value is present. 62 */ 63 byte[] getValue(); 64 65 /** 66 * Generates the extension's DER encoding and writes it to the output 67 * stream. 68 * 69 * @param out the output stream 70 * @exception IOException on encoding or output error. 71 * @exception NullPointerException if {@code out} is {@code null}. 72 */ 73 void encode(OutputStream stream); 74 } 75 76 alias CertExtension = Extension;