From f8057394d936231fab12626cf0e43dc0549de8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Conselheiro?= Date: Mon, 29 Apr 2024 08:05:14 -0300 Subject: [PATCH] removing additionalData for AES-GCM when undefined --- src/webcrypto.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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'); }