This commit is contained in:
+2
-2
@@ -24,8 +24,8 @@ 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)
|
||||
const box = await PrivateWrap.encrypt(k_wrapped, de!)
|
||||
const unbox = await box.decrypt(k.privateKey)
|
||||
const box = await PrivateWrap.wrap(k_wrapped, de!)
|
||||
const unbox = await box.unwrap(k.privateKey)
|
||||
expect(unbox).not.toBeNull()
|
||||
|
||||
const unboxed_message = await boxed_message.decrypt(unbox!)
|
||||
|
||||
@@ -13,13 +13,13 @@ beforeAll(async () => {
|
||||
})
|
||||
|
||||
test('base case', async () => {
|
||||
const box = await PrivateWrap.encrypt(message, k1.publicKey)
|
||||
const unboxed = await box.decrypt(k1.privateKey)
|
||||
const box = await PrivateWrap.wrap(message, k1.publicKey)
|
||||
const unboxed = await box.unwrap(k1.privateKey)
|
||||
expect(unboxed).toEqual(message)
|
||||
})
|
||||
test("Different key can't decrypt", async () => {
|
||||
const box = await PrivateWrap.encrypt(message, k1.publicKey)
|
||||
const unboxed = await box.decrypt(k2.privateKey)
|
||||
const box = await PrivateWrap.wrap(message, k1.publicKey)
|
||||
const unboxed = await box.unwrap(k2.privateKey)
|
||||
expect(unboxed).toBeNull()
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ test('Key generation', async () => {
|
||||
})
|
||||
|
||||
test('serialization', async () => {
|
||||
const box = await PrivateWrap.encrypt(message, k1.publicKey)
|
||||
const box = await PrivateWrap.wrap(message, k1.publicKey)
|
||||
|
||||
const ser = await box.toString()
|
||||
const de = await PrivateWrap.fromString(ser)
|
||||
|
||||
@@ -12,18 +12,18 @@ beforeAll(async () => {
|
||||
})
|
||||
|
||||
test('base case', async () => {
|
||||
const box = await PwdWrap.encrypt(message, k1)
|
||||
const unboxed = await box.decrypt(k1)
|
||||
const box = await PwdWrap.wrap(message, k1)
|
||||
const unboxed = await box.unwrap(k1)
|
||||
expect(unboxed).toEqual(message)
|
||||
})
|
||||
test("Different key can't decrypt", async () => {
|
||||
const box = await PwdWrap.encrypt(message, k1)
|
||||
const unboxed = await box.decrypt(k2)
|
||||
const box = await PwdWrap.wrap(message, k1)
|
||||
const unboxed = await box.unwrap(k2)
|
||||
expect(unboxed).toBeNull()
|
||||
})
|
||||
|
||||
test('serialization', async () => {
|
||||
const box = await PwdWrap.encrypt(message, k1)
|
||||
const box = await PwdWrap.wrap(message, k1)
|
||||
|
||||
const ser = box.toString()
|
||||
const de = PwdWrap.fromString(ser)
|
||||
|
||||
@@ -12,13 +12,13 @@ beforeAll(async () => {
|
||||
})
|
||||
|
||||
test('base case', async () => {
|
||||
const box = await SecretWrap.encrypt(message, k1)
|
||||
const unboxed = await box.decrypt(k1)
|
||||
const box = await SecretWrap.wrap(message, k1)
|
||||
const unboxed = await box.unwrap(k1)
|
||||
expect(unboxed).toEqual(message)
|
||||
})
|
||||
test("Different key can't decrypt", async () => {
|
||||
const box = await SecretWrap.encrypt(message, k1)
|
||||
const unboxed = await box.decrypt(k2)
|
||||
const box = await SecretWrap.wrap(message, k1)
|
||||
const unboxed = await box.unwrap(k2)
|
||||
expect(unboxed).toBeNull()
|
||||
})
|
||||
|
||||
@@ -28,7 +28,7 @@ test('Key generation', async () => {
|
||||
})
|
||||
|
||||
test('serialization', async () => {
|
||||
const box = await SecretWrap.encrypt(message, k1)
|
||||
const box = await SecretWrap.wrap(message, k1)
|
||||
|
||||
const ser = box.toString()
|
||||
const de = SecretWrap.fromString(ser)
|
||||
|
||||
+9
-9
@@ -8,14 +8,14 @@ beforeAll(async () => {
|
||||
})
|
||||
|
||||
async function seal(key: CryptoKey): Promise<CryptoKey> {
|
||||
const box = await SecretWrap.encrypt(key, wrap_key)
|
||||
const unboxed = await box.decrypt(wrap_key)
|
||||
const box = await SecretWrap.wrap(key, wrap_key)
|
||||
const unboxed = await box.unwrap(wrap_key)
|
||||
expect(unboxed).not.toBeNull()
|
||||
return unboxed!
|
||||
}
|
||||
async function cant_seal(key: CryptoKey): Promise<void> {
|
||||
expect(key.extractable).toBeFalse()
|
||||
expect(SecretWrap.encrypt(key, wrap_key)).rejects.toThrow()
|
||||
expect(SecretWrap.wrap(key, wrap_key)).rejects.toThrow()
|
||||
}
|
||||
|
||||
test('Signature', async () => {
|
||||
@@ -29,10 +29,10 @@ test('Signature', async () => {
|
||||
})
|
||||
test('SecretWrap', async () => {
|
||||
let k = await SecretWrap.gen(true)
|
||||
const box = await SecretWrap.encrypt(k, k) // Please kids, never do this for real !
|
||||
const box = await SecretWrap.wrap(k, k) // Please kids, never do this for real !
|
||||
k = await seal(k)
|
||||
|
||||
const unbox = await box.decrypt(k)
|
||||
const unbox = await box.unwrap(k)
|
||||
expect(unbox).not.toBeNull()
|
||||
expect(unbox).toEqual(k)
|
||||
})
|
||||
@@ -48,10 +48,10 @@ test('SecretBox', async () => {
|
||||
})
|
||||
test('PrivateWrap', async () => {
|
||||
const k = await PrivateWrap.gen(true)
|
||||
const box = await PrivateWrap.encrypt(wrap_key, k.publicKey)
|
||||
const box = await PrivateWrap.wrap(wrap_key, k.publicKey)
|
||||
const privk = await seal(k.privateKey)
|
||||
|
||||
const unbox = await box.decrypt(privk)
|
||||
const unbox = await box.unwrap(privk)
|
||||
expect(unbox).not.toBeNull()
|
||||
expect(unbox).toEqual(wrap_key)
|
||||
})
|
||||
@@ -67,8 +67,8 @@ test('PrivateBox', async () => {
|
||||
})
|
||||
test("Can't unwrap with a different key", async () => {
|
||||
const wrap_k2 = await SecretWrap.gen(false)
|
||||
const box = await SecretWrap.encrypt(wrap_key, wrap_key) // Never do this kids !
|
||||
const unbox = await box.decrypt(wrap_k2)
|
||||
const box = await SecretWrap.wrap(wrap_key, wrap_key) // Never do this kids !
|
||||
const unbox = await box.unwrap(wrap_k2)
|
||||
expect(unbox).toBeNull()
|
||||
})
|
||||
test('Cant wrap non-extractable', async () => {
|
||||
|
||||
Reference in New Issue
Block a user