use of com.swirlds.common.crypto.Hash in project hedera-services by hashgraph.
the class RecordStreamFileParsingTest method parseSigFileV5.
@Test
void parseSigFileV5() throws Exception {
final var streamFilePath = "src/test/resources/recordStreamTest/record0.0.3/2022-02-01T20_08_44.147325000Z.rcd";
final File streamFile = new File(streamFilePath);
final File sigFile = new File(streamFilePath + "_sig");
Hash expectedEntireHash = LinkedObjectStreamUtilities.computeEntireHash(streamFile);
Hash expectedMetaHash = LinkedObjectStreamUtilities.computeMetaHash(streamFile, Release023xStreamType.RELEASE_023x_STREAM_TYPE);
Pair<Pair<Hash, Signature>, Pair<Hash, Signature>> parsedResult = LinkedObjectStreamUtilities.parseSigFile(sigFile, Release023xStreamType.RELEASE_023x_STREAM_TYPE);
Hash entireHashInSig = parsedResult.getLeft().getLeft();
Hash metaHashInSig = parsedResult.getRight().getLeft();
assertEquals(expectedEntireHash, entireHashInSig);
assertEquals(expectedMetaHash, metaHashInSig);
}
use of com.swirlds.common.crypto.Hash in project hedera-services by hashgraph.
the class RecordStreamFileParsingTest method parseV5.
void parseV5(final String dir, final Hash expectedStartHash) throws Exception {
final File out = new File(dir + "/out.log");
// these files are generated with initial Hash be an empty Hash
final File recordsDir = new File(dir);
Iterator<SelfSerializable> iterator = LinkedObjectStreamUtilities.parseStreamDirOrFile(recordsDir, Release023xStreamType.RELEASE_023x_STREAM_TYPE);
Hash startHash = null;
int recordsCount = 0;
Hash endHash = null;
try (BufferedWriter writer = new BufferedWriter(new FileWriter(out))) {
while (iterator.hasNext()) {
SelfSerializable object = iterator.next();
if (startHash == null) {
startHash = (Hash) object;
writer.write(startHash.toString());
writer.write("\n");
} else if (!iterator.hasNext()) {
endHash = (Hash) object;
writer.write(endHash.toString());
writer.write("\n");
break;
} else {
assertTrue(object instanceof RecordStreamObject);
RecordStreamObject recordStreamObject = (RecordStreamObject) object;
writer.write(recordStreamObject.toShortString());
writer.write("\n");
assertNotNull(recordStreamObject.getTimestamp());
recordsCount++;
}
}
}
// the record streams are generated with an empty startHash
assertEquals(expectedStartHash, startHash);
assertNotEquals(0, recordsCount);
assertNotEquals(startHash, endHash);
}
use of com.swirlds.common.crypto.Hash 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());
}
use of com.swirlds.common.crypto.Hash in project hedera-services by hashgraph.
the class HashBench method setup.
@Setup(Level.Trial)
public void setup() {
hashes = new Hash[256];
Random random = new Random();
for (int i = 0; i < hashes.length; i++) {
byte[] hashData = new byte[48];
random.nextBytes(hashData);
hashes[i] = new Hash(hashData);
}
}
use of com.swirlds.common.crypto.Hash in project hedera-services by hashgraph.
the class VFCDataSourceLmdb method getHash.
private Hash getHash(ByteBuffer hashBytes) {
hashBytes.rewind();
Hash hash = new Hash(DigestType.SHA_384);
hashBytes.get(hash.getValue());
return hash;
}
Aggregations