From 6bdb8c0906ddebd79c73f26a9809155e1e865a88 Mon Sep 17 00:00:00 2001 From: Steve Hetzel Date: Wed, 31 Jan 2024 15:14:01 -0700 Subject: [PATCH] feat: add some comments --- src/crypto/crypto.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/crypto/crypto.ts b/src/crypto/crypto.ts index 30feea1cb..9e3141f44 100644 --- a/src/crypto/crypto.ts +++ b/src/crypto/crypto.ts @@ -358,6 +358,7 @@ export class Crypto extends AsyncOptionalCreatable { private decryptV2(tokens: string[]): Optional { const tag = tokens[1]; + // assume the iv is v2 length (12 bytes) when parsing. const iv = tokens[0].substring(0, IV_BYTES.v2 * 2); const secret = tokens[0].substring(IV_BYTES.v2 * 2, tokens[0].length); @@ -381,6 +382,8 @@ export class Crypto extends AsyncOptionalCreatable { throw error; }; + // This happens when the iv is v1 length (6 bytes), and the key is v1 length. + // We re-parse the tokens for iv and secret based on that length. if (this.v1KeyLength && err?.message === 'Unsupported state or unable to authenticate data') { getCryptoLogger().debug('v2 decryption failed so trying v1 decryption'); try {