Exemplo n.º 1
0
        public static Cid Cast(byte[] data)
        {
            if (data.Length == 34 && data[0] == 18 && data[1] == 32)
            {
                return(new Cid(Multihash.Cast(data)));
            }

            ulong vers;
            var   n = Binary.Varint.Read(data, 0, out vers);

            if (vers != 0 && vers != 1)
            {
                throw new Exception($"invalid cid version number: {vers}");
            }

            ulong codec;
            var   cn = Binary.Varint.Read(data, n, out codec);

            var rest = new byte[data.Length - (n + cn)];

            Buffer.BlockCopy(data, n + cn, rest, 0, rest.Length);

            var hash = Multihash.Cast(rest);

            return(new Cid(vers, (MulticodecCode)codec, hash));
        }
Exemplo n.º 2
0
        private static Multihash TestCastToMultihash(string hex, int code, string name)
        {
            var ob = Hex.Decode(hex);
            var b  = Binary.Varint.GetBytes((uint)code).Concat(Binary.Varint.GetBytes((uint)ob.Length)).Concat(ob).ToArray();

            return(Multihash.Cast(b));
        }
Exemplo n.º 3
0
        public void TestValidatePublicKey()
        {
            const string OffensiveKey = "CAASXjBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDjXAQQMal4SB2tSnX6NJIPmC69/BT8A8jc7/gDUZNkEhdhYHvc7k7S4vntV/c92nJGxNdop9fKJyevuNMuXhhHAgMBAAE=";
            var          pkb          = Convert.FromBase64String(OffensiveKey);
            var          pubk         = PublicKey.Unmarshal(pkb);
            var          k            = $"/pk/{Multihash.Cast(pubk.Hash)}";

            Assert.True(Validator.ValidatePublicKeyRecord(k, pkb));
        }