From a0409601cc5ab9bbd44cf5113d409a92c65b7f2c Mon Sep 17 00:00:00 2001 From: larabr <7375870+larabr@users.noreply.github.com> Date: Mon, 22 Mar 2021 14:30:29 +0100 Subject: [PATCH] Fix packet import --- src/util.js | 6 ++++-- test/general/key.js | 8 ++++++-- test/general/packet.js | 3 +-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util.js b/src/util.js index b8627df96d..9c153c551a 100644 --- a/src/util.js +++ b/src/util.js @@ -682,10 +682,12 @@ const util = { * @param {Array} allowedClasses * @returns {Object} map from enum.packet to corresponding *Packet class */ - constructAllowedPackets: /*#__PURE__*/ function(allowedClasses) { + constructAllowedPackets: function(allowedClasses) { const map = {}; allowedClasses.forEach(PacketClass => { - if (!PacketClass.tag) return; + if (!PacketClass.tag) { + throw new Error('Invalid input: expected a packet class'); + } map[PacketClass.tag] = PacketClass; }); return map; diff --git a/test/general/key.js b/test/general/key.js index 1742d23488..16b424a9ea 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -4,7 +4,6 @@ const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../..'); const util = require('../../src/util'); const key = require('../../src/key'); -const allPackets = require('../../src/packet/all_packets'); const chai = require('chai'); chai.use(require('chai-as-promised')); @@ -2785,7 +2784,12 @@ module.exports = () => describe('Key', function() { const packetlist = new openpgp.PacketList(); - await packetlist.read((await openpgp.unarmor(pub_sig_test)).data, util.constructAllowedPackets([...Object.values(allPackets)]), undefined, openpgp.config); + await packetlist.read( + (await openpgp.unarmor(pub_sig_test)).data, + util.constructAllowedPackets([...Object.values(openpgp).filter(packetClass => !!packetClass.tag)]), + undefined, + openpgp.config + ); const subkeys = pubKey.getSubkeys(); expect(subkeys).to.exist; diff --git a/test/general/packet.js b/test/general/packet.js index cbb0b7ab57..bfcc3ca424 100644 --- a/test/general/packet.js +++ b/test/general/packet.js @@ -3,7 +3,6 @@ const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../..'); const crypto = require('../../src/crypto'); const util = require('../../src/util'); -const allPackets = require('../../src/packet/all_packets'); const stub = require('sinon/lib/sinon/stub'); const chai = require('chai'); @@ -29,7 +28,7 @@ function stringify(array) { } module.exports = () => describe("Packet", function() { - const allAllowedPackets = util.constructAllowedPackets([...Object.values(allPackets)]); + const allAllowedPackets = util.constructAllowedPackets([...Object.values(openpgp).filter(packetClass => !!packetClass.tag)]); const armored_key = '-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +