Bug 1631019 - Parameter type mismatch, fix public export. r=PatrickBrunschwig
authorKai Engert <kaie@kuix.de>
Sun, 19 Apr 2020 18:50:08 +0200
changeset 38021 a432e1a57c2805be8bbd3ab16a641a39bca7a17c
parent 38020 1265c97794fd1ceeccc482e571a6cf3d918507cf
child 38022 ac199937ae496e0485684ca5897e0ded58bc1f1a
push id2595
push userclokep@gmail.com
push dateMon, 04 May 2020 19:02:04 +0000
treeherdercomm-beta@f53913797371 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersPatrickBrunschwig
bugs1631019
Bug 1631019 - Parameter type mismatch, fix public export. r=PatrickBrunschwig Differential Revision: https://phabricator.services.mozilla.com/D71476
mail/extensions/openpgp/content/modules/keyRing.jsm
mail/extensions/openpgp/content/ui/enigmailKeyManager.js
--- a/mail/extensions/openpgp/content/modules/keyRing.jsm
+++ b/mail/extensions/openpgp/content/modules/keyRing.jsm
@@ -447,27 +447,25 @@ var EnigmailKeyRing = {
    *                                     key ID, fingerprint, or userId
    * @param outputFile        String or nsIFile - output file name or Object - or NULL
    * @param exitCodeObj       Object   - o.value will contain exit code
    * @param errorMsgObj       Object   - o.value will contain error message from GnuPG
    *
    * @return String - if outputFile is NULL, the key block data; "" if a file is written
    */
   extractKey(includeSecretKey, idArray, outputFile, exitCodeObj, errorMsgObj) {
-    EnigmailLog.DEBUG(
-      "keyRing.jsm: EnigmailKeyRing.extractKey: " + idArray + "\n"
-    );
+    EnigmailLog.DEBUG("keyRing.jsm: EnigmailKeyRing.extractKey: %o\n", idArray);
     exitCodeObj.value = -1;
 
     if (includeSecretKey) {
       throw new Error("extractKey with secret key not implemented");
     }
 
-    if (!idArray.length) {
-      return "";
+    if (!Array.isArray(idArray) || !idArray.length) {
+      throw new Error("invalid parameter given to EnigmailKeyRing.extractKey");
     }
 
     if (idArray.length > 1) {
       throw new Error(
         "keyRing.jsm: EnigmailKeyRing.extractKey: multiple IDs not yet implemented"
       );
     }
 
--- a/mail/extensions/openpgp/content/ui/enigmailKeyManager.js
+++ b/mail/extensions/openpgp/content/ui/enigmailKeyManager.js
@@ -379,19 +379,25 @@ function enigCreateKeyMsg() {
     }
   } catch (ex) {}
   tmpFile.append("key.asc");
   tmpFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
 
   // save file
   var exitCodeObj = {};
   var errorMsgObj = {};
+
+  var keyIdArray = [];
+  for (let id of keyList) {
+    keyIdArray.push("0x" + id);
+  }
+
   EnigmailKeyRing.extractKey(
     false,
-    "0x" + keyList.join(" 0x"),
+    keyIdArray,
     tmpFile,
     exitCodeObj,
     errorMsgObj
   );
   if (exitCodeObj.value !== 0) {
     EnigAlert(errorMsgObj.value);
     return;
   }
@@ -642,22 +648,28 @@ function enigmailExportKeys() {
     "*.asc",
     defaultFileName,
     [EnigGetString("asciiArmorFile"), "*.asc"]
   );
   if (!outFile) {
     return;
   }
 
-  var keyListStr = "0x" + getSelectedKeyIds().join(" 0x");
   var exitCodeObj = {};
   var errorMsgObj = {};
+
+  let keyList2 = getSelectedKeyIds();
+  var keyIdArray = [];
+  for (let id of keyList2) {
+    keyIdArray.push("0x" + id);
+  }
+
   EnigmailKeyRing.extractKey(
     exportSecretKey,
-    keyListStr,
+    keyIdArray,
     outFile,
     exitCodeObj,
     errorMsgObj
   );
   if (exitCodeObj.value !== 0) {
     EnigAlert(EnigGetString("saveKeysFailed") + "\n\n" + errorMsgObj.value);
   } else {
     EnigmailDialog.info(window, EnigGetString("saveKeysOK"));
@@ -770,19 +782,25 @@ function enigmailCopyToClipbrd() {
 
   var keyList = getSelectedKeyIds();
   if (keyList.length === 0) {
     EnigmailDialog.info(window, EnigGetString("noKeySelected"));
     return;
   }
   var exitCodeObj = {};
   var errorMsgObj = {};
+
+  var keyIdArray = [];
+  for (let id of keyList) {
+    keyIdArray.push("0x" + id);
+  }
+
   var keyData = EnigmailKeyRing.extractKey(
     0,
-    ["0x" + keyList.join(" 0x")],
+    keyIdArray,
     null,
     exitCodeObj,
     errorMsgObj
   );
   if (exitCodeObj.value !== 0) {
     EnigAlert(
       EnigGetString("copyToClipbrdFailed") + "\n\n" + errorMsgObj.value
     );