Search in sources :

Example 1 with RunningHash

use of com.swirlds.common.crypto.RunningHash in project hedera-services by hashgraph.

the class RecordsRunningHashLeafTest method updateRunningHashInvalidateHashTest.

@Test
void updateRunningHashInvalidateHashTest() {
    final var runningHash = new RunningHash();
    // sets Hash for the RunningHash
    runningHash.setHash(new Hash(RandomUtils.nextBytes(DigestType.SHA_384.digestLength())));
    // initializes a leaf with a RunningHash
    final var leafForTestingRunningHash = new RecordsRunningHashLeaf(runningHash);
    // digest this leaf
    CryptoFactory.getInstance().digestSync(leafForTestingRunningHash, DigestType.SHA_384);
    assertNotNull(leafForTestingRunningHash.getHash());
    // update runningHash object
    final var newRunningHash = new RunningHash();
    newRunningHash.setHash(new Hash(RandomUtils.nextBytes(DigestType.SHA_384.digestLength())));
    leafForTestingRunningHash.setRunningHash(newRunningHash);
    // the Leaf's Hash should be set to be null after updating the runningHash object
    assertNull(leafForTestingRunningHash.getHash());
}
Also used : RunningHash(com.swirlds.common.crypto.RunningHash) Hash(com.swirlds.common.crypto.Hash) RunningHash(com.swirlds.common.crypto.RunningHash) Test(org.junit.jupiter.api.Test)

Example 2 with RunningHash

use of com.swirlds.common.crypto.RunningHash in project hedera-services by hashgraph.

the class RecordsRunningHashLeaf method deserialize.

@Override
public void deserialize(final SerializableDataInputStream in, final int version) throws IOException {
    runningHash = new RunningHash();
    runningHash.setHash(in.readSerializable());
}
Also used : RunningHash(com.swirlds.common.crypto.RunningHash)

Aggregations

RunningHash (com.swirlds.common.crypto.RunningHash)2 Hash (com.swirlds.common.crypto.Hash)1 Test (org.junit.jupiter.api.Test)1