Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
75 changes: 75 additions & 0 deletions PolyShim.Tests/Net50/MD5Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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,
]);
}
}
83 changes: 83 additions & 0 deletions PolyShim.Tests/Net50/SHA1Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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,
]);
}
}
107 changes: 107 additions & 0 deletions PolyShim.Tests/Net50/SHA256Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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,
]);
}
}
Loading
Loading