Merge pull request #540 from openpgpjs/err_handling
Tolerant flag for suppressing packet read errors
This commit is contained in:
commit
5db776c254
|
@ -44,6 +44,7 @@ export default {
|
|||
use_native: true, // use native node.js crypto and Web Crypto apis (if available)
|
||||
zero_copy: false, // use transferable objects between the Web Worker and main thread
|
||||
debug: false,
|
||||
tolerant: true, // ignore unsupported/unrecognizable packets instead of throwing an error
|
||||
show_version: true,
|
||||
show_comment: true,
|
||||
versionstring: "OpenPGP.js VERSION",
|
||||
|
|
|
@ -120,7 +120,7 @@ Compressed.prototype.decompress = function () {
|
|||
throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
|
||||
|
||||
default:
|
||||
throw new Error("Compression algorithm unknown :" + this.alogrithm);
|
||||
throw new Error("Compression algorithm unknown :" + this.algorithm);
|
||||
}
|
||||
|
||||
this.packets.read(decompressed);
|
||||
|
|
|
@ -15,6 +15,7 @@ import util from '../util';
|
|||
import packetParser from './packet.js';
|
||||
import * as packets from './all_packets.js';
|
||||
import enums from '../enums.js';
|
||||
import config from '../config';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
|
@ -44,6 +45,9 @@ Packetlist.prototype.read = function (bytes) {
|
|||
pushed = true;
|
||||
packet.read(parsed.packet);
|
||||
} catch(e) {
|
||||
if (!config.tolerant || parsed.tag == enums.packet.symmetricallyEncrypted || parsed.tag == enums.packet.literal || parsed.tag == enums.packet.compressed) {
|
||||
throw e;
|
||||
}
|
||||
if (pushed) {
|
||||
this.pop(); // drop unsupported packet
|
||||
}
|
||||
|
|
|
@ -527,7 +527,8 @@ describe('Key', function() {
|
|||
'=Q/kB',
|
||||
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
||||
|
||||
it('Parsing armored text with RSA key and ECC subkey', function(done) {
|
||||
it('Parsing armored text with RSA key and ECC subkey in tolerant mode', function(done) {
|
||||
openpgp.config.tolerant = true;
|
||||
var pubKeys = openpgp.key.readArmored(rsa_ecc_pub);
|
||||
expect(pubKeys).to.exist;
|
||||
expect(pubKeys.err).to.not.exist;
|
||||
|
@ -536,6 +537,15 @@ describe('Key', function() {
|
|||
done();
|
||||
});
|
||||
|
||||
it('Parsing armored text with RSA key and ECC subkey in non-tolerant mode', function(done) {
|
||||
openpgp.config.tolerant = false;
|
||||
var pubKeys = openpgp.key.readArmored(rsa_ecc_pub);
|
||||
expect(pubKeys).to.exist;
|
||||
expect(pubKeys.err).to.exist;
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
var multi_uid_key =
|
||||
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
||||
'Version: GnuPG v1',
|
||||
|
|
Loading…
Reference in New Issue
Block a user