mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-10-14 00:59:29 +00:00
readPrivateKeys
: support parsing key block with mix of private and public keys
Previously, parsing a key block where a public key followed a private one would fail.
This commit is contained in:
parent
cf0285add5
commit
ad7165dfd0
@ -456,14 +456,17 @@ export async function readPrivateKeys({ armoredKeys, binaryKeys, config }) {
|
|||||||
}
|
}
|
||||||
const keys = [];
|
const keys = [];
|
||||||
const packetlist = await PacketList.fromBinary(input, allowedKeyPackets, config);
|
const packetlist = await PacketList.fromBinary(input, allowedKeyPackets, config);
|
||||||
const keyIndex = packetlist.indexOfTag(enums.packet.secretKey);
|
const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
|
||||||
if (keyIndex.length === 0) {
|
|
||||||
throw new Error('No secret key packet found');
|
|
||||||
}
|
|
||||||
for (let i = 0; i < keyIndex.length; i++) {
|
for (let i = 0; i < keyIndex.length; i++) {
|
||||||
|
if (packetlist[keyIndex[i]].constructor.tag === enums.packet.publicKey) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const oneKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]);
|
const oneKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]);
|
||||||
const newKey = new PrivateKey(oneKeyList);
|
const newKey = new PrivateKey(oneKeyList);
|
||||||
keys.push(newKey);
|
keys.push(newKey);
|
||||||
}
|
}
|
||||||
|
if (keys.length === 0) {
|
||||||
|
throw new Error('No secret key packet found');
|
||||||
|
}
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user