# Extension

public interface **Extension** This interface represents an X.509 extension.


Extensions provide a means of associating additional attributes with users
or public keys and for managing a certification hierarchy. The extension
format also allows communities to define private extensions to carry
information unique to those communities.


Each extension contains an object identifier, a criticality setting
indicating whether it is a critical or a non-critical extension, and
and an ASN.1 DER-encoded value. Its ASN.1 definition is:

```
     Extension ::= SEQUENCE {
         extnId        OBJECT IDENTIFIER,
         critical      BOOLEAN DEFAULT FALSE,
         extnValue     OCTET STRING
                 -- contains a DER encoding of a value
                 -- of the type registered for use with
                 -- the extnId object identifier value
     }

 
```


This interface is designed to provide access to a single extension,
unlike `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/X509Extension.html` which is more suitable
for accessing a set of extensions.

### Public Method Summary

|---|---|
| abstract void | [encode](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Extension.html#encode(java.io.OutputStream))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out) Generates the extension's DER encoding and writes it to the output stream. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getId](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Extension.html#getId())() Gets the extensions's object identifier. |
| abstract byte\[\] | [getValue](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Extension.html#getValue())() Gets the extensions's DER-encoded value. |
| abstract boolean | [isCritical](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/cert/Extension.html#isCritical())() Gets the extension's criticality setting. |

## Public Methods

#### public abstract void
**encode**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out)

Generates the extension's DER encoding and writes it to the output
stream.

##### Parameters

| out | the output stream |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | on encoding or output error. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `out` is `null`. |
|---|---|

#### public abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getId**
()

Gets the extensions's object identifier.

##### Returns

- the object identifier as a String

#### public abstract byte\[\]
**getValue**
()

Gets the extensions's DER-encoded value. Note, this is the bytes
that are encoded as an OCTET STRING. It does not include the OCTET
STRING tag and length.

##### Returns

- a copy of the extension's value, or `null` if no extension value is present.

#### public abstract boolean
**isCritical**
()

Gets the extension's criticality setting.

##### Returns

- true if this is a critical extension.