Skip to content

Commit cfe6824

Browse files
authored
Merge pull request #16 from Advanced-Systems/certificate
Certificate Improvements
2 parents bb097db + 38d11ef commit cfe6824

20 files changed

+911
-303
lines changed

AdvancedSystems.Security.Tests/AdvancedSystems.Security.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PrivateAssets>all</PrivateAssets>
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
</PackageReference>
16-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.10" />
16+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.11" />
1717
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
1818
<PackageReference Include="Moq" Version="4.20.72" />
1919
<PackageReference Include="xunit" Version="2.9.2" />

AdvancedSystems.Security.Tests/Cryptography/CryptoRandomProviderTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77

88
namespace AdvancedSystems.Security.Tests.Cryptography;
99

10-
public class CryptoRandomProviderTests
10+
/// <summary>
11+
/// Tests the public methods in <seealso cref="CryptoRandomProvider"/>.
12+
/// </summary>
13+
public sealed class CryptoRandomProviderTests
1114
{
1215
#region Tests
1316

17+
/// <summary>
18+
/// Tests that <seealso cref="CryptoRandomProvider.GetBytes(int)"/> returns an
19+
/// array of non-zero bytes with the correct size.
20+
/// </summary>
1421
[Fact]
1522
public void TestGetBytes()
1623
{
@@ -25,6 +32,9 @@ public void TestGetBytes()
2532
Assert.All(buffer.ToArray(), b => Assert.InRange(b, byte.MinValue, byte.MaxValue));
2633
}
2734

35+
/// <summary>
36+
/// Tests heuristically that <seealso cref="CryptoRandomProvider.GetInt32()"/> returns an integer.
37+
/// </summary>
2838
[Fact]
2939
public void TestGetInt32()
3040
{
@@ -42,6 +52,9 @@ public void TestGetInt32()
4252
Assert.All(randomNumbers, x => Assert.InRange(x, int.MinValue, int.MaxValue));
4353
}
4454

55+
/// <summary>
56+
/// Tests heuristically that <seealso cref="CryptoRandomProvider.GetInt32(int, int)"/> returns an integer.
57+
/// </summary>
4558
[Fact]
4659
public void TestGetInt32_MinMax()
4760
{
@@ -61,6 +74,10 @@ public void TestGetInt32_MinMax()
6174
Assert.All(randomNumbers, x => Assert.InRange(x, min, max - 1));
6275
}
6376

77+
/// <summary>
78+
/// Tests that <seealso cref="CryptoRandomProvider.Shuffle{T}(Span{T})"/> changes the order
79+
/// of elements in an array.
80+
/// </summary>
6481
[Fact]
6582
public void TestShuffle()
6683
{
@@ -75,6 +92,10 @@ public void TestShuffle()
7592
Assert.NotEqual(array1, array2);
7693
}
7794

95+
/// <summary>
96+
/// Tests that elements returned by <seealso cref="CryptoRandomProvider.Choice{T}(Span{T})"/>
97+
/// are elements of the original collection.
98+
/// </summary>
7899
[Fact]
79100
public void TestChoice()
80101
{

AdvancedSystems.Security.Tests/Cryptography/HashTests.cs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@
88

99
namespace AdvancedSystems.Security.Tests.Cryptography;
1010

11-
public class HashTests
11+
/// <summary>
12+
/// Tests the public methods in <seealso cref="Hash"/>.
13+
/// </summary>
14+
public sealed class HashTests
1215
{
1316
#region Tests
1417

18+
/// <summary>
19+
/// Tests that the computed <seealso cref="HashAlgorithmName.MD5"/> hash returns a well-formatted string.
20+
/// </summary>
21+
/// <param name="input">
22+
/// The input to compute the hash code for.
23+
/// </param>
24+
/// <param name="expected">
25+
/// The expected result.
26+
/// </param>
27+
/// <param name="format">
28+
/// The formatting to use.
29+
/// </param>
1530
[Theory]
1631
[InlineData("Hello, World!", "65a8e27d8879283831b664bd8b7f0ad4", Format.Hex)]
1732
[InlineData("Hello, World!", "ZajifYh5KDgxtmS9i38K1A==", Format.Base64)]
@@ -31,6 +46,18 @@ public void TestMd5Hash(string input, string expected, Format format)
3146
Assert.Equal(expected, md5);
3247
}
3348

49+
/// <summary>
50+
/// Tests that the computed <seealso cref="HashAlgorithmName.SHA1"/> hash returns a well-formatted string.
51+
/// </summary>
52+
/// <param name="input">
53+
/// The input to compute the hash code for.
54+
/// </param>
55+
/// <param name="expected">
56+
/// The expected result.
57+
/// </param>
58+
/// <param name="format">
59+
/// The formatting to use.
60+
/// </param>
3461
[Theory]
3562
[InlineData("Hello, World!", "0a0a9f2a6772942557ab5355d76af442f8f65e01", Format.Hex)]
3663
[InlineData("Hello, World!", "CgqfKmdylCVXq1NV12r0Qvj2XgE=", Format.Base64)]
@@ -50,6 +77,18 @@ public void TestSHA1Hash(string input, string expected, Format format)
5077
Assert.Equal(expected, sha1);
5178
}
5279

80+
/// <summary>
81+
/// Tests that the computed <seealso cref="HashAlgorithmName.SHA256"/> hash returns a well-formatted string.
82+
/// </summary>
83+
/// <param name="input">
84+
/// The input to compute the hash code for.
85+
/// </param>
86+
/// <param name="expected">
87+
/// The expected result.
88+
/// </param>
89+
/// <param name="format">
90+
/// The formatting to use.
91+
/// </param>
5392
[Theory]
5493
[InlineData("Hello, World!", "dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f", Format.Hex)]
5594
[InlineData("Hello, World!", "3/1gIbsr1bCvZ2KQgJ7DpTGR3YHH9wpLKGiKNiGCmG8=", Format.Base64)]
@@ -69,6 +108,18 @@ public void TestSHA256Hash(string input, string expected, Format format)
69108
Assert.Equal(expected, sha256);
70109
}
71110

