Add Wireguard KeyGen Util
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\AS1024.Wireguard.Utils\AS1024.Wireguard.Utils.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
31
tests/AS1024.Wireguard.Utils.Tests/WireGuardKeyUtilsTests.cs
Normal file
31
tests/AS1024.Wireguard.Utils.Tests/WireGuardKeyUtilsTests.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace AS1024.Wireguard.Utils.Tests;
|
||||
|
||||
public class WireGuardKeyUtilsTests
|
||||
{
|
||||
[Fact]
|
||||
public void RoundTrip()
|
||||
{
|
||||
var priv = WireGuardKeyUtils.GeneratePrivateKey();
|
||||
var pub = WireGuardKeyUtils.GetPublicKey(priv);
|
||||
|
||||
var privB64 = Convert.ToBase64String(priv);
|
||||
Assert.Equal(priv, WireGuardKeyUtils.FromBase64(privB64));
|
||||
Assert.Equal(WireGuardKeyUtils.KeySize, pub.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Rfc7748Vector()
|
||||
{
|
||||
// RFC 7748 §6.1.
|
||||
var priv = Convert.FromHexString("77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a");
|
||||
var expected = Convert.FromHexString("8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a");
|
||||
|
||||
Assert.Equal(expected, WireGuardKeyUtils.GetPublicKey(priv));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RejectsWrongLength()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => WireGuardKeyUtils.GetPublicKey(new byte[31]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user