net.i2p.crypto

## Class SHA1Hash

- java.lang.Object
- - net.i2p.data.SimpleDataStructure
  - - net.i2p.crypto.SHA1Hash

- All Implemented Interfaces:
    DataStructure
  Direct Known Subclasses:
    InfoHash, NID, TokenKey

      public class SHA1Hash
      extends SimpleDataStructure

  I2P data structure for SHA-1 hash values. This class provides a SimpleDataStructure wrapper for 20-byte SHA-1 hashes used throughout I2P for data integrity and identification purposes. It extends SimpleDataStructure to support I2P's serialization framework and provides efficient caching of hash codes.

  Common uses include:

  - Router and destination identifiers
  - Message integrity verification
  - Data structure indexing and lookup

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `HASH_LENGTH`

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

      `_data`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SHA1Hash()`
    `SHA1Hash(byte[] data)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `hashCode()` a Hash is a hash, so just use the first 4 bytes for speed
    `int` | `length()` The legal length of the byte array in this data structure
    `void` | `readBytes(InputStream in)` Sets the data.
    `void` | `setData(byte[] data)` Sets the data.

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

      `calculateHash, equals, fromBase64, fromByteArray, getData, read, toBase64, toByteArray, toString, writeBytes`

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

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

- - ### Field Detail

    - #### HASH_LENGTH

          public static final int HASH_LENGTH

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SHA1Hash

          public SHA1Hash()

    - #### SHA1Hash

          public SHA1Hash(byte[] data)

      Throws:
        `IllegalArgumentException` - if data is not 20 bytes (null is ok)

  - ### Method Detail

    - #### hashCode

          public int hashCode()

      a Hash is a hash, so just use the first 4 bytes for speed
      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`

    - #### readBytes

          public void readBytes(InputStream in)
                         throws DataFormatException,
                                IOException

      Description copied from class: `SimpleDataStructure`
      Sets the data.
      Specified by:
        `readBytes` in interface `DataStructure`
      Overrides:
        `readBytes` in class `SimpleDataStructure`
      Parameters:
        `in` - the stream to read
      Throws:
        `DataFormatException` - if the data is improperly formatted
        `IOException` - if there was a problem reading the stream

    - #### setData

          public void setData(byte[] data)

      Description copied from class: `SimpleDataStructure`
      Sets the data.
      Overrides:
        `setData` in class `SimpleDataStructure`
      Parameters:
        `data` - of correct length, or null
      Throws:
        `IllegalArgumentException` - if data is not 20 bytes (null is ok)