mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-11-27 07:48:40 +00:00
Key.getSigningKey: prefer private decrypted (sub)keys
If dummy or public (sub)key packets are present alongside secret ones, the latter are now selected first, regardless of creation date.
This commit is contained in:
parent
1f574e0df7
commit
36308615ad
@ -273,7 +273,13 @@ class Key {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw util.wrapError('Could not verify primary key', err);
|
throw util.wrapError('Could not verify primary key', err);
|
||||||
}
|
}
|
||||||
const subkeys = this.subkeys.slice().sort((a, b) => b.keyPacket.created - a.keyPacket.created);
|
const subkeys = this.subkeys.slice().sort((a, b) => {
|
||||||
|
const aIsPrivate = a.isDecrypted() !== null && !a.isDummy();
|
||||||
|
const bIsPrivate = b.isDecrypted() !== null && !b.isDummy();
|
||||||
|
const diffIsPrivate = bIsPrivate - aIsPrivate;
|
||||||
|
// return non-dummy private (sub)keys first
|
||||||
|
return diffIsPrivate !== 0 ? diffIsPrivate : b.keyPacket.created - a.keyPacket.created;
|
||||||
|
});
|
||||||
let exception;
|
let exception;
|
||||||
for (const subkey of subkeys) {
|
for (const subkey of subkeys) {
|
||||||
if (!keyID || subkey.getKeyID().equals(keyID)) {
|
if (!keyID || subkey.getKeyID().equals(keyID)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user