net.i2p.data

## Class Certificate

- java.lang.Object
- - net.i2p.data.DataStructureImpl
  - - net.i2p.data.Certificate

- All Implemented Interfaces:
    DataStructure

      public class Certificate
      extends DataStructureImpl

  Defines a certificate that can be attached to various I2P structures, such as RouterIdentity and Destination, allowing routers and clients to help manage denial of service attacks and the network utilization. Certificates can even be defined to include identifiable information signed by some certificate authority, though that use probably isn't appropriate for an anonymous network ;) Todo: Properly support multiple certificates
  Author:
    jrandom

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected byte[]` | `_payload`
    `protected int` | `_type`
    `static int` | `CERTIFICATE_LENGTH_SIGNED_WITH_HASH`
    `static int` | `CERTIFICATE_TYPE_HASHCASH` specifies a Hashcash style certificate
    `static int` | `CERTIFICATE_TYPE_HIDDEN` we should not be used for anything (don't use us in the netDb, in tunnels, or tell others about us)
    `static int` | `CERTIFICATE_TYPE_MULTIPLE` Contains multiple certs
    `static int` | `CERTIFICATE_TYPE_NULL` Specifies a null certificate type with no payload
    `static int` | `CERTIFICATE_TYPE_SIGNED` Signed with 40-byte Signature and (optional) 32-byte hash
    `static Certificate` | `NULL_CERT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Certificate()`
    `Certificate(int type, byte[] payload)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Certificate` | `create(byte[] data, int off)` If null cert, return immutable static instance, else create new
    `static Certificate` | `create(InputStream in)` If null cert, return immutable static instance, else create new
    `boolean` | `equals(Object object)`
    `int` | `getCertificateType()`
    `byte[]` | `getPayload()`
    `int` | `hashCode()`
    `int` | `readBytes(byte[] source, int offset)`
    `void` | `readBytes(InputStream in)` Load up the current object with data from the given stream.
    `void` | `setCertificateType(int type)`
    `void` | `setPayload(byte[] payload)`
    `int` | `size()`
    `String` | `toString()`
    `int` | `writeBytes(byte[] target, int offset)`
    `void` | `writeBytes(OutputStream out)` Write out the data structure to the stream, using the format defined in the I2P data structure specification.

    - ### Methods inherited from class net.i2p.data.DataStructureImpl

      `calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### NULL_CERT

          public static final Certificate NULL_CERT

    - #### _type

          protected int _type

    - #### _payload

          protected byte[] _payload

    - #### CERTIFICATE_TYPE_NULL

          public static final int CERTIFICATE_TYPE_NULL

      Specifies a null certificate type with no payload
      See Also:
        Constant Field Values

    - #### CERTIFICATE_TYPE_HASHCASH

          public static final int CERTIFICATE_TYPE_HASHCASH

      specifies a Hashcash style certificate
      See Also:
        Constant Field Values

    - #### CERTIFICATE_TYPE_HIDDEN

          public static final int CERTIFICATE_TYPE_HIDDEN

      we should not be used for anything (don't use us in the netDb, in tunnels, or tell others about us)
      See Also:
        Constant Field Values

    - #### CERTIFICATE_TYPE_SIGNED

          public static final int CERTIFICATE_TYPE_SIGNED

      Signed with 40-byte Signature and (optional) 32-byte hash
      See Also:
        Constant Field Values

    - #### CERTIFICATE_LENGTH_SIGNED_WITH_HASH

          public static final int CERTIFICATE_LENGTH_SIGNED_WITH_HASH

      See Also:
        Constant Field Values

    - #### CERTIFICATE_TYPE_MULTIPLE

          public static final int CERTIFICATE_TYPE_MULTIPLE

      Contains multiple certs
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Certificate

          public Certificate()

    - #### Certificate

          public Certificate(int type,
                     byte[] payload)

  - ### Method Detail

    - #### create

          public static Certificate create(byte[] data,
                           int off)

      If null cert, return immutable static instance, else create new
      Throws:
        `AIOOBE` - if not enough bytes
      Since:
        0.8.3

    - #### create

          public static Certificate create(InputStream in)
                                    throws DataFormatException,
                                           IOException

      If null cert, return immutable static instance, else create new
      Throws:
        `DataFormatException`
        `IOException`
      Since:
        0.8.3

    - #### getCertificateType

          public int getCertificateType()

    - #### setCertificateType

          public void setCertificateType(int type)

    - #### getPayload

          public byte[] getPayload()

    - #### setPayload

          public void setPayload(byte[] payload)

    - #### readBytes

          public void readBytes(InputStream in)
                         throws DataFormatException,
                                IOException

      Description copied from interface: `DataStructure`
      Load up the current object with data from the given stream. Data loaded this way must match the I2P data structure specification.
      Parameters:
        `in` - stream to read from
      Throws:
        `DataFormatException` - if the data is improperly formatted
        `IOException` - if there was a problem reading the stream

    - #### writeBytes

          public void writeBytes(OutputStream out)
                          throws DataFormatException,
                                 IOException

      Description copied from interface: `DataStructure`
      Write out the data structure to the stream, using the format defined in the I2P data structure specification.
      Parameters:
        `out` - stream to write to
      Throws:
        `DataFormatException` - if the data was incomplete or not yet ready to be written
        `IOException` - if there was a problem writing to the stream

    - #### writeBytes

          public int writeBytes(byte[] target,
                       int offset)

      Returns:
        the written length (NOT the new offset)

    - #### readBytes

          public int readBytes(byte[] source,
                      int offset)
                        throws DataFormatException

      Throws:
        `DataFormatException`

    - #### size

          public int size()

    - #### equals

          public boolean equals(Object object)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`