Пример #1
0
        public unsafe Checksum(byte[] checksum)
        {
            if (checksum.Length == 0)
            {
                _checkSum = default;
                return;
            }
            else if (checksum.Length != Sha1HashSize)
            {
                throw new ArgumentException($"{nameof(checksum)} must be a SHA-1 hash", nameof(checksum));
            }

            fixed(byte *data = checksum)
            {
                // Avoid a direct dereferencing assignment since sizeof(Sha1Hash) may be greater than Sha1HashSize.
                _checkSum = Sha1Hash.FromPointer((Sha1Hash *)data);
            }
        }
Пример #2
0
        public unsafe Checksum(ImmutableArray <byte> checksum)
        {
            if (checksum.Length == 0)
            {
                _checkSum = default;
                return;
            }
            else if (checksum.Length != Sha1HashSize)
            {
                throw new ArgumentException($"{nameof(checksum)} must be a SHA-1 hash", nameof(checksum));
            }

            using (var pooled = SharedPools.ByteArray.GetPooledObject())
            {
                var bytes = pooled.Object;
                checksum.CopyTo(bytes);

                fixed(byte *data = bytes)
                {
                    // Avoid a direct dereferencing assignment since sizeof(Sha1Hash) may be greater than Sha1HashSize.
                    _checkSum = Sha1Hash.FromPointer((Sha1Hash *)data);
                }
            }
        }