mirror of
https://github.com/0x5eal/wg-lua.git
synced 2024-12-13 05:20:37 +00:00
chore(tests): include tests
This commit is contained in:
parent
ad8321955d
commit
e50a64797a
7 changed files with 59 additions and 4 deletions
2
.prettierignore
Normal file
2
.prettierignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
out/
|
||||
tests/
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "wg-lua",
|
||||
"name": "@rbxts/wg-lua",
|
||||
"version": "1.0.0",
|
||||
"description": "A lua implementation of the wireguard keygen algorithm.",
|
||||
"main": "out/init.lua",
|
||||
|
|
|
@ -33,7 +33,7 @@ const _atob = (asc: string) => {
|
|||
let r1: number;
|
||||
let r2: number;
|
||||
|
||||
for (let i = 0; i < asc.size(); ) {
|
||||
for (let i = 0; i < asc.size(); i++) {
|
||||
u24 =
|
||||
(b64Table[string.byte(asc, i++)[0]] << 18) |
|
||||
(b64Table[string.byte(asc, i++)[0]] << 12) |
|
||||
|
|
|
@ -19,6 +19,8 @@ export const wireguard: Wireguard = {
|
|||
const privateKey = generatePrivateKey();
|
||||
const publicKey = generatePublicKey(privateKey);
|
||||
|
||||
print(privateKey);
|
||||
|
||||
return {
|
||||
publicKey: atob(publicKey),
|
||||
privateKey: atob(privateKey),
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
const { atob } = require<{ atob: (buf: number[]) => string }>("base64");
|
||||
|
||||
function gf(init?: number[]): number[] {
|
||||
const r = new Array<number>(16, 0);
|
||||
if (init) {
|
||||
|
|
11
tests/generateKeypair.luau
Normal file
11
tests/generateKeypair.luau
Normal file
|
@ -0,0 +1,11 @@
|
|||
local wg = require("../out/").wireguard
|
||||
|
||||
local BASE64_PAT = "^(?:%a%d+/?){4}*(?:%a%d+/?){2}==|(?:%a%d+/?){3}=?$"
|
||||
|
||||
local keypair = wg:generateKeypair()
|
||||
|
||||
assert(#keypair.publicKey == 44, "expected public key to be 44 bytes")
|
||||
assert(#keypair.privateKey == 44, "expected private key to be 44 bytes")
|
||||
|
||||
assert(keypair.privateKey:match(BASE64_PAT), "expected private key to be base64 encoded")
|
||||
assert(keypair.publicKey:match(BASE64_PAT), "expected public key to be base64 encoded")
|
42
tests/generatePublicKey.luau
Normal file
42
tests/generatePublicKey.luau
Normal file
|
@ -0,0 +1,42 @@
|
|||
local wg = require("../out/").wireguard
|
||||
|
||||
local PRIVATE_KEY = {
|
||||
[1] = 208,
|
||||
[2] = 109,
|
||||
[3] = 43,
|
||||
[4] = 223,
|
||||
[5] = 41,
|
||||
[6] = 233,
|
||||
[7] = 180,
|
||||
[8] = 88,
|
||||
[9] = 228,
|
||||
[10] = 1,
|
||||
[11] = 132,
|
||||
[12] = 145,
|
||||
[13] = 79,
|
||||
[14] = 164,
|
||||
[15] = 143,
|
||||
[16] = 199,
|
||||
[17] = 134,
|
||||
[18] = 67,
|
||||
[19] = 153,
|
||||
[20] = 226,
|
||||
[21] = 151,
|
||||
[22] = 39,
|
||||
[23] = 198,
|
||||
[24] = 16,
|
||||
[25] = 30,
|
||||
[26] = 109,
|
||||
[27] = 90,
|
||||
[28] = 11,
|
||||
[29] = 22,
|
||||
[30] = 4,
|
||||
[31] = 217,
|
||||
[32] = 105,
|
||||
}
|
||||
local PUBLIC_KEY = "mYqWwJuiVXsXqfqXOKOKVTTZRovUXqzPkRtz1DwX1Wc="
|
||||
|
||||
local publicKey = wg:generatePublicKey(PRIVATE_KEY)
|
||||
|
||||
assert(#publicKey == 44, "expected public key to be 44 bytes")
|
||||
assert(publicKey == PUBLIC_KEY, "expected the correct public key")
|
Loading…
Reference in a new issue