mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-22 16:13:41 +00:00
Add config parameter to top-level functions (#1241)
Refactor functions to take the configuration as a parameter.
This allows setting a config option for a single function call, whereas
setting `openpgp.config` could lead to concurrency-related issues when
multiple async function calls are made at the same time.
`openpgp.config` is used as default for unset config values in top-level
functions.
`openpgp.config` is used as default config object in low-level functions
(i.e., when calling a low-level function, it may be required to pass
`{ ...openpgp.config, modifiedConfig: modifiedValue }`).
Also,
- remove `config.rsaBlinding`: blinding is now always applied to RSA decryption
- remove `config.debug`: debugging mode can be enabled by setting
`process.env.NODE_ENV = 'development'`
- remove `config.useNative`: native crypto is always used when available
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
|
||||
import stream from 'web-stream-tools';
|
||||
import config from '../config';
|
||||
import crypto from '../crypto';
|
||||
import enums from '../enums';
|
||||
import util from '../util';
|
||||
@@ -35,6 +34,7 @@ import {
|
||||
OnePassSignaturePacket,
|
||||
SignaturePacket
|
||||
} from '../packet';
|
||||
import defaultConfig from '../config';
|
||||
|
||||
/**
|
||||
* Implementation of the Symmetrically Encrypted Data Packet (Tag 9)
|
||||
@@ -63,11 +63,6 @@ class SymmetricallyEncryptedDataPacket {
|
||||
* @type {PacketList}
|
||||
*/
|
||||
this.packets = null;
|
||||
/**
|
||||
* When true, decrypt fails if message is not integrity protected
|
||||
* @see module:config.ignoreMdcError
|
||||
*/
|
||||
this.ignoreMdcError = config.ignoreMdcError;
|
||||
}
|
||||
|
||||
read(bytes) {
|
||||
@@ -83,12 +78,14 @@ class SymmetricallyEncryptedDataPacket {
|
||||
* See {@link https://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2} for algorithms.
|
||||
* @param {module:enums.symmetric} sessionKeyAlgorithm Symmetric key algorithm to use
|
||||
* @param {Uint8Array} key The key of cipher blocksize length to be used
|
||||
* @param {Object} config (optional) full configuration, defaults to openpgp.config
|
||||
|
||||
* @throws {Error} if decryption was not successful
|
||||
* @async
|
||||
*/
|
||||
async decrypt(sessionKeyAlgorithm, key, streaming) {
|
||||
async decrypt(sessionKeyAlgorithm, key, streaming, config = defaultConfig) {
|
||||
// If MDC errors are not being ignored, all missing MDC packets in symmetrically encrypted data should throw an error
|
||||
if (!this.ignoreMdcError) {
|
||||
if (!config.ignoreMdcError) {
|
||||
throw new Error('Decryption failed due to missing MDC.');
|
||||
}
|
||||
|
||||
@@ -111,15 +108,16 @@ class SymmetricallyEncryptedDataPacket {
|
||||
* See {@link https://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2} for algorithms.
|
||||
* @param {module:enums.symmetric} sessionKeyAlgorithm Symmetric key algorithm to use
|
||||
* @param {Uint8Array} key The key of cipher blocksize length to be used
|
||||
* @param {Object} config (optional) full configuration, defaults to openpgp.config
|
||||
* @throws {Error} if encryption was not successful
|
||||
* @async
|
||||
*/
|
||||
async encrypt(algo, key) {
|
||||
async encrypt(algo, key, streaming, config = defaultConfig) {
|
||||
const data = this.packets.write();
|
||||
|
||||
const prefix = await crypto.getPrefixRandom(algo);
|
||||
const FRE = await crypto.cfb.encrypt(algo, key, prefix, new Uint8Array(crypto.cipher[algo].blockSize));
|
||||
const ciphertext = await crypto.cfb.encrypt(algo, key, data, FRE.subarray(2));
|
||||
const FRE = await crypto.cfb.encrypt(algo, key, prefix, new Uint8Array(crypto.cipher[algo].blockSize), config);
|
||||
const ciphertext = await crypto.cfb.encrypt(algo, key, data, FRE.subarray(2), config);
|
||||
this.encrypted = util.concat([FRE, ciphertext]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user