Added initial tests
This commit is contained in:
parent
18c6d8e13c
commit
6c6a50c395
20
Ed25519 Tests/Ed25519 Tests.csproj
Normal file
20
Ed25519 Tests/Ed25519 Tests.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<RootNamespace>Ed25519_Tests</RootNamespace>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="nunit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ed25519\Ed25519.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
47
Ed25519 Tests/SignerTests.cs
Normal file
47
Ed25519 Tests/SignerTests.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Ed25519;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Constraints;
|
||||
|
||||
namespace Ed25519_Tests
|
||||
{
|
||||
public sealed class SignerTests
|
||||
{
|
||||
[Test]
|
||||
public void TestSigner01()
|
||||
{
|
||||
var message = Encoding.UTF8.GetBytes("This is a test message.");
|
||||
var publicKey = Encoding.ASCII.GetBytes("01365464163464646464164641634160"); // 32 bytes
|
||||
var privateKey = Encoding.ASCII.GetBytes("Secret key");
|
||||
|
||||
var signature = Signer.Sign(message, privateKey, publicKey);
|
||||
|
||||
Assert.That(signature.Length, Is.EqualTo(64));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSigner02()
|
||||
{
|
||||
var message = Encoding.UTF8.GetBytes("This is a test message.");
|
||||
var publicKey = Encoding.ASCII.GetBytes("0136546416346464646416464163416"); // 31 bytes
|
||||
var privateKey = Encoding.ASCII.GetBytes("Secret key");
|
||||
|
||||
Assert.That(() => Signer.Sign(message, privateKey, publicKey), Throws.ArgumentException); // Public key is too short
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSigner03()
|
||||
{
|
||||
var message = Encoding.UTF8.GetBytes("This is a test message.");
|
||||
var publicKey = Encoding.ASCII.GetBytes("01365464163464646464164641634160"); // 32 bytes
|
||||
var privateKey = Encoding.ASCII.GetBytes("Secret key");
|
||||
|
||||
var signature = Signer.Sign(message, privateKey, publicKey);
|
||||
var validationResult = Signer.Validate(signature, message, publicKey);
|
||||
|
||||
Assert.That(validationResult, Is.True);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29613.14
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ed25519", "Ed25519\Ed25519.csproj", "{A36D2E95-E99A-4CB4-B735-417BAE007BC7}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ed25519", "Ed25519\Ed25519.csproj", "{A36D2E95-E99A-4CB4-B735-417BAE007BC7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ed25519 Tests", "Ed25519 Tests\Ed25519 Tests.csproj", "{7CF58545-8CB8-4B23-82DF-D1E71679151C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{A36D2E95-E99A-4CB4-B735-417BAE007BC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A36D2E95-E99A-4CB4-B735-417BAE007BC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A36D2E95-E99A-4CB4-B735-417BAE007BC7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7CF58545-8CB8-4B23-82DF-D1E71679151C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7CF58545-8CB8-4B23-82DF-D1E71679151C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7CF58545-8CB8-4B23-82DF-D1E71679151C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7CF58545-8CB8-4B23-82DF-D1E71679151C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user