Improve fetchKeys function

This commit is contained in:
Yarmo Mackenbach 2020-06-26 13:08:04 +02:00
parent 51110408b1
commit ae89964feb

View file

@ -133,6 +133,7 @@ async function encryptMessage(opts) {
}; };
async function fetchKeys(opts) { async function fetchKeys(opts) {
// Init
let lookupOpts, wkd, hkd, sig, lastPrimarySig; let lookupOpts, wkd, hkd, sig, lastPrimarySig;
let output = { let output = {
publicKey: null, publicKey: null,
@ -143,6 +144,7 @@ async function fetchKeys(opts) {
sigContent: null sigContent: null
}; };
// Fetch keys depending on the input mode
switch (opts.mode) { switch (opts.mode) {
case "plaintext": case "plaintext":
output.publicKey = (await openpgp.key.readArmored(opts.input)).keys[0]; output.publicKey = (await openpgp.key.readArmored(opts.input)).keys[0];
@ -201,7 +203,8 @@ async function fetchKeys(opts) {
break; break;
} }
output.fingerprint = output.publicKey.primaryKey.getFingerprint(); // Gather more data about the primary key and user
output.fingerprint = await output.publicKey.primaryKey.getFingerprint();
output.user = await output.publicKey.getPrimaryUser(); output.user = await output.publicKey.getPrimaryUser();
lastPrimarySig = output.user.selfCertification; lastPrimarySig = output.user.selfCertification;
output.notations = lastPrimarySig.notations || []; output.notations = lastPrimarySig.notations || [];