mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-21 15:49:09 +00:00
prioritize signing with subkeys when possible
This commit is contained in:
10
src/key.js
10
src/key.js
@@ -287,11 +287,6 @@ function isValidSigningKeyPacket(keyPacket, signature, date=new Date()) {
|
||||
Key.prototype.getSigningKeyPacket = async function (keyId=null, date=new Date(), userId={}) {
|
||||
const primaryKey = this.primaryKey;
|
||||
if (await this.verifyPrimaryKey(date, userId) === enums.keyStatus.valid) {
|
||||
const primaryUser = await this.getPrimaryUser(date, userId);
|
||||
if (primaryUser && (!keyId || primaryKey.getKeyId().equals(keyId)) &&
|
||||
isValidSigningKeyPacket(primaryKey, primaryUser.selfCertification, date)) {
|
||||
return primaryKey;
|
||||
}
|
||||
for (let i = 0; i < this.subKeys.length; i++) {
|
||||
if (!keyId || this.subKeys[i].subKey.getKeyId().equals(keyId)) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
@@ -303,6 +298,11 @@ Key.prototype.getSigningKeyPacket = async function (keyId=null, date=new Date(),
|
||||
}
|
||||
}
|
||||
}
|
||||
const primaryUser = await this.getPrimaryUser(date, userId);
|
||||
if (primaryUser && (!keyId || primaryKey.getKeyId().equals(keyId)) &&
|
||||
isValidSigningKeyPacket(primaryKey, primaryUser.selfCertification, date)) {
|
||||
return primaryKey;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user