Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions PolyShim.Tests/Net50/MD5Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Security.Cryptography;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net50;

public class MD5Tests
{
[Fact]
public void HashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };

// Act
var hash = MD5.HashData(data);

// Assert
hash.Should()
.Equal(
[0x7c, 0xfd, 0xd0, 0x78, 0x89, 0xb3, 0x29, 0x5d, 0x6a, 0x55, 0x09, 0x14, 0xab, 0x35, 0xe0, 0x68]
);
}

[Fact]
public void TryHashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };
var destination = new byte[16];

// Act
var result = MD5.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten);

// Assert
result.Should().BeTrue();
bytesWritten.Should().Be(16);
destination.Should()
.Equal(
[0x7c, 0xfd, 0xd0, 0x78, 0x89, 0xb3, 0x29, 0x5d, 0x6a, 0x55, 0x09, 0x14, 0xab, 0x35, 0xe0, 0x68]
);
}
}
44 changes: 44 additions & 0 deletions PolyShim.Tests/Net50/SHA1Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Security.Cryptography;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net50;

public class SHA1Tests
{
[Fact]
public void HashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };

// Act
var hash = SHA1.HashData(data);

// Assert
hash.Should()
.Equal(
[0x11, 0x96, 0x6a, 0xb9, 0xc0, 0x99, 0xf8, 0xfa, 0xbe, 0xfa, 0xc5, 0x4c, 0x08, 0xd5, 0xbe, 0x2b, 0xd8, 0xc9, 0x03, 0xaf]
);
}

[Fact]
public void TryHashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };
var destination = new byte[20];

// Act
var result = SHA1.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten);

// Assert
result.Should().BeTrue();
bytesWritten.Should().Be(20);
destination.Should()
.Equal(
[0x11, 0x96, 0x6a, 0xb9, 0xc0, 0x99, 0xf8, 0xfa, 0xbe, 0xfa, 0xc5, 0x4c, 0x08, 0xd5, 0xbe, 0x2b, 0xd8, 0xc9, 0x03, 0xaf]
);
}
}
54 changes: 54 additions & 0 deletions PolyShim.Tests/Net50/SHA256Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Security.Cryptography;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net50;

public class SHA256Tests
{
[Fact]
public void HashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };

// Act
var hash = SHA256.HashData(data);

// Assert
hash.Should()
.Equal(
[
0x74, 0xf8, 0x1f, 0xe1, 0x67, 0xd9, 0x9b, 0x4c,
0xb4, 0x1d, 0x6d, 0x0c, 0xcd, 0xa8, 0x22, 0x78,
0xca, 0xee, 0x9f, 0x3e, 0x2f, 0x25, 0xd5, 0xe5,
0xa3, 0x93, 0x6f, 0xf3, 0xdc, 0xec, 0x60, 0xd0,
]
);
}

[Fact]
public void TryHashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };
var destination = new byte[32];

// Act
var result = SHA256.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten);

// Assert
result.Should().BeTrue();
bytesWritten.Should().Be(32);
destination.Should()
.Equal(
[
0x74, 0xf8, 0x1f, 0xe1, 0x67, 0xd9, 0x9b, 0x4c,
0xb4, 0x1d, 0x6d, 0x0c, 0xcd, 0xa8, 0x22, 0x78,
0xca, 0xee, 0x9f, 0x3e, 0x2f, 0x25, 0xd5, 0xe5,
0xa3, 0x93, 0x6f, 0xf3, 0xdc, 0xec, 0x60, 0xd0,
]
);
}
}
58 changes: 58 additions & 0 deletions PolyShim.Tests/Net50/SHA384Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Security.Cryptography;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net50;

public class SHA384Tests
{
[Fact]
public void HashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };

// Act
var hash = SHA384.HashData(data);

// Assert
hash.Should()
.Equal(
[
0xd8, 0x88, 0x75, 0xdb, 0x0f, 0x77, 0xaa, 0xd8,
0xf3, 0xd9, 0x94, 0xfe, 0x68, 0xcd, 0x1c, 0xc7,
0xec, 0x3a, 0x4f, 0xf1, 0x43, 0x78, 0xb7, 0xfe,
0xb9, 0x91, 0xe5, 0x47, 0x84, 0x85, 0x01, 0x92,
0x14, 0x58, 0x54, 0xc3, 0x6e, 0x5a, 0x40, 0xa0,
0xc2, 0xe8, 0x0d, 0xa2, 0x00, 0x2d, 0x7c, 0xc8,
]
);
}

[Fact]
public void TryHashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };
var destination = new byte[48];

// Act
var result = SHA384.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten);

// Assert
result.Should().BeTrue();
bytesWritten.Should().Be(48);
destination.Should()
.Equal(
[
0xd8, 0x88, 0x75, 0xdb, 0x0f, 0x77, 0xaa, 0xd8,
0xf3, 0xd9, 0x94, 0xfe, 0x68, 0xcd, 0x1c, 0xc7,
0xec, 0x3a, 0x4f, 0xf1, 0x43, 0x78, 0xb7, 0xfe,
0xb9, 0x91, 0xe5, 0x47, 0x84, 0x85, 0x01, 0x92,
0x14, 0x58, 0x54, 0xc3, 0x6e, 0x5a, 0x40, 0xa0,
0xc2, 0xe8, 0x0d, 0xa2, 0x00, 0x2d, 0x7c, 0xc8,
]
);
}
}
62 changes: 62 additions & 0 deletions PolyShim.Tests/Net50/SHA512Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Security.Cryptography;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net50;

public class SHA512Tests
{
[Fact]
public void HashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };

// Act
var hash = SHA512.HashData(data);

