Esempio n. 1
0
            public HashingStreamImpl(
                Stream stream,
                ContentHasher <T> hasher,
                CryptoStreamMode mode,
                bool useParallelHashing,
                long parallelHashingFileSizeBoundary,
                long streamLength)
            {
                Contract.Requires(stream != null);
                Contract.Requires(hasher != null);
                Contract.Requires(useParallelHashing || parallelHashingFileSizeBoundary == -1);

                _baseStream         = stream;
                _hasher             = hasher;
                _streamMode         = mode;
                _useParallelHashing = useParallelHashing;
                _parallelHashingFileSizeBoundary = parallelHashingFileSizeBoundary;

                if (_useParallelHashing)
                {
                    _hashingBufferBlock = new ActionBlock <Pool <Buffer> .PoolHandle>(
                        HashSegmentAsync,
                        new ExecutionDataflowBlockOptions()
                    {
                        MaxDegreeOfParallelism = 1
                    });
                }

                _hashAlgorithm = new GuardedHashAlgorithm(this, streamLength, hasher);
            }
Esempio n. 2
0
            public HashingStreamImpl(Stream stream, ContentHasher <T> hasher, CryptoStreamMode mode, bool useParallelHashing, long parallelHashingFileSizeBoundary)
            {
                Contract.Requires(stream != null);
                Contract.Requires(hasher != null);
                Contract.Requires(useParallelHashing || parallelHashingFileSizeBoundary == -1);

                _baseStream         = stream;
                _hasher             = hasher;
                _streamMode         = mode;
                _useParallelHashing = useParallelHashing;
                _parallelHashingFileSizeBoundary = parallelHashingFileSizeBoundary;

                if (_useParallelHashing)
                {
                    _hashingBufferBlock = new ActionBlock <Pool <Buffer> .PoolHandle>(
                        HashSegmentAsync,
                        new ExecutionDataflowBlockOptions()
                    {
                        MaxDegreeOfParallelism = 1
                    });
                }

                _hasherHandle  = hasher.CreateToken();
                _hashAlgorithm = _hasherHandle.Hasher;

                if (!_hashAlgorithm.CanTransformMultipleBlocks)
                {
                    throw new NotImplementedException();
                }

                if (_hashAlgorithm.InputBlockSize != 1)
                {
                    throw new NotImplementedException();
                }

                if (_hashAlgorithm.OutputBlockSize != 1)
                {
                    throw new NotImplementedException();
                }
            }
Esempio n. 3
0
                public GuardedHashAlgorithm(HashingStreamImpl ownerStream, ContentHasher <T> hasher)
                {
                    _ownerStream = ownerStream;
                    _hasherToken = hasher.CreateToken();

                    var hashAlgorithm = _hasherToken.Hasher;

                    if (!hashAlgorithm.CanTransformMultipleBlocks)
                    {
                        throw new NotImplementedException();
                    }

                    if (hashAlgorithm.InputBlockSize != 1)
                    {
                        throw new NotImplementedException();
                    }

                    if (hashAlgorithm.OutputBlockSize != 1)
                    {
                        throw new NotImplementedException();
                    }
                }
Esempio n. 4
0
                public GuardedHashAlgorithm(HashingStreamImpl ownerStream, long streamLength, ContentHasher <T> hasher)
                {
                    _ownerStream = ownerStream;
                    _hasherToken = hasher.CreateToken();

                    var hashAlgorithm = _hasherToken.Hasher;

                    if (streamLength >= 0 && hashAlgorithm is IHashAlgorithmInputLength sizeHint)
                    {
                        sizeHint.SetInputLength(streamLength);
                    }

                    if (!hashAlgorithm.CanTransformMultipleBlocks)
                    {
                        throw new NotImplementedException();
                    }

                    if (hashAlgorithm.InputBlockSize != 1)
                    {
                        throw new NotImplementedException();
                    }

                    if (hashAlgorithm.OutputBlockSize != 1)
                    {
                        throw new NotImplementedException();
                    }
                }