This commit is contained in:
+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