/// <inheritdoc />
 public IHashValue ComputeHash(byte[] data, CancellationToken cancellationToken)
 {
     using (var hashAlgorithm = _config.InstanceFactory())
     {
         return(new HashValue(
                    hashAlgorithm.ComputeHash(data),
                    HashSizeInBits));
     }
 }
예제 #2
0
 public IHashValue ComputeHash(Stream data)
 {
     using (var hashAlgorithm = _config.InstanceFactory())
     {
         return(new HashValue(
                    hashAlgorithm.ComputeHash(data),
                    HashSizeInBits));
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="HashAlgorithmWrapper_Implementation"/> class.
        /// </summary>
        /// <param name="config">The configuration to use for this instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="config"/></exception>
        /// <exception cref="ArgumentException"><paramref name="config"/>.<see cref="IHashAlgorithmWrapperConfig.InstanceFactory"/> has not been set.;<paramref name="config"/>.<see cref="IHashAlgorithmWrapperConfig.InstanceFactory"/></exception>
        public HashAlgorithmWrapper_Implementation(IHashAlgorithmWrapperConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            _config = config.Clone();


            if (_config.InstanceFactory == null)
            {
                throw new ArgumentException($"{nameof(config)}.{nameof(config.InstanceFactory)} has not been set.", $"{nameof(config)}.{nameof(config.InstanceFactory)}");
            }



            using (var hashAlgorithm = _config.InstanceFactory())
                HashSizeInBits = hashAlgorithm.HashSize;
        }