|
1 | 1 | using CasDotnetSdk.Hashers; |
2 | | -using System; |
3 | | -using System.Collections.Generic; |
4 | 2 | using System.Globalization; |
5 | | -using System.IO; |
6 | | -using System.Linq; |
7 | | -using System.Text; |
8 | 3 | using Xunit; |
9 | 4 |
|
10 | 5 | namespace CasDotnetSdkTests.Tests |
11 | 6 | { |
12 | 7 | public class SHAWrapperTests |
13 | 8 | { |
14 | 9 | private readonly SHAWrapper _wrapper; |
15 | | - private readonly string _testString; |
16 | 10 | private const string DataDirectory = "SHA/Data"; |
17 | 11 |
|
18 | 12 | public SHAWrapperTests() |
19 | 13 | { |
20 | 14 | this._wrapper = new SHAWrapper(); |
21 | 15 | } |
22 | 16 |
|
23 | | - [Fact] |
24 | | - public void SHA512HashBytes() |
25 | | - { |
26 | | - byte[] data = Encoding.UTF8.GetBytes(this._testString); |
27 | | - byte[] hashed = this._wrapper.Hash512(data); |
28 | | - Assert.NotNull(hashed); |
29 | | - Assert.NotEmpty(hashed); |
30 | | - Assert.True(hashed.Length > 0); |
31 | | - } |
32 | | - |
33 | | - [Fact] |
34 | | - public void SHA512VerifyPass() |
35 | | - { |
36 | | - byte[] data = Encoding.UTF8.GetBytes(this._testString); |
37 | | - byte[] hashed = this._wrapper.Hash512(data); |
38 | | - bool isSame = this._wrapper.Verify512(data, hashed); |
39 | | - Assert.True(isSame); |
40 | | - } |
41 | | - |
42 | | - [Fact] |
43 | | - public void SHA512VerifyFail() |
44 | | - { |
45 | | - byte[] data = Encoding.UTF8.GetBytes(this._testString); |
46 | | - byte[] hashed = this._wrapper.Hash512(data); |
47 | | - data = Encoding.UTF8.GetBytes("Not the same byte array"); |
48 | | - bool isSame = this._wrapper.Verify512(data, hashed); |
49 | | - Assert.False(isSame); |
50 | | - } |
51 | | - |
52 | | - [Fact] |
53 | | - public void SHA256HashBytes() |
54 | | - { |
55 | | - byte[] data = Encoding.UTF8.GetBytes(this._testString); |
56 | | - byte[] hashed = this._wrapper.Hash256(data); |
57 | | - Assert.NotNull(hashed); |
58 | | - Assert.NotEmpty(hashed); |
59 | | - Assert.True(hashed.Length > 0); |
60 | | - } |
61 | | - |
62 | | - [Fact] |
63 | | - public void SHA256VerifyPass() |
64 | | - { |
65 | | - byte[] data = Encoding.UTF8.GetBytes(this._testString); |
66 | | - byte[] hashed = this._wrapper.Hash256(data); |
67 | | - bool isSame = this._wrapper.Verify256(data, hashed); |
68 | | - Assert.True(isSame); |
69 | | - } |
70 | | - |
71 | | - [Fact] |
72 | | - public void SHA256VerifyFail() |
73 | | - { |
74 | | - byte[] data = Encoding.UTF8.GetBytes(this._testString); |
75 | | - byte[] hashed = this._wrapper.Hash256(data); |
76 | | - data = Encoding.UTF8.GetBytes("Not the same byte array"); |
77 | | - bool isSame = this._wrapper.Verify256(data, hashed); |
78 | | - Assert.False(isSame); |
79 | | - } |
80 | | - |
81 | 17 | [Theory] |
82 | 18 | [MemberData(nameof(SHA256NistVectors))] |
83 | 19 | public void SHA256MatchesNistVectors(byte[] message, byte[] expectedDigest) |
|
0 commit comments