Class Sha1Hash

java.lang.Object
com.frostwire.jlibtorrent.Sha1Hash
All Implemented Interfaces:
Cloneable, Comparable<Sha1Hash>

public final class Sha1Hash extends Object implements Comparable<Sha1Hash>, Cloneable
This type holds a SHA-1 digest or any other kind of 20 byte sequence. It implements a number of convenience functions, such as bit operations, comparison operators etc.

In libtorrent it is primarily used to hold info-hashes, piece-hashes, peer IDs, node IDs etc.

  • Constructor Details

    • Sha1Hash

      public Sha1Hash(sha1_hash h)
      Parameters:
      h - native object
    • Sha1Hash

      public Sha1Hash(byte[] bytes)
      Parameters:
      bytes - hash as an array of bytes
    • Sha1Hash

      public Sha1Hash(String hex)
      Parameters:
      hex - hex coded representation of the hash
    • Sha1Hash

      public Sha1Hash()
      Constructs an all-zero sha1-hash
  • Method Details

    • swig

      public sha1_hash swig()
      Returns:
      the native object
    • clear

      public void clear()
      set the sha1-hash to all zeroes.
    • isAllZeros

      public boolean isAllZeros()
      return true if the sha1-hash is all zero.
      Returns:
      true if zero
    • countLeadingZeroes

      public int countLeadingZeroes()
      Returns:
      the number of leading zeroes
    • toHex

      public String toHex()
      Returns the hex representation of this has.

      This method uses internally the libtorrent to_hex function.

      Returns:
      the hex representation
    • compareTo

      public int compareTo(Sha1Hash o)
      Specified by:
      compareTo in interface Comparable<Sha1Hash>
      Parameters:
      o -
      Returns:
    • toString

      public String toString()
      Returns an hex representation of this hash. Internally it calls toHex().
      Overrides:
      toString in class Object
      Returns:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
    • clone

      public Sha1Hash clone()
      Overrides:
      clone in class Object
    • max

      public static Sha1Hash max()
      returns an all-F sha1-hash. i.e. the maximum value representable by a 160 bit number (20 bytes). This is a static member function.
      Returns:
      the maximum number
    • min

      public static Sha1Hash min()
      returns an all-zero sha1-hash. i.e. the minimum value representable by a 160 bit number (20 bytes). This is a static member function.
      Returns:
      the minimum number (zero)