From a5d894f514bf0fa8c7c15322d5652fddc29379a8 Mon Sep 17 00:00:00 2001 From: larabr <7375870+larabr@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:57:19 +0100 Subject: [PATCH] Internal: avoid importing `enums` in legacy_cipher chunk To avoid issues with the lightweight build: for now it works fine, but it could mess up chunking in the future, and it already results in a circular import. --- src/crypto/cipher/index.js | 3 ++- src/crypto/cipher/legacy_ciphers.js | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/crypto/cipher/index.js b/src/crypto/cipher/index.js index 88c1b9cb..7a1a8ec8 100644 --- a/src/crypto/cipher/index.js +++ b/src/crypto/cipher/index.js @@ -11,7 +11,8 @@ export async function getLegacyCipher(algo) { case enums.symmetric.twofish: case enums.symmetric.tripledes: { const { legacyCiphers } = await import('./legacy_ciphers'); - const cipher = legacyCiphers.get(algo); + const algoName = enums.read(enums.symmetric, algo); + const cipher = legacyCiphers.get(algoName); if (!cipher) { throw new Error('Unsupported cipher algorithm'); } diff --git a/src/crypto/cipher/legacy_ciphers.js b/src/crypto/cipher/legacy_ciphers.js index f091d471..0fbf62f9 100644 --- a/src/crypto/cipher/legacy_ciphers.js +++ b/src/crypto/cipher/legacy_ciphers.js @@ -3,15 +3,16 @@ * Separate dynamic imports are not convenient as they result in multiple chunks. */ -import { TripleDES } from './des'; -import CAST5 from './cast5'; -import TwoFish from './twofish'; -import BlowFish from './blowfish'; -import enums from '../../enums'; +import { TripleDES as tripledes } from './des'; +import cast5 from './cast5'; +import twofish from './twofish'; +import blowfish from './blowfish'; -export const legacyCiphers = new Map([ - [enums.symmetric.tripledes, TripleDES], - [enums.symmetric.cast5, CAST5], - [enums.symmetric.blowfish, BlowFish], - [enums.symmetric.twofish, TwoFish] -]); +// We avoid importing 'enums' as this module is lazy loaded, and doing so could mess up +// chunking for the lightweight build +export const legacyCiphers = new Map(Object.entries({ + tripledes, + cast5, + twofish, + blowfish +}));