32 lines
966 B
C#
32 lines
966 B
C#
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]));
|
|
}
|
|
}
|