net.i2p.data

## Class Signature

- java.lang.Object
- - net.i2p.data.SimpleDataStructure
  - - net.i2p.data.Signature

- All Implemented Interfaces:
    DataStructure

      public class Signature
      extends SimpleDataStructure

  Cryptographic signature implementation for I2P data structures and identity verification.

  Signature provides digital signature capabilities with support for multiple algorithms:

  - Default Algorithm: DSA-SHA1 (40 bytes: 20-byte R + 20-byte S)
  - Modern Algorithms: ECDSA-P256, EdDSA-Ed25519 with variable lengths
  - Algorithm Support: Extensible design for future signature types
  - Verification: Used throughout I2P for identity and data integrity

  Signature Structure:

  - DSA-SHA1: 40 bytes total (R: 20 bytes, S: 20 bytes)
  - ECDSA-P256: Variable length (typically 64-72 bytes)
  - EdDSA-Ed25519: 64 bytes (fixed length)
  - Type Information: Embedded in signature data for verification

  Supported Algorithms:

  - DSA-SHA1: Legacy algorithm, 1024-bit keys
  - ECDSA-P256: Modern algorithm, 256-bit elliptic curve
  - EdDSA-Ed25519: Modern algorithm, 25519 elliptic curve
  - RSA: Supported but discouraged due to performance issues

  Usage:

  - Identity Verification: Proves ownership of `Destination`
  - Data Integrity: Ensures data hasn't been tampered with
  - NetDb Entries: Signs RouterInfo and LeaseSet structures
  - Messages: Authenticates I2NP messages and I2CP communications

  Security Considerations:

  - Algorithm Selection: Prefer modern algorithms (Ed25519, ECDSA-P256)
  - Key Management: Protect private signing keys
  - Verification: Always verify signatures before trusting data
  - Performance: RSA signatures are slow and may be used for DoS

  Evolution:

  - Pre-0.9.8: Only DSA-SHA1 supported (40 bytes fixed)
  - Post-0.9.8: Arbitrary length and type support via `SigType`
  - Current: Multiple algorithms with automatic type detection

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `SIGNATURE_BYTES` 40

    - ### Fields inherited from class net.i2p.data.SimpleDataStructure

      `_data`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Signature()`
    `Signature(byte[] data)`
    `Signature(SigType type)` Unknown type not allowed as we won't know the length to read in the data.
    `Signature(SigType type, byte[] data)` Should we allow an unknown type here?

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object obj)` Warning - this returns true for two different classes with the same size and same data, e.g.
    `SigType` | `getType()` Gets the signature type.
    `int` | `hashCode()` We assume the data has enough randomness in it, so use the first 4 bytes for speed.
    `int` | `length()` The legal length of the byte array in this data structure
    `String` | `toString()`

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

      `calculateHash, fromBase64, fromByteArray, getData, read, readBytes, setData, toBase64, toByteArray, writeBytes`

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

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

- - ### Field Detail

    - #### SIGNATURE_BYTES

          public static final int SIGNATURE_BYTES

      40

  - ### Constructor Detail

    - #### Signature

          public Signature()

    - #### Signature

          public Signature(byte[] data)

    - #### Signature

          public Signature(SigType type)

      Unknown type not allowed as we won't know the length to read in the data.
      Parameters:
        `type` - non-null

    - #### Signature

          public Signature(SigType type,
                           byte[] data)

      Should we allow an unknown type here?
      Parameters:
        `type` - non-null

  - ### Method Detail

    - #### equals

          public boolean equals(Object obj)

      Description copied from class: `SimpleDataStructure`
      Warning - this returns true for two different classes with the same size and same data, e.g. SessionKey and SessionTag, but you wouldn't put them in the same Set, would you?
      Overrides:
        `equals` in class `SimpleDataStructure`

    - #### getType

          public SigType getType()

      Gets the signature type.
      Returns:
        non-null

    - #### hashCode

          public int hashCode()

      Description copied from class: `SimpleDataStructure`
      We assume the data has enough randomness in it, so use the first 4 bytes for speed. If this is not the case, override in the extending class.
      Overrides:
        `hashCode` in class `SimpleDataStructure`

    - #### length

          public int length()

      Description copied from class: `SimpleDataStructure`
      The legal length of the byte array in this data structure
      Specified by:
        `length` in class `SimpleDataStructure`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `SimpleDataStructure`