Internal: improve tree-shaking for crypto modules

Every submodule under the 'crypto' directory was exported-imported
even if a handful of functions where actually needed.
We now only export entire modules behind default exports if it makes
sense for readability and if the different submodules would be
imported together anyway (e.g. `cipherMode` exports are all needed
by the SEIPD class).

We've also dropped exports that are not used outside of the crypto modules,
e.g. pkcs5 helpers.
This commit is contained in:
larabr
2024-11-20 15:28:21 +01:00
parent bf85deedb8
commit 2a8969b437
41 changed files with 336 additions and 388 deletions

View File

@@ -19,7 +19,7 @@ import * as stream from '@openpgp/web-stream-tools';
import { armor, unarmor } from './encoding/armor';
import { Argon2OutOfMemoryError } from './type/s2k';
import defaultConfig from './config';
import crypto from './crypto';
import { generateSessionKey } from './crypto';
import enums from './enums';
import util from './util';
import { Signature } from './signature';
@@ -255,7 +255,7 @@ export class Message {
pkeskPacketCopy.read(serialisedPKESK);
const randomSessionKey = {
sessionKeyAlgorithm,
sessionKey: crypto.generateSessionKey(sessionKeyAlgorithm)
sessionKey: generateSessionKey(sessionKeyAlgorithm)
};
try {
await pkeskPacketCopy.decrypt(decryptionKeyPacket, randomSessionKey);
@@ -368,7 +368,7 @@ export class Message {
})
));
const sessionKeyData = crypto.generateSessionKey(symmetricAlgo);
const sessionKeyData = generateSessionKey(symmetricAlgo);
return { data: sessionKeyData, algorithm: symmetricAlgoName, aeadAlgorithm: aeadAlgoName };
}