+47
-1
lines changedFilter options
+47
-1
lines changed Original file line number Diff line number Diff line change
@@ -237,10 +237,28 @@ public static IEnumerable<HashingAlgorithm> All
237
237
/// When <paramref name="name"/> is not registered.
238
238
/// </exception>
239
239
public static HashAlgorithm GetAlgorithm(string name)
240
+
{
241
+
return GetAlgorithmMetadata(name).Hasher();
242
+
}
243
+
244
+
/// <summary>
245
+
/// Gets the metadata with the specified IPFS multi-hash name.
246
+
/// </summary>
247
+
/// <param name="name">
248
+
/// The name of a hashing algorithm, see <see href="https://github.com/multiformats/multicodec/blob/master/table.csv"/>
249
+
/// for IPFS defined names.
250
+
/// </param>
251
+
/// <returns>
252
+
/// The metadata associated with the hashing <paramref name="name"/>.
253
+
/// </returns>
254
+
/// <exception cref="KeyNotFoundException">
255
+
/// When <paramref name="name"/> is not registered.
256
+
/// </exception>
257
+
public static HashingAlgorithm GetAlgorithmMetadata(string name)
240
258
{
241
259
try
242
260
{
243
-
return HashingAlgorithm.Names[name].Hasher();
261
+
return HashingAlgorithm.Names[name];
244
262
}
245
263
catch (KeyNotFoundException)
246
264
{
Original file line number Diff line number Diff line change
@@ -31,6 +31,34 @@ public void GetHasher_Unknown()
31
31
ExceptionAssert.Throws<KeyNotFoundException>(() => HashingAlgorithm.GetAlgorithm("unknown"));
32
32
}
33
33
34
+
[TestMethod]
35
+
public void GetMetadata()
36
+
{
37
+
var info = HashingAlgorithm.GetAlgorithmMetadata("sha3-256");
38
+
Assert.IsNotNull(info);
39
+
Assert.AreEqual("sha3-256", info.Name);
40
+
Assert.AreEqual(0x16, info.Code);
41
+
Assert.AreEqual(256 /8, info.DigestSize);
42
+
Assert.IsNotNull(info.Hasher);
43
+
}
44
+
45
+
[TestMethod]
46
+
public void GetMetadata_Unknown()
47
+
{
48
+
ExceptionAssert.Throws<KeyNotFoundException>(() => HashingAlgorithm.GetAlgorithmMetadata("unknown"));
49
+
}
50
+
51
+
[TestMethod]
52
+
public void GetMetadata_Alias()
53
+
{
54
+
var info = HashingAlgorithm.GetAlgorithmMetadata("id");
55
+
Assert.IsNotNull(info);
56
+
Assert.AreEqual("identity", info.Name);
57
+
Assert.AreEqual(0, info.Code);
58
+
Assert.AreEqual(0, info.DigestSize);
59
+
Assert.IsNotNull(info.Hasher);
60
+
}
61
+
34
62
[TestMethod]
35
63
public void HashingAlgorithm_Bad_Name()
36
64
{
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4