Bundle legacy ciphers in a single chunk

This commit is contained in:
larabr 2024-02-05 14:10:07 +01:00
parent 057f5fe33b
commit 55f3ea22f2
2 changed files with 27 additions and 15 deletions

View File

@ -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');
}
}

View File

@ -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]
]);