Beispiel #1
0
        /// <inheritdoc />
        protected override void HashCore(byte[] array, int ibStart, int cbSize)
        {
            while (cbSize > 0)
            {
                if (_currentOffset == _buffer.Length)
                {
                    _blockHashes.Add(VsoHash.HashBlock(_buffer, _buffer.Length));
                    _currentOffset = 0;
                }

                int bytesToCopy = Math.Min(cbSize, _buffer.Length - _currentOffset);
                Buffer.BlockCopy(array, ibStart, _buffer, _currentOffset, bytesToCopy);
                _currentOffset += bytesToCopy;
                ibStart        += bytesToCopy;
                cbSize         -= bytesToCopy;
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        protected override byte[] HashFinal()
        {
            var rollingId = new VsoHash.RollingBlobIdentifier();

            // Flush out buffer
            if (_currentOffset != 0)
            {
                _blockHashes.Add(VsoHash.HashBlock(_buffer, _currentOffset));
            }

            // if there are no blocks add an empty block
            if (_blockHashes.Count == 0)
            {
                _blockHashes.Add(VsoHash.HashBlock(new byte[] { }, 0));
            }

            for (int i = 0; i < _blockHashes.Count - 1; i++)
            {
                rollingId.Update(_blockHashes[i]);
            }

            return(rollingId.Finalize(_blockHashes[_blockHashes.Count - 1]).Bytes);
        }
Beispiel #3
0
 private BlobBlockHash HashBlock(byte[] block, int lengthToHash)
 {
     return(VsoHash.HashBlock(block, lengthToHash));
 }