remove some redundant code

This commit is contained in:
Sanjana Rajan 2018-03-12 23:47:17 +01:00
parent 38508b33d1
commit 3945912b29

View File

@ -278,7 +278,7 @@ Key.prototype.getSigningKeyPacket = async function (keyId=null, date=new Date())
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
await this.subKeys[i].verify(primaryKey, date);
if (await this.subKeys[i].verify(primaryKey, date) === enums.keyStatus.valid) {
for (let j = 0; j < this.subKeys[i].bindingSignatures.length; j++) {
if (isValidSigningKeyPacket(this.subKeys[i].subKey, this.subKeys[i].bindingSignatures[j], date)) {
return this.subKeys[i].subKey;
@ -287,6 +287,7 @@ Key.prototype.getSigningKeyPacket = async function (keyId=null, date=new Date())
}
}
}
}
return null;
};
@ -321,7 +322,7 @@ Key.prototype.getEncryptionKeyPacket = async function(keyId, date=new Date()) {
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
await this.subKeys[i].verify(primaryKey, date);
if (await this.subKeys[i].verify(primaryKey, date) === enums.keyStatus.valid) {
for (let j = 0; j < this.subKeys[i].bindingSignatures.length; j++) {
if (isValidEncryptionKeyPacket(this.subKeys[i].subKey, this.subKeys[i].bindingSignatures[j], date)) {
return this.subKeys[i].subKey;
@ -329,6 +330,7 @@ Key.prototype.getEncryptionKeyPacket = async function(keyId, date=new Date()) {
}
}
}
}
// if no valid subkey for encryption, evaluate primary key
const primaryUser = await this.getPrimaryUser(date);
if (primaryUser && (!keyId || primaryKey.getKeyId().equals(keyId)) &&