Table of Contents

Class HashStream<T>

Namespace
Amazon.Runtime.Internal.Util
Assembly
AWSSDK.Core.dll

A wrapper stream that calculates a hash of the base stream as it is being read or written. The calculated hash is only available after the stream is closed or CalculateHash is called. After calling CalculateHash, any further reads on the streams will not change the CalculatedHash. If an ExpectedHash is specified and is not equal to the calculated hash, Close or CalculateHash methods will throw an AmazonClientException. If base stream's position is not 0 or HashOnReads is true and the entire stream is not read, the CalculatedHash will be set to an empty byte array and comparison to ExpectedHash will not be made.

public class HashStream<T> : HashStream, IDisposable, IAsyncDisposable where T : IHashingWrapper, new()

Type Parameters

T
Inheritance
HashStream<T>
Implements
Derived
Inherited Members

Constructors

HashStream(Stream, byte[], long)

Initializes an HashStream with a hash algorithm and a base stream.

public HashStream(Stream baseStream, byte[] expectedHash, long expectedLength)

Parameters

baseStream Stream

Stream to calculate hash for.

expectedHash byte[]

Expected hash. Will be compared against calculated hash on stream close. Pass in null to disable check.

expectedLength long

Expected length of the stream. If the reading stops before reaching this position, CalculatedHash will be set to empty array.

Exceptions

AmazonClientException

Exception thrown during Close() or CalculateHash(), if ExpectedHash is set and is different from CalculateHash that the stream calculates, provided that CalculatedHash is not a zero-length byte array.