LibHac/tests/LibHac.Tests/CryptoTests/Common.cs
2019-11-26 18:13:30 -06:00

31 lines
864 B
C#

using System;
using LibHac.Crypto;
using Xunit;
namespace LibHac.Tests.CryptoTests
{
internal static class Common
{
internal static void CipherTestCore(byte[] inputData, byte[] expected, ICipher cipher)
{
var transformBuffer = new byte[inputData.Length];
Buffer.BlockCopy(inputData, 0, transformBuffer, 0, inputData.Length);
cipher.Transform(transformBuffer, transformBuffer);
Assert.Equal(expected, transformBuffer);
}
internal static void HashTestCore(ReadOnlySpan<byte> message, byte[] expectedDigest, IHash hash)
{
var digestBuffer = new byte[Sha256.DigestSize];
hash.Initialize();
hash.Update(message);
hash.GetHash(digestBuffer);
Assert.Equal(expectedDigest, digestBuffer);
}
}
}