111+
/// <summary>
112+
/// Tests that the computed <seealso cref="HashAlgorithmName.SHA384"/> hash returns a well-formatted string.
113+
/// </summary>
114+
/// <param name="input">
115+
/// The input to compute the hash code for.
116+
/// </param>
117+
/// <param name="expected">
118+
/// The expected result.
119+
/// </param>
120+
/// <param name="format">
121+
/// The formatting to use.
122+
/// </param>
72123
[Theory]
73124
[InlineData("Hello, World!", "5485cc9b3365b4305dfb4e8337e0a598a574f8242bf17289e0dd6c20a3cd44a089de16ab4ab308f63e44b1170eb5f515", Format.Hex)]
74125
[InlineData("Hello, World!", "VIXMmzNltDBd+06DN+ClmKV0+CQr8XKJ4N1sIKPNRKCJ3harSrMI9j5EsRcOtfUV", Format.Base64)]
@@ -88,6 +139,18 @@ public void TestSHA384Hash(string input, string expected, Format format)
88139
Assert.Equal(expected, sha384);
89140
}
90141

142+
/// <summary>
143+
/// Tests that the computed <seealso cref="HashAlgorithmName.SHA512"/> hash returns a well-formatted string.
144+
/// </summary>
145+
/// <param name="input">
146+
/// The input to compute the hash code for.
147+
/// </param>
148+
/// <param name="expected">
149+
/// The expected result.
150+
/// </param>
151+
/// <param name="format">
152+
/// The formatting to use.
153+
/// </param>
91154
[Theory]
92155
[InlineData("Hello, World!", "374d794a95cdcfd8b35993185fef9ba368f160d8daf432d08ba9f1ed1e5abe6cc69291e0fa2fe0006a52570ef18c19def4e617c33ce52ef0a6e5fbe318cb0387", Format.Hex)]
93156
[InlineData("Hello, World!", "N015SpXNz9izWZMYX++bo2jxYNja9DLQi6nx7R5avmzGkpHg+i/gAGpSVw7xjBne9OYXwzzlLvCm5fvjGMsDhw==", Format.Base64)]

0 commit comments

Comments
 (0)