Example #1
0
 public void Decode(ReadOnlyByteSpan code)
 {
     Depth       = code[0];
     Fingerprint = BitConverter.ToInt32(code.Slice(1, 4));
     Child       = (uint)code[5] << 24 | (uint)code[6] << 16 | (uint)code[7] << 8 | code[8];
     code.Slice(9, 32).CopyTo(ChainCode.Span);
     PublicKey = new PublicKey();
     PublicKey.Set(code.Slice(41, 33));
 }
        public static void TransformFinalBlock(this HashAlgorithm alg, ReadOnlyByteSpan data, ByteSpan hash)
        {
            var length = data.Length;
            var array  = ArrayPool <byte> .Shared.Rent(Math.Min(MaxBufferSize, length));

            try
            {
                var mOff = 0;
                do
                {
                    var mLen = Math.Min(array.Length, data.Length - mOff);
                    data.Slice(mOff, mLen).CopyTo(array);
                    mOff += mLen;
                    if (mOff < length)
                    {
                        alg.TransformBlock(array, 0, mLen, null, 0);
                    }
                    else
                    {
                        alg.TransformFinalBlock(array, 0, mLen);
                        alg.Hash.CopyTo(hash);
                    }
                }while (mOff < length);
            }
            finally
            {
                Array.Clear(array, 0, array.Length);
                ArrayPool <byte> .Shared.Return(array);
            }
        }
Example #3
0
 public UInt160(ReadOnlyByteSpan span, bool reverse = false) : this()
 {
     if (span.Length < Length)
     {
         throw new ArgumentException($"{Length} bytes are required.");
     }
     span.Slice(0, Length).CopyTo(Span);
     if (reverse)
     {
         Span.Reverse();
     }
 }