Don't use native streams in old Edge
This commit is contained in:
parent
2fffc76060
commit
3a84442b5f
|
@ -50,7 +50,12 @@ import './polyfills';
|
||||||
import util from './util';
|
import util from './util';
|
||||||
import AsyncProxy from './worker/async_proxy';
|
import AsyncProxy from './worker/async_proxy';
|
||||||
|
|
||||||
const toNativeReadable = global.ReadableStream && createReadableStreamWrapper(global.ReadableStream);
|
let toNativeReadable;
|
||||||
|
if (global.ReadableStream) {
|
||||||
|
try {
|
||||||
|
toNativeReadable = createReadableStreamWrapper(global.ReadableStream);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// //
|
// //
|
||||||
|
|
|
@ -1998,7 +1998,9 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
it('Streaming encrypt and decrypt small message roundtrip', async function() {
|
it('Streaming encrypt and decrypt small message roundtrip', async function() {
|
||||||
let plaintext = [];
|
let plaintext = [];
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const data = new (global.ReadableStream || openpgp.stream.ReadableStream)({
|
const useNativeStream = (() => { try { new global.ReadableStream(); return true; } catch (e) { return false; } })();
|
||||||
|
const ReadableStream = useNativeStream ? global.ReadableStream : openpgp.stream.ReadableStream;
|
||||||
|
const data = new ReadableStream({
|
||||||
async pull(controller) {
|
async pull(controller) {
|
||||||
if (i++ < 4) {
|
if (i++ < 4) {
|
||||||
let randomBytes = await openpgp.crypto.random.getRandomBytes(10);
|
let randomBytes = await openpgp.crypto.random.getRandomBytes(10);
|
||||||
|
@ -2013,7 +2015,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
message: openpgp.message.fromBinary(data),
|
message: openpgp.message.fromBinary(data),
|
||||||
passwords: ['test']
|
passwords: ['test']
|
||||||
}));
|
}));
|
||||||
expect(openpgp.util.isStream(encrypted.data)).to.equal(global.ReadableStream ? 'web' : 'ponyfill');
|
expect(openpgp.util.isStream(encrypted.data)).to.equal(useNativeStream ? 'web' : 'ponyfill');
|
||||||
|
|
||||||
const msgAsciiArmored = encrypted.data;
|
const msgAsciiArmored = encrypted.data;
|
||||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||||
|
@ -2022,7 +2024,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
message,
|
message,
|
||||||
format: 'binary'
|
format: 'binary'
|
||||||
});
|
});
|
||||||
expect(openpgp.util.isStream(decrypted.data)).to.equal(global.ReadableStream ? 'web' : 'ponyfill');
|
expect(openpgp.util.isStream(decrypted.data)).to.equal(useNativeStream ? 'web' : 'ponyfill');
|
||||||
expect(await openpgp.stream.readToEnd(decrypted.data)).to.deep.equal(openpgp.util.concatUint8Array(plaintext));
|
expect(await openpgp.stream.readToEnd(decrypted.data)).to.deep.equal(openpgp.util.concatUint8Array(plaintext));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2328,8 +2330,9 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
streaming: 'web',
|
streaming: 'web',
|
||||||
format: 'binary'
|
format: 'binary'
|
||||||
};
|
};
|
||||||
|
const useNativeStream = (() => { try { new global.ReadableStream(); return true; } catch (e) { return false; } })();
|
||||||
return openpgp.sign(signOpt).then(async function (signed) {
|
return openpgp.sign(signOpt).then(async function (signed) {
|
||||||
expect(openpgp.util.isStream(signed.data)).to.equal(global.ReadableStream ? 'web' : 'ponyfill');
|
expect(openpgp.util.isStream(signed.data)).to.equal(useNativeStream ? 'web' : 'ponyfill');
|
||||||
const message = await openpgp.message.read(signed.data);
|
const message = await openpgp.message.read(signed.data);
|
||||||
message.packets.concat(await openpgp.stream.readToEnd(message.packets.stream, _ => _));
|
message.packets.concat(await openpgp.stream.readToEnd(message.packets.stream, _ => _));
|
||||||
const packets = new openpgp.packet.List();
|
const packets = new openpgp.packet.List();
|
||||||
|
@ -2338,7 +2341,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
verifyOpt.message = new openpgp.message.Message(packets);
|
verifyOpt.message = new openpgp.message.Message(packets);
|
||||||
return openpgp.verify(verifyOpt);
|
return openpgp.verify(verifyOpt);
|
||||||
}).then(async function (verified) {
|
}).then(async function (verified) {
|
||||||
expect(openpgp.stream.isStream(verified.data)).to.equal(global.ReadableStream ? 'web' : 'ponyfill');
|
expect(openpgp.stream.isStream(verified.data)).to.equal(useNativeStream ? 'web' : 'ponyfill');
|
||||||
expect([].slice.call(await openpgp.stream.readToEnd(verified.data))).to.deep.equal([].slice.call(data));
|
expect([].slice.call(await openpgp.stream.readToEnd(verified.data))).to.deep.equal([].slice.call(data));
|
||||||
expect(await verified.signatures[0].verified).to.be.true;
|
expect(await verified.signatures[0].verified).to.be.true;
|
||||||
expect(await signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid))
|
expect(await signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid))
|
||||||
|
|
|
@ -9,7 +9,8 @@ const { expect } = chai;
|
||||||
|
|
||||||
const { stream, util } = openpgp;
|
const { stream, util } = openpgp;
|
||||||
|
|
||||||
const ReadableStream = global.ReadableStream || openpgp.stream.ReadableStream;
|
const useNativeStream = (() => { try { new global.ReadableStream(); return true; } catch (e) { return false; } })();
|
||||||
|
const ReadableStream = useNativeStream ? global.ReadableStream : openpgp.stream.ReadableStream;
|
||||||
|
|
||||||
const pub_key =
|
const pub_key =
|
||||||
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||||
|
@ -936,7 +937,7 @@ describe('Streaming', function() {
|
||||||
tryTests('WhatWG Streams', tests, {
|
tryTests('WhatWG Streams', tests, {
|
||||||
if: true,
|
if: true,
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
expectedType = global.ReadableStream ? 'web' : 'ponyfill';
|
expectedType = useNativeStream ? 'web' : 'ponyfill';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user