public static class NodeAttachmentService.HashCheckingStream
Wraps a stream and hashes data as it is read: if the entire stream is consumed, then at the end the hash of
the read data is compared to the expected hash and exception NodeAttachmentService.HashMismatchException
is thrown by either NodeAttachmentService.HashCheckingStream.read
or NodeAttachmentService.HashCheckingStream.close
if they didn't match. The goal of this is to detect cases where attachments in the store have been tampered with
or corrupted and no longer match their file name. It won't always work: if we read a zip for our own uses and skip
around inside it, we haven't read the whole file, so we can't check the hash. But when copying it over the network
this will provide an additional safety check against user error.
Constructor and Description |
---|
HashCheckingStream(SecureHash.SHA256 expected,
int expectedSize,
java.io.InputStream input,
com.google.common.io.CountingInputStream counter,
com.google.common.hash.HashingInputStream stream)
Wraps a stream and hashes data as it is read: if the entire stream is consumed, then at the end the hash of
the read data is compared to the expected hash and
exception NodeAttachmentService.HashMismatchException is thrown by either NodeAttachmentService.HashCheckingStream.read or NodeAttachmentService.HashCheckingStream.close
if they didn't match. The goal of this is to detect cases where attachments in the store have been tampered with
or corrupted and no longer match their file name. It won't always work: if we read a zip for our own uses and skip
around inside it, we haven't read the whole file, so we can't check the hash. But when copying it over the network
this will provide an additional safety check against user error. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
SecureHash.SHA256 |
getExpected() |
int |
getExpectedSize() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
public HashCheckingStream(SecureHash.SHA256 expected, int expectedSize, java.io.InputStream input, com.google.common.io.CountingInputStream counter, com.google.common.hash.HashingInputStream stream)
Wraps a stream and hashes data as it is read: if the entire stream is consumed, then at the end the hash of
the read data is compared to the expected hash and exception NodeAttachmentService.HashMismatchException
is thrown by either NodeAttachmentService.HashCheckingStream.read
or NodeAttachmentService.HashCheckingStream.close
if they didn't match. The goal of this is to detect cases where attachments in the store have been tampered with
or corrupted and no longer match their file name. It won't always work: if we read a zip for our own uses and skip
around inside it, we haven't read the whole file, so we can't check the hash. But when copying it over the network
this will provide an additional safety check against user error.
public void close()
public int read()
public int read(byte[] b, int off, int len)
public SecureHash.SHA256 getExpected()
public int getExpectedSize()