Class V2Util

java.lang.Object
org.klomp.snark.v2.V2Util

public class V2Util extends Object
Merkle utilities
Since:
0.9.71
  • Field Details

  • Constructor Details

    • V2Util

      public V2Util()
  • Method Details

    • isValidPieceLength

      public static boolean isValidPieceLength(int plen)
      16K min and power of two Storage.MAX_PIECE_SIZE is checked elsewhere but do it here also.
    • checkMerkle

      public static boolean checkMerkle(MerkleHash root, List<MerkleHash> pieces, int plen)
      Parameters:
      pieces - two minimum
      plen - piece length, 16K minimum, power of two
    • calculateMerkleRoot

      public static MerkleHash calculateMerkleRoot(List<MerkleHash> pieces, int plen)
      Parameters:
      pieces - two minimum
      plen - piece length, 16K minimum, power of two
    • calculateMerkleRoot

      public static MerkleHash calculateMerkleRoot(File f) throws IOException
      Returns:
      the root hash
      Throws:
      IOException
    • calculateMerkleRoot

      public static MerkleHash calculateMerkleRoot(byte[] b) throws IOException
      Returns:
      the root hash
      Throws:
      IOException
    • calculateMerkleRoot

      public static MerkleHash calculateMerkleRoot(InputStream in, int plen) throws IOException
      Warning: Will return bad value if plen is greater than the next power of two of the input size
      Parameters:
      plen - piece length, will be rectified to next power of two 16K min
      Returns:
      the root hash
      Throws:
      IOException
    • calculateMerklePieces

      public static List<MerkleHash> calculateMerklePieces(File f, int plen) throws IOException
      Parameters:
      plen - will use only if smaller than file size
      Returns:
      the piece hashes
      Throws:
      IOException
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception