예제 #1
0
        [InlineData("8tWhXW5oUwtPd9d3FnjuLP1NozN3vc45rmsoWEEfrZL1L6gi9dqi1YkZu5iHb2HJ8WbZaaKAyNWWRAa8yaxMkGKJmX", "hello world")] // sha3_512
        public void TestVerify(string mhs, string data)
        {
            var mh    = Multihash.Parse(mhs);
            var bytes = Encoding.UTF8.GetBytes(data);

            Assert.True(mh.Verify(bytes));
        }
예제 #2
0
        public void VerifyRoundTrip(HashType type)
        {
            var rand  = new Random(Environment.TickCount);
            var bytes = new byte[rand.Next(1024, 4096)];

            rand.NextBytes(bytes);

            var mh  = Multihash.Sum(type, bytes, type == HashType.ID ? bytes.Length : -1);
            var str = mh.ToString();
            var mh2 = Multihash.Parse(str);

            Assert.True(mh2.Verify(bytes));
        }
예제 #3
0
        public static Cid Decode(string v)
        {
            if (v.Length < 2)
            {
                throw new ArgumentException("cid too short", nameof(v));
            }

            if (v.Length == 46 && v.Substring(0, 2) == "Qm")
            {
                return(new Cid(Multihash.Parse(v)));
            }

            return(Cast(Multibase.Decode(v)));
        }
예제 #4
0
        public async Task VerifyRoundTripAsync(HashType type)
        {
            var rand  = new Random(Environment.TickCount);
            var bytes = new byte[rand.Next(1024, 4096)];

            rand.NextBytes(bytes);

            var mh = await Multihash.SumAsync(type, bytes);

            var str = mh.ToString();
            var mh2 = Multihash.Parse(str);

            Assert.True(await mh2.VerifyAsync(bytes));
        }