Package org.klomp.snark.v2
Class V2Util
java.lang.Object
org.klomp.snark.v2.V2Util
Merkle utilities
- Since:
- 0.9.71
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<MerkleHash> calculateMerklePieces(File f, int plen) static List<MerkleHash> calculateMerklePieces(InputStream in, int plen) Warn, will return bad value for files if plen is greater than the next power of two of the input sizestatic MerkleHashcalculateMerkleRoot(byte[] b, int plen) static MerkleHashstatic MerkleHashcalculateMerkleRoot(InputStream in, int plen) Warn, will return bad value for files if plen is greater than the next power of two of the input sizestatic MerkleHashcalculateMerkleRoot(List<MerkleHash> pieces, int plen) static booleancheckMerkle(MerkleHash root, List<MerkleHash> pieces, int plen) static booleanisValidPieceLength(int plen) 16K min and power of two Storage.MAX_PIECE_SIZE is checked elsewhere but do it here also.static voidstatic intrectify(long flen) static intrectify(long flen, int plen)
-
Field Details
-
MIN
public static final int MIN- See Also:
-
-
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. -
rectify
public static int rectify(long flen) - Parameters:
flen- the file length- Returns:
- next power of two of flen, or 0 if flen is 0
-
rectify
public static int rectify(long flen, int plen) - Parameters:
flen- the file lengthplen- piece length, 16K minimum, power of two, or zero- Returns:
- plen, or next power of two of flen if smaller, or 0 if flen is 0
-
checkMerkle
- Parameters:
pieces- two minimumplen- piece length, 16K minimum, power of two
-
calculateMerkleRoot
- Parameters:
pieces- two minimumplen- piece length, 16K minimum, power of two
-
calculateMerkleRoot
- Returns:
- the root hash
- Throws:
IOException
-
calculateMerkleRoot
- Parameters:
plen- piece length, for pieces, MUST be the full padded piece length- Returns:
- the root hash
- Throws:
IOException
-
calculateMerkleRoot
Warn, will return bad value for files if plen is greater than the next power of two of the input size- Parameters:
plen- piece length, for files, MUST be rectified to next power of two with rectify(); for pieces, MUST be the full padded piece length- Returns:
- the root hash
- Throws:
IOException
-
calculateMerklePieces
- Parameters:
plen- will use only if smaller than file size- Returns:
- the piece hashes
- Throws:
IOException
-
calculateMerklePieces
Warn, will return bad value for files if plen is greater than the next power of two of the input size- Parameters:
plen- piece length, for files, MUST be rectified to next power of two with rectify(); for pieces, MUST be the full padded piece length- Returns:
- the piece hashes
- Throws:
IOException
-
main
- Throws:
Exception
-