@Test public final void testDigest() { byte[] merkleTreeDigest = merkleTree.digest(); byte[] testDigest = {(byte) 0xA8, (byte) 0xA3, (byte) 0x36, (byte) 0x1D, (byte) 0x40, (byte) 0x1C, (byte) 0xFD, (byte) 0xA3, (byte) 0xDD, (byte) 0x26, (byte) 0xF1, (byte) 0x0B, (byte) 0xB4, (byte) 0x0E, (byte) 0x1E, (byte) 0xC2, (byte) 0xD1, (byte) 0xD8, (byte) 0x94, (byte) 0x6A}; boolean isValid = true; for (int index=0; index<testDigest.length; index++) { if (merkleTreeDigest[index] != testDigest[index]) { isValid = false; } } assertTrue("Merkle tree digest incorrect", isValid); byte[] leafTreeDigest = merkleTree.leftTree().digest(); byte[] testLeafDigest = {(byte) 0x90, (byte) 0xE0, (byte) 0xE8, (byte) 0xD5, (byte) 0xC8, (byte) 0xCC, (byte) 0x1E, (byte) 0x9F, (byte) 0xFC, (byte) 0x54, (byte) 0x16, (byte) 0x2A, (byte) 0x1D, (byte) 0x2C, (byte) 0xAB, (byte) 0x0A, (byte) 0x02, (byte) 0x33, (byte) 0x79, (byte) 0x2B}; isValid = true; for (int index=0; index<testLeafDigest.length; index++) { if (leafTreeDigest[index] != testLeafDigest[index]) { isValid = false; } } assertTrue("Leaf digest incorrect", isValid); }
private byte[] digest(Leaf leaf) { final List<byte[]> dataBlock = leaf.getDataBlock(); final int numBlocks = dataBlock.size(); for (int index=0; index<numBlocks-1; index++) { md.update(dataBlock.get(index)); } digest = md.digest(dataBlock.get(numBlocks-1)); return (digest); }
MerkleTree { private byte[] digest(Leaf leaf) { final List<byte[]> dataBlock = leaf.getDataBlock(); final int numBlocks = dataBlock.size(); for (int index=0; index<numBlocks-1; index++) { md.update(dataBlock.get(index)); } digest = md.digest(dataBlock.get(numBlocks-1)); return (digest); } }
MerkleTree { private byte[] digest(Leaf leaf) { final List<byte[]> dataBlock = leaf.getDataBlock(); final int numBlocks = dataBlock.size(); for (int index=0; index<numBlocks-1; index++) { md.update(dataBlock.get(index)); } digest = md.digest(dataBlock.get(numBlocks-1)); return (digest); } MerkleTree(MessageDigest md); }
MerkleTree { private byte[] digest(Leaf leaf) { final List<byte[]> dataBlock = leaf.getDataBlock(); final int numBlocks = dataBlock.size(); for (int index=0; index<numBlocks-1; index++) { md.update(dataBlock.get(index)); } digest = md.digest(dataBlock.get(numBlocks-1)); return (digest); } MerkleTree(MessageDigest md); void add(final MerkleTree leftTree, final MerkleTree rightTree); void add(final Leaf leftLeaf, final Leaf rightLeaf); MerkleTree leftTree(); MerkleTree rightTree(); Leaf leftLeaf(); Leaf rightLeaf(); byte[] digest(); void prettyPrint(); }
MerkleTree { private byte[] digest(Leaf leaf) { final List<byte[]> dataBlock = leaf.getDataBlock(); final int numBlocks = dataBlock.size(); for (int index=0; index<numBlocks-1; index++) { md.update(dataBlock.get(index)); } digest = md.digest(dataBlock.get(numBlocks-1)); return (digest); } MerkleTree(MessageDigest md); void add(final MerkleTree leftTree, final MerkleTree rightTree); void add(final Leaf leftLeaf, final Leaf rightLeaf); MerkleTree leftTree(); MerkleTree rightTree(); Leaf leftLeaf(); Leaf rightLeaf(); byte[] digest(); void prettyPrint();  }