コード例 #1
0
        public byte[] GetResult()
        {
            var bytesRemaining = _currentByteIndex - _byteIndexProcessedUpTo;

            if (bytesRemaining > 0)
            {
                var remainder = _buffer.AsSpan().Slice(_byteIndexProcessedUpTo, bytesRemaining);

                _hashFunction.AddRemainder(remainder);
            }

            var hash = _hashFunction.GetFinalHashValue();

            var buffer = _buffer;

            _buffer = Array.Empty <byte>();
            ArrayPool <byte> .Shared.Return(buffer);

            return(hash);
        }
コード例 #2
0
        private static byte[] GenerateHashImpl(
            ReadOnlySpan <byte> bytes,
            IHashFunction hashFunction)
        {
            var blockSizeBytes = hashFunction.BlockSizeBytes;
            var blockCount     = bytes.Length / blockSizeBytes;
            var remainder      = bytes.Length % blockSizeBytes;

            for (var blockIndex = 0; blockIndex < blockCount; blockIndex++)
            {
                var start = blockIndex * blockSizeBytes;
                var block = bytes.Slice(start, blockSizeBytes);
                hashFunction.AddCompleteBlock(block);
            }

            if (remainder > 0)
            {
                hashFunction.AddRemainder(bytes.Slice(bytes.Length - remainder));
            }

            return(hashFunction.GetFinalHashValue());
        }