diff --git a/src/webcrypto.ts b/src/webcrypto.ts index 0264c06..c4a3ccb 100644 --- a/src/webcrypto.ts +++ b/src/webcrypto.ts @@ -75,8 +75,11 @@ type BlockMode = (typeof mode)[keyof typeof mode]; function getCryptParams(algo: BlockMode, nonce: Uint8Array, AAD?: Uint8Array) { if (algo === mode.CBC) return { name: mode.CBC, iv: nonce }; if (algo === mode.CTR) return { name: mode.CTR, counter: nonce, length: 64 }; - if (algo === mode.GCM) - return { name: mode.GCM, iv: nonce, additionalData: AAD || new Uint8Array(0) }; + if (algo === mode.GCM) { + if (AAD) return { name: mode.GCM, iv: nonce, additionalData: AAD }; + else return { name: mode.GCM, iv: nonce }; + } + throw new Error('unknown aes block mode'); }