diff --git a/README.md b/README.md index 6b8660bdfd..f79cd8c23a 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ OpenPGP.js [![BrowserStack Status](https://automate.browserstack.com/badge.svg?b - [Performance](#performance) - [Getting started](#getting-started) - [Node.js](#nodejs) + - [Deno (experimental)](#deno-experimental) - [Browser (webpack)](#browser-webpack) - [Browser (plain files)](#browser-plain-files) - [Examples](#examples) @@ -109,6 +110,14 @@ Or as an ES6 module, from an .mjs file: import * as openpgp from 'openpgp'; ``` +#### Deno (experimental) + +Import as an ES6 module, from an .mjs file on a CDN of your choice. + +```js +import * as openpgp from "https://cdn.jsdelivr.net/npm/openpgp@5/dist/openpgp.mjs"; +``` + #### Browser (webpack) Install OpenPGP.js using npm and save it in your devDependencies: diff --git a/src/crypto/hash/index.js b/src/crypto/hash/index.js index cfec8d381e..8537b68505 100644 --- a/src/crypto/hash/index.js +++ b/src/crypto/hash/index.js @@ -75,9 +75,14 @@ if (nodeCrypto) { // Use Node native crypto for all hash functions ripemd: nodeHash('ripemd160') }; } else { // Use JS fallbacks + let webCryptoHash = false, + hasUserAgentCaps = navigator && navigator.userAgent; + if (hasUserAgentCaps && navigator.userAgent.indexOf('Edge') === -1) { + webCryptoHash = 'SHA-1'; + } hashFunctions = { md5: md5, - sha1: asmcryptoHash(Sha1, navigator.userAgent.indexOf('Edge') === -1 && 'SHA-1'), + sha1: asmcryptoHash(Sha1, webCryptoHash), sha224: hashjsHash(sha224), sha256: asmcryptoHash(Sha256, 'SHA-256'), sha384: hashjsHash(sha384, 'SHA-384'), diff --git a/src/crypto/mode/eax.js b/src/crypto/mode/eax.js index cf68c4600e..c0f53fdd94 100644 --- a/src/crypto/mode/eax.js +++ b/src/crypto/mode/eax.js @@ -48,10 +48,13 @@ async function OMAC(key) { } async function CTR(key) { + let + hasUserAgentCaps = navigator && navigator.userAgent, + isEdge = hasUserAgentCaps && navigator.userAgent.indexOf('Edge') !== -1; if ( util.getWebCrypto() && key.length !== 24 && // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support - navigator.userAgent.indexOf('Edge') === -1 + (!isEdge) ) { key = await webCrypto.importKey('raw', key, { name: 'AES-CTR', length: key.length * 8 }, false, ['encrypt']); return async function(pt, iv) { diff --git a/src/crypto/mode/gcm.js b/src/crypto/mode/gcm.js index 424b7e1afb..a310d2c850 100644 --- a/src/crypto/mode/gcm.js +++ b/src/crypto/mode/gcm.js @@ -52,11 +52,14 @@ async function GCM(cipher, key) { return { encrypt: async function(pt, iv, adata = new Uint8Array()) { + let + hasUserAgentCaps = navigator && navigator.userAgent, + isEdge = hasUserAgentCaps && navigator.userAgent.indexOf('Edge') !== -1; if ( !pt.length || // iOS does not support GCM-en/decrypting empty messages // Also, synchronous en/decryption might be faster in this case. - (!adata.length && navigator.userAgent.indexOf('Edge') !== -1) + (!adata.length && isEdge) // Edge does not support GCM-en/decrypting without ADATA ) { return AES_GCM.encrypt(pt, key, iv, adata); @@ -66,11 +69,14 @@ async function GCM(cipher, key) { }, decrypt: async function(ct, iv, adata = new Uint8Array()) { + let + hasUserAgentCaps = navigator && navigator.userAgent, + isEdge = hasUserAgentCaps && navigator.userAgent.indexOf('Edge') !== -1; if ( ct.length === tagLength || // iOS does not support GCM-en/decrypting empty messages // Also, synchronous en/decryption might be faster in this case. - (!adata.length && navigator.userAgent.indexOf('Edge') !== -1) + (!adata.length && isEdge) // Edge does not support GCM-en/decrypting without ADATA ) { return AES_GCM.decrypt(ct, key, iv, adata); diff --git a/src/util.js b/src/util.js index a510bc3945..b49fd9bb6e 100644 --- a/src/util.js +++ b/src/util.js @@ -429,8 +429,11 @@ const util = { const os = require('os'); return os.cpus().length; } - - return navigator.hardwareConcurrency || 1; + if (navigator && navigator.hardwareConcurrency) { + return navigator.hardwareConcurrency || 1; + } else { + return 1; + } }, isEmailAddress: function(data) { diff --git a/test/general/streaming.js b/test/general/streaming.js index 6839f1f4ff..62327ca9ff 100644 --- a/test/general/streaming.js +++ b/test/general/streaming.js @@ -918,7 +918,9 @@ function tests() { if (util.detectNode()) { coresStub.restore(); } else { - delete navigator.hardwareConcurrency; + if (navigator && navigator.hardwareConcurrency !== void 0) { + delete navigator.hardwareConcurrency; + } } } }); diff --git a/test/worker/application_worker.js b/test/worker/application_worker.js index f40dd9f559..1de0396425 100644 --- a/test/worker/application_worker.js +++ b/test/worker/application_worker.js @@ -12,7 +12,7 @@ module.exports = () => tryTests('Application Worker', tests, { function tests() { it('Should support loading OpenPGP.js from inside a Web Worker', async function() { - if (/Edge/.test(navigator.userAgent)) { + if (navigator && navigator.userAgent && /Edge/.test(navigator.userAgent)) { this.skip(); // Old Edge doesn't support crypto.getRandomValues inside a Worker. } try {