// Assert
hash.Should()
.Equal(
[
0x50, 0x54, 0x0b, 0xc4, 0xae, 0x31, 0x87, 0x5f,
0xce, 0xb3, 0x82, 0x94, 0x34, 0xc5, 0x5e, 0x3c,
0x2b, 0x66, 0xdd, 0xd7, 0x22, 0x7a, 0x88, 0x3a,
0x3b, 0x4c, 0xc8, 0xf6, 0xcd, 0xa9, 0x65, 0xad,
0x17, 0x12, 0xb3, 0xee, 0x00, 0x08, 0xf9, 0xce,
0xe0, 0x8d, 0xa9, 0x3f, 0x52, 0x34, 0xc1, 0xa7,
0xbf, 0x0e, 0x25, 0x70, 0xef, 0x56, 0xd6, 0x52,
0x80, 0xff, 0xea, 0x69, 0x1b, 0x95, 0x3e, 0xfe,
]
);
}

[Fact]
public void TryHashData_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };
var destination = new byte[64];

// Act
var result = SHA512.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten);

// Assert
result.Should().BeTrue();
bytesWritten.Should().Be(64);
destination.Should()
.Equal(
[
0x50, 0x54, 0x0b, 0xc4, 0xae, 0x31, 0x87, 0x5f,
0xce, 0xb3, 0x82, 0x94, 0x34, 0xc5, 0x5e, 0x3c,
0x2b, 0x66, 0xdd, 0xd7, 0x22, 0x7a, 0x88, 0x3a,
0x3b, 0x4c, 0xc8, 0xf6, 0xcd, 0xa9, 0x65, 0xad,
0x17, 0x12, 0xb3, 0xee, 0x00, 0x08, 0xf9, 0xce,
0xe0, 0x8d, 0xa9, 0x3f, 0x52, 0x34, 0xc1, 0xa7,
0xbf, 0x0e, 0x25, 0x70, 0xef, 0x56, 0xd6, 0x52,
0x80, 0xff, 0xea, 0x69, 0x1b, 0x95, 0x3e, 0xfe,
]
);
}
}
28 changes: 28 additions & 0 deletions PolyShim.Tests/Net70/MD5Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net70;

public class MD5Tests
{
[Fact]
public async Task HashDataAsync_Test()
{
// Arrange
using var stream = new MemoryStream([1, 2, 3, 4, 5]);
var destination = new byte[16];

// Act
var bytesWritten = await MD5.HashDataAsync(stream, destination);

// Assert
bytesWritten.Should().Be(16);
destination.Should()
.Equal(
[0x7c, 0xfd, 0xd0, 0x78, 0x89, 0xb3, 0x29, 0x5d, 0x6a, 0x55, 0x09, 0x14, 0xab, 0x35, 0xe0, 0x68]
);
}
}
28 changes: 28 additions & 0 deletions PolyShim.Tests/Net70/SHA1Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net70;

public class SHA1Tests
{
[Fact]
public async Task HashDataAsync_Test()
{
// Arrange
using var stream = new MemoryStream([1, 2, 3, 4, 5]);
var destination = new byte[20];

// Act
var bytesWritten = await SHA1.HashDataAsync(stream, destination);

// Assert
bytesWritten.Should().Be(20);
destination.Should()
.Equal(
[0x11, 0x96, 0x6a, 0xb9, 0xc0, 0x99, 0xf8, 0xfa, 0xbe, 0xfa, 0xc5, 0x4c, 0x08, 0xd5, 0xbe, 0x2b, 0xd8, 0xc9, 0x03, 0xaf]
);
}
}
33 changes: 33 additions & 0 deletions PolyShim.Tests/Net70/SHA256Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net70;

public class SHA256Tests
{
[Fact]
public async Task HashDataAsync_Test()
{
// Arrange
using var stream = new MemoryStream([1, 2, 3, 4, 5]);
var destination = new byte[32];

// Act
var bytesWritten = await SHA256.HashDataAsync(stream, destination);

// Assert
bytesWritten.Should().Be(32);
destination.Should()
.Equal(
[
0x74, 0xf8, 0x1f, 0xe1, 0x67, 0xd9, 0x9b, 0x4c,
0xb4, 0x1d, 0x6d, 0x0c, 0xcd, 0xa8, 0x22, 0x78,
0xca, 0xee, 0x9f, 0x3e, 0x2f, 0x25, 0xd5, 0xe5,
0xa3, 0x93, 0x6f, 0xf3, 0xdc, 0xec, 0x60, 0xd0,
]
);
}
}
35 changes: 35 additions & 0 deletions PolyShim.Tests/Net70/SHA384Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net70;

public class SHA384Tests
{
[Fact]
public async Task HashDataAsync_Test()
{
// Arrange
using var stream = new MemoryStream([1, 2, 3, 4, 5]);
var destination = new byte[48];

// Act
var bytesWritten = await SHA384.HashDataAsync(stream, destination);

// Assert
bytesWritten.Should().Be(48);
destination.Should()
.Equal(
[
0xd8, 0x88, 0x75, 0xdb, 0x0f, 0x77, 0xaa, 0xd8,
0xf3, 0xd9, 0x94, 0xfe, 0x68, 0xcd, 0x1c, 0xc7,
0xec, 0x3a, 0x4f, 0xf1, 0x43, 0x78, 0xb7, 0xfe,
0xb9, 0x91, 0xe5, 0x47, 0x84, 0x85, 0x01, 0x92,
0x14, 0x58, 0x54, 0xc3, 0x6e, 0x5a, 0x40, 0xa0,
0xc2, 0xe8, 0x0d, 0xa2, 0x00, 0x2d, 0x7c, 0xc8,
]
);
}
}
Loading