Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Deno support #1448

Merged
merged 3 commits into from Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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, using /dist/openpgp.mjs.

```js
import * as openpgp from "./openpgpgjs/dist/openpgp.mjs";
Hexagon marked this conversation as resolved.
Show resolved Hide resolved
```

#### Browser (webpack)

Install OpenPGP.js using npm and save it in your devDependencies:
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/hash/index.js
Expand Up @@ -77,7 +77,7 @@ if (nodeCrypto) { // Use Node native crypto for all hash functions
} else { // Use JS fallbacks
hashFunctions = {
md5: md5,
sha1: asmcryptoHash(Sha1, navigator.userAgent.indexOf('Edge') === -1 && 'SHA-1'),
sha1: asmcryptoHash(Sha1, (!navigator.userAgent || navigator.userAgent.indexOf('Edge') === -1) && 'SHA-1'),
sha224: hashjsHash(sha224),
sha256: asmcryptoHash(Sha256, 'SHA-256'),
sha384: hashjsHash(sha384, 'SHA-384'),
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/mode/eax.js
Expand Up @@ -51,7 +51,7 @@ async function CTR(key) {
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
(!navigator.userAgent || navigator.userAgent.indexOf('Edge') === -1)
) {
key = await webCrypto.importKey('raw', key, { name: 'AES-CTR', length: key.length * 8 }, false, ['encrypt']);
return async function(pt, iv) {
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/mode/gcm.js
Expand Up @@ -56,7 +56,7 @@ async function GCM(cipher, key) {
!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 && navigator.userAgent && navigator.userAgent.indexOf('Edge') !== -1)
// Edge does not support GCM-en/decrypting without ADATA
) {
return AES_GCM.encrypt(pt, key, iv, adata);
Expand All @@ -70,7 +70,7 @@ async function GCM(cipher, key) {
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 && navigator.userAgent && navigator.userAgent.indexOf('Edge') !== -1)
// Edge does not support GCM-en/decrypting without ADATA
) {
return AES_GCM.decrypt(ct, key, iv, adata);
Expand Down
2 changes: 1 addition & 1 deletion test/worker/application_worker.js
Expand Up @@ -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.userAgent && /Edge/.test(navigator.userAgent)) {
this.skip(); // Old Edge doesn't support crypto.getRandomValues inside a Worker.
}
try {
Expand Down