mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-03-30 15:08:32 +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 packetlist = await PacketList.fromBinary(input, allowedKeyPackets, config);
|
||||
const keyIndex = packetlist.indexOfTag(enums.packet.secretKey);
|
||||
if (keyIndex.length === 0) {
|
||||
throw new Error('No secret key packet found');
|
||||
}
|
||||
const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
|
||||
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 newKey = new PrivateKey(oneKeyList);
|
||||
keys.push(newKey);
|
||||
}
|
||||
if (keys.length === 0) {
|
||||
throw new Error('No secret key packet found');
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user