diff --git a/src/crypto/cipher/index.js b/src/crypto/cipher/index.js index 662a4d19..878b05c0 100644 --- a/src/crypto/cipher/index.js +++ b/src/crypto/cipher/index.js @@ -7,24 +7,19 @@ export async function getCipher(algo) { case enums.symmetric.aes192: case enums.symmetric.aes256: return aes(getCipherKeySize(algo)); + case enums.symmetric.cast5: + case enums.symmetric.blowfish: + case enums.symmetric.twofish: case enums.symmetric.tripledes: { - const { TripleDES } = await import('./des'); - return TripleDES; - } - case enums.symmetric.cast5: { - const { default: CAST5 } = await import('./cast5'); - return CAST5; - } - case enums.symmetric.twofish: { - const { default: TwoFish } = await import('./twofish'); - return TwoFish; - } - case enums.symmetric.blowfish: { - const { default: BlowFish } = await import('./blowfish'); - return BlowFish; + const { legacyCiphers } = await import('./legacy_ciphers'); + const cipher = legacyCiphers.get(algo); + if (!cipher) { + throw new Error('Unsupported cipher algorithm'); + } + return cipher; } default: - throw new Error('Unsupported symmetric-key algorithm'); + throw new Error('Unsupported cipher algorithm'); } } diff --git a/src/crypto/cipher/legacy_ciphers.js b/src/crypto/cipher/legacy_ciphers.js new file mode 100644 index 00000000..f091d471 --- /dev/null +++ b/src/crypto/cipher/legacy_ciphers.js @@ -0,0 +1,17 @@ +/** + * This file is needed to dynamic import the legacy ciphers. + * 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'; + +export const legacyCiphers = new Map([ + [enums.symmetric.tripledes, TripleDES], + [enums.symmetric.cast5, CAST5], + [enums.symmetric.blowfish, BlowFish], + [enums.symmetric.twofish, TwoFish] +]);