THe whole set of bindigns.
This commit is contained in:
36
SpaceWizards.Sodium.Tests/SecretBoxTest.cs
Normal file
36
SpaceWizards.Sodium.Tests/SecretBoxTest.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Security.Cryptography;
|
||||
using NUnit.Framework;
|
||||
using static SpaceWizards.Sodium.Interop.Methods;
|
||||
|
||||
namespace SpaceWizards.Sodium.Tests;
|
||||
|
||||
[TestFixture]
|
||||
public sealed class SecretBoxTest
|
||||
{
|
||||
[Test]
|
||||
public unsafe void Test()
|
||||
{
|
||||
var message = RandomNumberGenerator.GetBytes(1024);
|
||||
var cipher = RandomNumberGenerator.GetBytes((int)(1024 + crypto_secretbox_MACBYTES));
|
||||
|
||||
var key = stackalloc byte[(int)crypto_secretbox_KEYBYTES];
|
||||
var nonce = stackalloc byte[(int)crypto_secretbox_NONCEBYTES];
|
||||
|
||||
crypto_secretbox_keygen(key);
|
||||
randombytes_buf(nonce, crypto_secretbox_NONCEBYTES);
|
||||
fixed (byte* mPtr = message)
|
||||
fixed (byte* cPtr = cipher)
|
||||
{
|
||||
crypto_secretbox_easy(cPtr, mPtr, (ulong)message.Length, nonce, key);
|
||||
}
|
||||
|
||||
var decrypted = new byte[message.Length];
|
||||
fixed (byte* dPtr = decrypted)
|
||||
fixed (byte* cPtr = cipher)
|
||||
{
|
||||
crypto_secretbox_open_easy(dPtr, cPtr, (ulong)cipher.Length, nonce, key);
|
||||
}
|
||||
|
||||
Assert.That(decrypted, Is.EquivalentTo(message));
|
||||
}
|
||||
}
|
||||
26
SpaceWizards.Sodium.Tests/SpaceWizards.Sodium.Tests.csproj
Normal file
26
SpaceWizards.Sodium.Tests/SpaceWizards.Sodium.Tests.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SpaceWizards.Sodium.Interop\SpaceWizards.Sodium.Interop.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user