Skip to content

Commit

Permalink
Fix packet import
Browse files Browse the repository at this point in the history
  • Loading branch information
larabr committed Mar 22, 2021
1 parent 3cc0f8d commit a040960
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/util.js
Expand Up @@ -682,10 +682,12 @@ const util = {
* @param {Array<Object>} 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;
Expand Down
8 changes: 6 additions & 2 deletions test/general/key.js
Expand Up @@ -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'));
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions test/general/packet.js
Expand Up @@ -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');
Expand All @@ -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' +
Expand Down

0 comments on commit a040960

Please sign in to comment.