# Extension

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

# Extension


`
public


interface
Extension
`


`


`

|------------------------------|
| java.security.cert.Extension |

<br />

*** ** * ** ***

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 [X509Extension](https://developer.android.com/reference/java/security/cert/X509Extension) which is more suitable
for accessing a set of extensions.

## Summary

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

## Public methods

### encode

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void encode (OutputStream out)
```

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

<br />

|                   Parameters                    ||
|-------|------------------------------------------|
| `out` | `OutputStream`: the output stream <br /> |

|                                                            Throws                                                            ||
|------------------------------------------------------------------------------------------------|------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException)                     | on encoding or output error. |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if `out` is `null`.          |

### getId

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract String getId ()
```

Gets the extensions's object identifier.

<br />

|                                                   Returns                                                    ||
|--------------------------------------------------------------------|------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the object identifier as a String <br /> |

### getValue

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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.

<br />

|                                            Returns                                            ||
|----------|-------------------------------------------------------------------------------------|
| `byte[]` | a copy of the extension's value, or `null` if no extension value is present. <br /> |

### isCritical

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract boolean isCritical ()
```

Gets the extension's criticality setting.

<br />

|                         Returns                         ||
|-----------|----------------------------------------------|
| `boolean` | true if this is a critical extension. <br /> |