Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/openpgpjs/openpgpjs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Huigens <d.huigens@protonmail.com>2022-06-29 21:59:38 +0300
committerGitHub <noreply@github.com>2022-06-29 21:59:38 +0300
commit04e806e0b4a6872652e48d7df2d443e9e0d81597 (patch)
treea02b7c4179a7bcad19fbf4343fefeb580a420f10
parente69d8b24fc373342fadf6acd4602ca63105992d1 (diff)
Support Node.js 18 (#1542)
Recent Node.js seems to have dropped support for ripemd160. Thus, properly check the availability of hashes before using them. Also, add Node.js 18 to CI.
-rw-r--r--.github/workflows/node.js.yml2
-rw-r--r--src/crypto/hash/index.js35
2 files changed, 14 insertions, 23 deletions
diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml
index 07ee301d..11a05029 100644
--- a/.github/workflows/node.js.yml
+++ b/.github/workflows/node.js.yml
@@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
- node-version: [12.x, 14.x, 16.x]
+ node-version: [12.x, 14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
diff --git a/src/crypto/hash/index.js b/src/crypto/hash/index.js
index 27f42c6b..0765881e 100644
--- a/src/crypto/hash/index.js
+++ b/src/crypto/hash/index.js
@@ -20,8 +20,12 @@ import enums from '../../enums';
const webCrypto = util.getWebCrypto();
const nodeCrypto = util.getNodeCrypto();
+const nodeCryptoHashes = nodeCrypto && nodeCrypto.getHashes();
function nodeHash(type) {
+ if (!nodeCrypto || !nodeCryptoHashes.includes(type)) {
+ return;
+ }
return async function (data) {
const shasum = nodeCrypto.createHash(type);
return stream.transform(data, value => {
@@ -63,28 +67,15 @@ function asmcryptoHash(hash, webCryptoHash) {
};
}
-let hashFunctions;
-if (nodeCrypto) { // Use Node native crypto for all hash functions
- hashFunctions = {
- md5: nodeHash('md5'),
- sha1: nodeHash('sha1'),
- sha224: nodeHash('sha224'),
- sha256: nodeHash('sha256'),
- sha384: nodeHash('sha384'),
- sha512: nodeHash('sha512'),
- ripemd: nodeHash('ripemd160')
- };
-} else { // Use JS fallbacks
- hashFunctions = {
- md5: md5,
- sha1: asmcryptoHash(Sha1, 'SHA-1'),
- sha224: hashjsHash(sha224),
- sha256: asmcryptoHash(Sha256, 'SHA-256'),
- sha384: hashjsHash(sha384, 'SHA-384'),
- sha512: hashjsHash(sha512, 'SHA-512'), // asmcrypto sha512 is huge.
- ripemd: hashjsHash(ripemd160)
- };
-}
+const hashFunctions = {
+ md5: nodeHash('md5') || md5,
+ sha1: nodeHash('sha1') || asmcryptoHash(Sha1, 'SHA-1'),
+ sha224: nodeHash('sha224') || hashjsHash(sha224),
+ sha256: nodeHash('sha256') || asmcryptoHash(Sha256, 'SHA-256'),
+ sha384: nodeHash('sha384') || hashjsHash(sha384, 'SHA-384'),
+ sha512: nodeHash('sha512') || hashjsHash(sha512, 'SHA-512'), // asmcrypto sha512 is huge.
+ ripemd: nodeHash('ripemd160') || hashjsHash(ripemd160)
+};
export default {