-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
135e094
commit e5cd63f
Showing
7 changed files
with
202 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
TYPESCRIPT_TEST_FILE | ||
TESTFILE_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,27 @@ import { | |
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { createRequire } from "https://deno.land/[email protected]/node/module.ts"; | ||
|
||
import { enc, dec, wrap, unwrap, generateKeyPair } from "./main.ts"; | ||
import { | ||
enc, | ||
dec, | ||
wrap, | ||
unwrap, | ||
wrapKey, | ||
unwrapKey, | ||
generateKeyPair | ||
} from "./main.ts"; | ||
|
||
const hello_world = new TextEncoder().encode("Hello World"); | ||
const [priv, pub] = generateKeyPair(); | ||
const [priv2, pub2] = generateKeyPair(); | ||
|
||
const base64ToUint8 = (str: string): Uint8Array => | ||
Uint8Array.from(atob(str), (c) => c.charCodeAt(0)); | ||
|
||
// uses the release config for the tests | ||
const TEST_STRING = new TextEncoder().encode("hello this is a test string"); | ||
const TEST_WRAPPED = await Deno.readFile("./TESTFILE_TYPESCRIPT_ENC_BIN") | ||
const TEST_KEY = await Deno.readFile("./TESTFILE_TYPESCRIPT_PRIVKEY") | ||
|
||
// this function tests whether the encryption and decryption functions work | ||
export function encrypt_decrypt() { | ||
|
@@ -24,7 +39,15 @@ Deno.test(encrypt_decrypt) | |
Deno.test(function wrap_unwrap() { | ||
const enc_test = enc(priv, pub2, hello_world); | ||
const wrapped = wrap(enc_test); | ||
console.log(wrapped) | ||
const unwrapped = unwrap(wrapped); | ||
const plain = dec(priv2, unwrapped); | ||
assertEquals(enc_test, unwrapped); | ||
}); | ||
|
||
Deno.test(function unwrapanddecrypt() { | ||
const unwrapped = unwrap(TEST_WRAPPED); | ||
const unwrappedKey = unwrapKey(TEST_KEY) | ||
const plain = dec(unwrappedKey, unwrapped); | ||
assertEquals(plain, TEST_STRING) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.