-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
HashAlgorithmNameTests.cs
69 lines (61 loc) · 2.62 KB
/
HashAlgorithmNameTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using Xunit;
namespace System.Security.Cryptography.Tests
{
public static class HashAlgorithmNameTests
{
[Theory]
[MemberData(nameof(ValidInputs))]
public static void FromOid_ValidInput(string oid, HashAlgorithmName expected)
{
Assert.Equal(expected, HashAlgorithmName.FromOid(oid));
}
[Fact]
public static void FromOid_ThrowsForNullInput()
{
Assert.Throws<ArgumentNullException>(() => HashAlgorithmName.FromOid(null));
}
[Fact]
public static void FromOid_ThrowsForInvalidInput()
{
CryptographicException exception = Assert.Throws<CryptographicException>(() => HashAlgorithmName.FromOid("1.2.3.4"));
Assert.Contains("1.2.3.4", exception.Message);
}
[Fact]
public static void TryFromOid_ThrowsForNullInput()
{
Assert.Throws<ArgumentNullException>(() => HashAlgorithmName.TryFromOid(null, out _));
}
[Theory]
[MemberData(nameof(ValidInputs))]
public static void TryFromOid_ValidInput(string oid, HashAlgorithmName expected)
{
Assert.True(HashAlgorithmName.TryFromOid(oid, out HashAlgorithmName actual));
Assert.Equal(expected, actual);
}
[Theory]
[InlineData("1.2.3.4")]
[InlineData("SHA1")]
[InlineData("1.2.840.113549.1.1.5")]
public static void TryFromOid_ReturnsFalseForInvalidInput(string oidValue)
{
Assert.False(HashAlgorithmName.TryFromOid(oidValue, out _));
}
public static IEnumerable<object[]> ValidInputs
{
get
{
yield return new object[] { "1.2.840.113549.2.5", HashAlgorithmName.MD5 };
yield return new object[] { "1.3.14.3.2.26", HashAlgorithmName.SHA1 };
yield return new object[] { "2.16.840.1.101.3.4.2.1", HashAlgorithmName.SHA256 };
yield return new object[] { "2.16.840.1.101.3.4.2.2", HashAlgorithmName.SHA384 };
yield return new object[] { "2.16.840.1.101.3.4.2.3", HashAlgorithmName.SHA512 };
yield return new object[] { "2.16.840.1.101.3.4.2.8", HashAlgorithmName.SHA3_256 };
yield return new object[] { "2.16.840.1.101.3.4.2.9", HashAlgorithmName.SHA3_384 };
yield return new object[] { "2.16.840.1.101.3.4.2.10", HashAlgorithmName.SHA3_512 };
}
}
}
}