diff --git a/test/misc.test.ts b/test/misc.test.ts index 005b910..69e0e37 100644 --- a/test/misc.test.ts +++ b/test/misc.test.ts @@ -11,7 +11,8 @@ test('Private box', async () => { expect(de).not.toBeNull() const box = await PrivateBox.encrypt(message, de!) - const unbox = await box.decrypt(k.privateKey) + expect(box).not.toBeNull() + const unbox = await box!.decrypt(k.privateKey) expect(unbox).toEqual(message) }) test('Private wrap', async () => { @@ -24,11 +25,14 @@ test('Private wrap', async () => { const message = crypto.getRandomValues(new Uint8Array(8)) const k_wrapped = await SecretBox.gen(true) const boxed_message = await SecretBox.encrypt(message, k_wrapped) + expect(boxed_message).not.toBeNull() + const box = await PrivateWrap.wrap(k_wrapped, de!) - const unbox = await box.unwrap(k.privateKey) + expect(box).not.toBeNull() + const unbox = await box!.unwrap(k.privateKey) expect(unbox).not.toBeNull() - const unboxed_message = await boxed_message.decrypt(unbox!) + const unboxed_message = await boxed_message!.decrypt(unbox!) expect(unboxed_message).toEqual(message) }) test('Signature', async () => { diff --git a/test/private-box.test.ts b/test/private-box.test.ts index e00458e..7244432 100644 --- a/test/private-box.test.ts +++ b/test/private-box.test.ts @@ -14,12 +14,14 @@ beforeAll(async () => { test('base case', async () => { const box = await PrivateBox.encrypt(message, k1.publicKey) - const unboxed = await box.decrypt(k1.privateKey) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k1.privateKey) expect(unboxed).toEqual(message) }) test("Different key can't decrypt", async () => { const box = await PrivateBox.encrypt(message, k1.publicKey) - const unboxed = await box.decrypt(k2.privateKey) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k2.privateKey) expect(unboxed).toBeNull() }) @@ -36,8 +38,9 @@ test('Key generation', async () => { test('serialization', async () => { const box = await PrivateBox.encrypt(message, k1.publicKey) + expect(box).not.toBeNull() - const ser = await box.toString() + const ser = await box!.toString() const de = await PrivateBox.fromString(ser) expect(de).not.toBeNull() diff --git a/test/private-wrap.test.ts b/test/private-wrap.test.ts index 67738b7..8c9a47c 100644 --- a/test/private-wrap.test.ts +++ b/test/private-wrap.test.ts @@ -14,12 +14,14 @@ beforeAll(async () => { test('base case', async () => { const box = await PrivateWrap.wrap(message, k1.publicKey) - const unboxed = await box.unwrap(k1.privateKey) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k1.privateKey) expect(unboxed).toEqual(message) }) test("Different key can't decrypt", async () => { const box = await PrivateWrap.wrap(message, k1.publicKey) - const unboxed = await box.unwrap(k2.privateKey) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k2.privateKey) expect(unboxed).toBeNull() }) @@ -36,8 +38,9 @@ test('Key generation', async () => { test('serialization', async () => { const box = await PrivateWrap.wrap(message, k1.publicKey) + expect(box).not.toBeNull() - const ser = await box.toString() + const ser = await box!.toString() const de = await PrivateWrap.fromString(ser) expect(de).not.toBeNull() diff --git a/test/pwd-box.test.ts b/test/pwd-box.test.ts index d1ae7cc..f7330df 100644 --- a/test/pwd-box.test.ts +++ b/test/pwd-box.test.ts @@ -13,19 +13,22 @@ beforeAll(async () => { test('base case', async () => { const box = await PwdBox.encrypt(message, k1) - const unboxed = await box.decrypt(k1) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k1) expect(unboxed).toEqual(message) }) test("Different key can't decrypt", async () => { const box = await PwdBox.encrypt(message, k1) - const unboxed = await box.decrypt(k2) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k2) expect(unboxed).toBeNull() }) test('serialization', async () => { const box = await PwdBox.encrypt(message, k1) + expect(box).not.toBeNull() - const ser = box.toString() + const ser = box!.toString() const de = PwdBox.fromString(ser) expect(de).not.toBeNull() diff --git a/test/pwd-wrap.test.ts b/test/pwd-wrap.test.ts index 9f2429b..d569696 100644 --- a/test/pwd-wrap.test.ts +++ b/test/pwd-wrap.test.ts @@ -13,19 +13,22 @@ beforeAll(async () => { test('base case', async () => { const box = await PwdWrap.wrap(message, k1) - const unboxed = await box.unwrap(k1) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k1) expect(unboxed).toEqual(message) }) test("Different key can't decrypt", async () => { const box = await PwdWrap.wrap(message, k1) - const unboxed = await box.unwrap(k2) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k2) expect(unboxed).toBeNull() }) test('serialization', async () => { const box = await PwdWrap.wrap(message, k1) + expect(box).not.toBeNull() - const ser = box.toString() + const ser = box!.toString() const de = PwdWrap.fromString(ser) expect(de).not.toBeNull() diff --git a/test/secret-box.test.ts b/test/secret-box.test.ts index 508f97d..9789301 100644 --- a/test/secret-box.test.ts +++ b/test/secret-box.test.ts @@ -13,12 +13,14 @@ beforeAll(async () => { test('base case', async () => { const box = await SecretBox.encrypt(message, k1) - const unboxed = await box.decrypt(k1) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k1) expect(unboxed).toEqual(message) }) test("Different key can't decrypt", async () => { const box = await SecretBox.encrypt(message, k1) - const unboxed = await box.decrypt(k2) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k2) expect(unboxed).toBeNull() }) @@ -29,8 +31,9 @@ test('Key generation', async () => { test('serialization', async () => { const box = await SecretBox.encrypt(message, k1) + expect(box).not.toBeNull() - const ser = box.toString() + const ser = box!.toString() const de = SecretBox.fromString(ser) expect(de).not.toBeNull() diff --git a/test/secret-wrap.test.ts b/test/secret-wrap.test.ts index 4e746a2..abfc9ce 100644 --- a/test/secret-wrap.test.ts +++ b/test/secret-wrap.test.ts @@ -13,12 +13,14 @@ beforeAll(async () => { test('base case', async () => { const box = await SecretWrap.wrap(message, k1) - const unboxed = await box.unwrap(k1) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k1) expect(unboxed).toEqual(message) }) test("Different key can't decrypt", async () => { const box = await SecretWrap.wrap(message, k1) - const unboxed = await box.unwrap(k2) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k2) expect(unboxed).toBeNull() }) @@ -29,8 +31,9 @@ test('Key generation', async () => { test('serialization', async () => { const box = await SecretWrap.wrap(message, k1) + expect(box).not.toBeNull() - const ser = box.toString() + const ser = box!.toString() const de = SecretWrap.fromString(ser) expect(de).not.toBeNull() diff --git a/test/wrap.test.ts b/test/wrap.test.ts index 7ff6027..4fe27ef 100644 --- a/test/wrap.test.ts +++ b/test/wrap.test.ts @@ -9,13 +9,15 @@ beforeAll(async () => { async function seal(key: CryptoKey): Promise { const box = await SecretWrap.wrap(key, wrap_key) - const unboxed = await box.unwrap(wrap_key) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(wrap_key) expect(unboxed).not.toBeNull() return unboxed! } async function cant_seal(key: CryptoKey): Promise { expect(key.extractable).toBeFalse() - expect(SecretWrap.wrap(key, wrap_key)).rejects.toThrow() + const box = await SecretWrap.wrap(key, wrap_key) + expect(box).toBeNull() } test('Signature', async () => { @@ -30,9 +32,10 @@ test('Signature', async () => { test('SecretWrap', async () => { let k = await SecretWrap.gen(true) const box = await SecretWrap.wrap(k, k) // Please kids, never do this for real ! + expect(box).not.toBeNull() k = await seal(k) - const unbox = await box.unwrap(k) + const unbox = await box!.unwrap(k) expect(unbox).not.toBeNull() expect(unbox).toEqual(k) }) @@ -40,18 +43,20 @@ test('SecretBox', async () => { const message = crypto.getRandomValues(new Uint8Array(8)) let k = await SecretBox.gen(true) const box = await SecretBox.encrypt(message, k) + expect(box).not.toBeNull() k = await seal(k) - const unbox = await box.decrypt(k) + const unbox = await box!.decrypt(k) expect(unbox).not.toBeNull() expect(unbox).toEqual(message) }) test('PrivateWrap', async () => { const k = await PrivateWrap.gen(true) const box = await PrivateWrap.wrap(wrap_key, k.publicKey) + expect(box).not.toBeNull() const privk = await seal(k.privateKey) - const unbox = await box.unwrap(privk) + const unbox = await box!.unwrap(privk) expect(unbox).not.toBeNull() expect(unbox).toEqual(wrap_key) }) @@ -59,19 +64,21 @@ test('PrivateBox', async () => { const message = crypto.getRandomValues(new Uint8Array(8)) let k = await PrivateBox.gen(true) const box = await PrivateBox.encrypt(message, k.publicKey) + expect(box).not.toBeNull() const privk = await seal(k.privateKey) - const unbox = await box.decrypt(privk) + const unbox = await box!.decrypt(privk) expect(unbox).not.toBeNull() expect(unbox).toEqual(message) }) test("Can't unwrap with a different key", async () => { const wrap_k2 = await SecretWrap.gen(false) const box = await SecretWrap.wrap(wrap_key, wrap_key) // Never do this kids ! - const unbox = await box.unwrap(wrap_k2) + expect(box).not.toBeNull() + const unbox = await box!.unwrap(wrap_k2) expect(unbox).toBeNull() }) -test('Cant wrap non-extractable', async () => { +test("Can't wrap non-extractable", async () => { const k_sb = await SecretBox.gen(false) const k_sw = await SecretWrap.gen(false) const k_pb = await PrivateBox.gen(false)