Ejemplo n.º 1
0
        public static Hash ConcatAndCompute(Hash hash1, Hash hash2, Hash hash3)
        {
            var bytes = ByteArrayHelper.ConcatArrays(
                ByteArrayHelper.ConcatArrays(hash1.ToByteArray(), hash2.ToByteArray()), hash3.ToByteArray());

            return(ComputeFrom(bytes));
        }
Ejemplo n.º 2
0
        private static byte[] _AddCheckSum(byte[] data)
        {
            var checkSum         = _GetCheckSum(data);
            var dataWithCheckSum = ByteArrayHelper.ConcatArrays(data, checkSum);

            return(dataWithCheckSum);
        }
Ejemplo n.º 3
0
        //Returns null if the checksum is invalid
        private static byte[] _VerifyAndRemoveCheckSum(byte[] data)
        {
            var result          = ByteArrayHelper.SubArray(data, 0, data.Length - CheckSumSize);
            var givenCheckSum   = ByteArrayHelper.SubArray(data, data.Length - CheckSumSize);
            var correctCheckSum = _GetCheckSum(result);

            return(givenCheckSum.SequenceEqual(correctCheckSum) ? result : null);
        }
Ejemplo n.º 4
0
 public static ByteString ToByteString(this string hexString)
 {
     return(ByteString.CopyFrom(ByteArrayHelper.HexStringToByteArray(hexString)));
 }
Ejemplo n.º 5
0
        public static Hash ConcatAndCompute(Hash hash1, Hash hash2)
        {
            var bytes = ByteArrayHelper.ConcatArrays(hash1.ToByteArray(), hash2.ToByteArray());

            return(Hash.FromRawBytes(bytes));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads the content value represented in hex string.
        /// </summary>
        /// <param name="hex"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public static Hash HexStringToHash(string hex)
        {
            var bytes = ByteArrayHelper.HexStringToByteArray(hex);

            return(Hash.FromByteArray(bytes));
        }