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:
@@ -6,7 +6,6 @@
|
||||
* @requires hash.js
|
||||
* @requires web-stream-tools
|
||||
* @requires crypto/hash/md5
|
||||
* @requires config
|
||||
* @requires util
|
||||
* @module crypto/hash
|
||||
*/
|
||||
@@ -19,8 +18,8 @@ import sha512 from 'hash.js/lib/hash/sha/512';
|
||||
import { ripemd160 } from 'hash.js/lib/hash/ripemd';
|
||||
import stream from 'web-stream-tools';
|
||||
import md5 from './md5';
|
||||
import config from '../../config';
|
||||
import util from '../../util';
|
||||
import defaultConfig from '../../config';
|
||||
|
||||
const webCrypto = util.getWebCrypto();
|
||||
const nodeCrypto = util.getNodeCrypto();
|
||||
@@ -36,7 +35,7 @@ function node_hash(type) {
|
||||
}
|
||||
|
||||
function hashjs_hash(hash, webCryptoHash) {
|
||||
return async function(data) {
|
||||
return async function(data, config = defaultConfig) {
|
||||
if (!util.isStream(data) && webCrypto && webCryptoHash && data.length >= config.minBytesForWebCrypto) {
|
||||
return new Uint8Array(await webCrypto.digest(webCryptoHash, data));
|
||||
}
|
||||
@@ -48,7 +47,7 @@ function hashjs_hash(hash, webCryptoHash) {
|
||||
}
|
||||
|
||||
function asmcrypto_hash(hash, webCryptoHash) {
|
||||
return async function(data) {
|
||||
return async function(data, config = defaultConfig) {
|
||||
if (util.isStream(data)) {
|
||||
const hashInstance = new hash();
|
||||
return stream.transform(data, value => {
|
||||
|
||||
Reference in New Issue
Block a user