private void checkBlock(byte[] data, boolean newAlgo) throws CHKEncodeException, InvalidCompressionCodecException, CHKVerifyException, CHKDecodeException, IOException {
byte cryptoAlgorithm = newAlgo ? Key.ALGO_AES_CTR_256_SHA256 : Key.ALGO_AES_PCFB_256_SHA256;
byte[] copyOfData = new byte[data.length];
System.arraycopy(data, 0, copyOfData, 0, data.length);
ClientCHKBlock encodedBlock =
ClientCHKBlock.encode(new ArrayBucket(data), false, false, (short)-1, data.length, null, false, null, cryptoAlgorithm);
// Not modified in-place.
assert(Arrays.equals(data, copyOfData));
ClientCHK key = encodedBlock.getClientKey();
if(newAlgo) {
// Check with no JCA.
ClientCHKBlock otherEncodedBlock =
ClientCHKBlock.encode(new ArrayBucket(data), false, false, (short)-1, data.length, null, false, null, cryptoAlgorithm, true);
assertTrue(key.equals(otherEncodedBlock.getClientKey()));
assertTrue(Arrays.equals(otherEncodedBlock.getBlock().data, encodedBlock.getBlock().data));
assertTrue(Arrays.equals(otherEncodedBlock.getBlock().headers, encodedBlock.getBlock().headers));
}
// Verify it.
CHKBlock block = CHKBlock.construct(encodedBlock.getBlock().data, encodedBlock.getBlock().headers, cryptoAlgorithm);
ClientCHKBlock checkBlock = new ClientCHKBlock(block, key);
ArrayBucket checkData = (ArrayBucket) checkBlock.decode(new ArrayBucketFactory(), data.length, false);
assert(Arrays.equals(checkData.toByteArray(), data));
if(newAlgo) {
checkData = (ArrayBucket) checkBlock.decode(new ArrayBucketFactory(), data.length, false, true);
assert(Arrays.equals(checkData.toByteArray(), data));
}
}