Exemple #1
0
        public void GetMetadata_Alias()
        {
            var info = HashingAlgorithm.GetAlgorithmMetadata("id");

            Assert.IsNotNull(info);
            Assert.AreEqual("identity", info.Name);
            Assert.AreEqual(0, info.Code);
            Assert.AreEqual(0, info.DigestSize);
            Assert.IsNotNull(info.Hasher);
        }
Exemple #2
0
        public void GetMetadata()
        {
            var info = HashingAlgorithm.GetAlgorithmMetadata("sha3-256");

            Assert.IsNotNull(info);
            Assert.AreEqual("sha3-256", info.Name);
            Assert.AreEqual(0x16, info.Code);
            Assert.AreEqual(256 / 8, info.DigestSize);
            Assert.IsNotNull(info.Hasher);
        }
Exemple #3
0
        public void GetHasher()
        {
            using (var hasher = HashingAlgorithm.GetAlgorithm("sha3-256"))
            {
                Assert.IsNotNull(hasher);
                var input    = new byte[] { 0xe9 };
                var expected = "f0d04dd1e6cfc29a4460d521796852f25d9ef8d28b44ee91ff5b759d72c1e6d6".ToHexBuffer();

                var actual = hasher.ComputeHash(input);
                CollectionAssert.AreEqual(expected, actual);
            }
        }
 /// <summary>
 ///   Remove an IPFS hashing algorithm from the registry.
 /// </summary>
 /// <param name="algorithm">
 ///   The <see cref="HashingAlgorithm"/> to remove.
 /// </param>
 public static void Deregister(HashingAlgorithm algorithm)
 {
     Names.Remove(algorithm.Name);
     Codes.Remove(algorithm.Code);
 }
Exemple #5
0
 public void HashingAlgorithm_Alias_Target_Is_Bad()
 {
     ExceptionAssert.Throws <ArgumentException>(() => HashingAlgorithm.RegisterAlias("foo", "  "));
 }
Exemple #6
0
 public void HashingAlgorithm_Alias_Target_Does_Not_Exist()
 {
     ExceptionAssert.Throws <ArgumentException>(() => HashingAlgorithm.RegisterAlias("foo", "sha1-x"));
 }
Exemple #7
0
 public void HashingAlgorithm_Alias_Already_Exists()
 {
     ExceptionAssert.Throws <ArgumentException>(() => HashingAlgorithm.RegisterAlias("id", "identity"));
 }
Exemple #8
0
 public void HashingAlgorithm_Bad_Alias()
 {
     ExceptionAssert.Throws <ArgumentNullException>(() => HashingAlgorithm.RegisterAlias(null, "sha1"));
     ExceptionAssert.Throws <ArgumentNullException>(() => HashingAlgorithm.RegisterAlias("", "sha1"));
     ExceptionAssert.Throws <ArgumentNullException>(() => HashingAlgorithm.RegisterAlias("   ", "sha1"));
 }
Exemple #9
0
 public void HashingAlgorithm_Number_Already_Exists()
 {
     ExceptionAssert.Throws <ArgumentException>(() => HashingAlgorithm.Register("sha1-x", 0x11, 1));
 }
Exemple #10
0
 public void HashingAlgorithm_Bad_Name()
 {
     ExceptionAssert.Throws <ArgumentNullException>(() => HashingAlgorithm.Register(null, 1, 1));
     ExceptionAssert.Throws <ArgumentNullException>(() => HashingAlgorithm.Register("", 1, 1));
     ExceptionAssert.Throws <ArgumentNullException>(() => HashingAlgorithm.Register("   ", 1, 1));
 }
Exemple #11
0
 public void GetMetadata_Unknown()
 {
     ExceptionAssert.Throws <KeyNotFoundException>(() => HashingAlgorithm.GetAlgorithmMetadata("unknown"));
 }