From 301df9684da42c89a5f6a54ce7f67cd1bdf5b5b1 Mon Sep 17 00:00:00 2001 From: Kai Engert Date: Wed, 19 Feb 2020 15:50:29 +0100 Subject: [PATCH] Bug 1616575, openpgp code should throw "new Error()", not string. r=mkmelin Differential Revision: https://phabricator.services.mozilla.com/D63331 --HG-- extra : rebase_source : 638dbb072955d62c695b009a0d6b69ea56f7d762 --- .../openpgp/content/modules/autoSetup.jsm | 2 +- .../openpgp/content/modules/autocrypt.jsm | 2 +- .../openpgp/content/modules/clipboard.jsm | 4 +- .../modules/cryptoAPI/GnuPGCryptoAPI.jsm | 2 +- .../openpgp/content/modules/funcs.jsm | 4 +- .../openpgp/content/modules/keyRing.jsm | 8 +- .../openpgp/content/modules/mimeDecrypt.jsm | 2 +- .../content/modules/persistentCrypto.jsm | 4 +- .../content/modules/pgpmimeHandler.jsm | 6 +- .../openpgp/content/modules/rnp.jsm | 150 +++++++++--------- .../openpgp/content/modules/webKey.jsm | 2 +- .../content/ui/enigmailMessengerOverlay.js | 2 +- 12 files changed, 95 insertions(+), 93 deletions(-) diff --git a/mail/extensions/openpgp/content/modules/autoSetup.jsm b/mail/extensions/openpgp/content/modules/autoSetup.jsm index bbe9b5488e..71f7fb555d 100644 --- a/mail/extensions/openpgp/content/modules/autoSetup.jsm +++ b/mail/extensions/openpgp/content/modules/autoSetup.jsm @@ -242,7 +242,7 @@ var EnigmailAutoSetup = { let passwd = EnigmailWindows.autocryptSetupPasswd(passwordWindow, "input", res.passphraseFormat, res.passphraseHint); if ((!passwd) || passwd == "") { - throw "noPasswd"; + throw new Error("noPasswd"); } // TODO: await EnigmailAutocrypt.handleBackupMessage(passwd, res.attachmentData, headerValue.acSetupMessage.author); diff --git a/mail/extensions/openpgp/content/modules/autocrypt.jsm b/mail/extensions/openpgp/content/modules/autocrypt.jsm index beedc1fad5..07e1f21dfe 100644 --- a/mail/extensions/openpgp/content/modules/autocrypt.jsm +++ b/mail/extensions/openpgp/content/modules/autocrypt.jsm @@ -68,7 +68,7 @@ var EnigmailAutocrypt = { fromAddr = EnigmailFuncs.stripEmail(fromAddr).toLowerCase(); } catch (ex) { - throw "processAutocryptHeader error " + ex; + throw new Error("processAutocryptHeader error " + ex); } let foundTypes = {}; let paramArr = []; diff --git a/mail/extensions/openpgp/content/modules/clipboard.jsm b/mail/extensions/openpgp/content/modules/clipboard.jsm index 2a8a3f94ae..f9acd680c5 100644 --- a/mail/extensions/openpgp/content/modules/clipboard.jsm +++ b/mail/extensions/openpgp/content/modules/clipboard.jsm @@ -53,7 +53,9 @@ var EnigmailClipboard = { */ getClipboardContent: function(window, clipBoardType) { - if (!window) throw "erorr - window must not be null"; + if (!window) { + throw new Error("window is a required parameter"); + } let clipBoard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard); let data = {}; diff --git a/mail/extensions/openpgp/content/modules/cryptoAPI/GnuPGCryptoAPI.jsm b/mail/extensions/openpgp/content/modules/cryptoAPI/GnuPGCryptoAPI.jsm index d957d155e3..83aa826562 100644 --- a/mail/extensions/openpgp/content/modules/cryptoAPI/GnuPGCryptoAPI.jsm +++ b/mail/extensions/openpgp/content/modules/cryptoAPI/GnuPGCryptoAPI.jsm @@ -266,7 +266,7 @@ class GnuPGCryptoAPI extends CryptoAPI { } async genKey(userId, keyType, keySize, expiryTime, passphrase) { - throw "GnuPG genKey() not implemented"; + throw new Error("GnuPG genKey() not implemented"); return null; } diff --git a/mail/extensions/openpgp/content/modules/funcs.jsm b/mail/extensions/openpgp/content/modules/funcs.jsm index 9f060e8211..ff398b6d3f 100644 --- a/mail/extensions/openpgp/content/modules/funcs.jsm +++ b/mail/extensions/openpgp/content/modules/funcs.jsm @@ -334,8 +334,8 @@ var EnigmailFuncs = { */ compareMimePartLevel: function(mime1, mime2) { let s = new RegExp("^[0-9]+(\\.[0-9]+)*$"); - if (mime1.search(s) < 0) throw "Invalid mime1"; - if (mime2.search(s) < 0) throw "Invalid mime2"; + if (mime1.search(s) < 0) throw new Error("Invalid mime1"); + if (mime2.search(s) < 0) throw new Error("Invalid mime2"); let a1 = mime1.split(/\./); let a2 = mime2.split(/\./); diff --git a/mail/extensions/openpgp/content/modules/keyRing.jsm b/mail/extensions/openpgp/content/modules/keyRing.jsm index 4a9454d6a4..4aae33cf66 100644 --- a/mail/extensions/openpgp/content/modules/keyRing.jsm +++ b/mail/extensions/openpgp/content/modules/keyRing.jsm @@ -400,7 +400,7 @@ var EnigmailKeyRing = { console.debug(id); if (includeSecretKey) { - throw "extractKey with secret key not implemented"; + throw new Error("extractKey with secret key not implemented"); } if (!id.length) { @@ -408,7 +408,7 @@ var EnigmailKeyRing = { } if (id.length > 1) { - throw "keyRing.jsm: EnigmailKeyRing.extractKey: multiple IDs not yet implemented"; + throw new Error("keyRing.jsm: EnigmailKeyRing.extractKey: multiple IDs not yet implemented"); } const cApi = EnigmailCryptoAPI(); @@ -495,11 +495,11 @@ var EnigmailKeyRing = { } if (limitedUids.length > 0) { - throw "importKeyAsync with limitedUids: not implemented"; + throw new Error("importKeyAsync with limitedUids: not implemented"); } if (minimizeKey) { - throw "importKeyAsync with minimizeKey: not implemented"; + throw new Error("importKeyAsync with minimizeKey: not implemented"); } const cApi = EnigmailCryptoAPI(); diff --git a/mail/extensions/openpgp/content/modules/mimeDecrypt.jsm b/mail/extensions/openpgp/content/modules/mimeDecrypt.jsm index f22c4f94c5..288e019160 100644 --- a/mail/extensions/openpgp/content/modules/mimeDecrypt.jsm +++ b/mail/extensions/openpgp/content/modules/mimeDecrypt.jsm @@ -445,7 +445,7 @@ MimeDecryptHandler.prototype = { if (!this.isUrlEnigmailConvert()) { this.returnData(EnigmailMimeDecrypt.emptyAttachment()); } else { - throw "mimeDecrypt.jsm: Cannot decrypt messages with mixed (encrypted/non-encrypted) content"; + throw new Error("Cannot decrypt messages with mixed (encrypted/non-encrypted) content"); } return; } diff --git a/mail/extensions/openpgp/content/modules/persistentCrypto.jsm b/mail/extensions/openpgp/content/modules/persistentCrypto.jsm index ff659ee3e8..410c6e4221 100644 --- a/mail/extensions/openpgp/content/modules/persistentCrypto.jsm +++ b/mail/extensions/openpgp/content/modules/persistentCrypto.jsm @@ -332,7 +332,7 @@ CryptMessageIntoFolder.prototype = { decryptPGPMIME: async function(mimePart) { EnigmailLog.DEBUG("persistentCrypto.jsm: decryptPGPMIME(" + mimePart.partNum + ")\n"); - if (!mimePart.subParts[1]) throw "Not a correct PGP/MIME message"; + if (!mimePart.subParts[1]) throw new Error("Not a correct PGP/MIME message"); const uiFlags = EnigmailConstants.UI_INTERACTIVE | EnigmailConstants.UI_UNVERIFIED_ENC_OK | EnigmailConstants.UI_IGNORE_MDC_ERROR; @@ -356,7 +356,7 @@ CryptMessageIntoFolder.prototype = { if (!data || data.length === 0) { if (statusFlagsObj.value & EnigmailConstants.DISPLAY_MESSAGE) { getDialog().alert(null, errorMsgObj.value); - throw "Decryption impossible"; + throw new Error("Decryption impossible"); } } diff --git a/mail/extensions/openpgp/content/modules/pgpmimeHandler.jsm b/mail/extensions/openpgp/content/modules/pgpmimeHandler.jsm index a46b852d64..aea8c8d388 100644 --- a/mail/extensions/openpgp/content/modules/pgpmimeHandler.jsm +++ b/mail/extensions/openpgp/content/modules/pgpmimeHandler.jsm @@ -42,13 +42,13 @@ var gLastEncryptedUri = ""; const throwErrors = { onDataAvailable: function() { - throw "error"; + throw new Error("error"); }, onStartRequest: function() { - throw "error"; + throw new Error("error"); }, onStopRequest: function() { - throw "error"; + throw new Error("error"); } }; diff --git a/mail/extensions/openpgp/content/modules/rnp.jsm b/mail/extensions/openpgp/content/modules/rnp.jsm index 571ee6be05..ce564be0b0 100644 --- a/mail/extensions/openpgp/content/modules/rnp.jsm +++ b/mail/extensions/openpgp/content/modules/rnp.jsm @@ -64,7 +64,7 @@ var RNP = { let allowed = new ctypes.bool; if (RNPLib.rnp_key_have_secret(handle, have_secret.address())) { - throw "rnp_key_have_secret failed"; + throw new Error("rnp_key_have_secret failed"); } keyObj.secretAvailable = have_secret.value; @@ -76,7 +76,7 @@ var RNP = { } if (RNPLib.rnp_key_get_keyid(handle, key_id.address())) { - throw "rnp_key_get_keyid failed"; + throw new Error("rnp_key_get_keyid failed"); } keyObj.keyId = key_id.readString(); if (forListing) { @@ -84,28 +84,28 @@ var RNP = { } if (RNPLib.rnp_key_get_fprint(handle, fingerprint.address())) { - throw "rnp_key_get_fprint failed"; + throw new Error("rnp_key_get_fprint failed"); } keyObj.fpr = fingerprint.readString(); if (RNPLib.rnp_key_get_alg(handle, algo.address())) { - throw "rnp_key_get_alg failed"; + throw new Error("rnp_key_get_alg failed"); } keyObj.algoSym = algo.readString(); if (RNPLib.rnp_key_get_bits(handle, bits.address())) { - throw "rnp_key_get_bits failed"; + throw new Error("rnp_key_get_bits failed"); } keyObj.keySize = bits.value; if (RNPLib.rnp_key_get_creation(handle, key_creation.address())) { - throw "rnp_key_get_creation failed"; + throw new Error("rnp_key_get_creation failed"); } keyObj.keyCreated = key_creation.value; keyObj.created = EnigmailTime.getDateTime(keyObj.keyCreated, true, false); if (RNPLib.rnp_key_get_expiration(handle, key_expiration.address())) { - throw "rnp_key_get_creation failed"; + throw new Error("rnp_key_get_creation failed"); } if (key_expiration.value > 0) { keyObj.expiryTime = keyObj.keyCreated + key_expiration.value; @@ -116,28 +116,28 @@ var RNP = { keyObj.keyUseFor = ""; if (RNPLib.rnp_key_allows_usage(handle, str_encrypt, allowed.address())) { - throw "rnp_key_allows_usage failed"; + throw new Error("rnp_key_allows_usage failed"); } if (allowed.value) { keyObj.keyUseFor += "e"; meta.e = true; } if (RNPLib.rnp_key_allows_usage(handle, str_sign, allowed.address())) { - throw "rnp_key_allows_usage failed"; + throw new Error("rnp_key_allows_usage failed"); } if (allowed.value) { keyObj.keyUseFor += "s"; meta.s = true; } if (RNPLib.rnp_key_allows_usage(handle, str_certify, allowed.address())) { - throw "rnp_key_allows_usage failed"; + throw new Error("rnp_key_allows_usage failed"); } if (allowed.value) { keyObj.keyUseFor += "c"; meta.c = true; } if (RNPLib.rnp_key_allows_usage(handle, str_authenticate, allowed.address())) { - throw "rnp_key_allows_usage failed"; + throw new Error("rnp_key_allows_usage failed"); } if (allowed.value) { keyObj.keyUseFor += "a"; @@ -192,16 +192,16 @@ var RNP = { let uid_count = new ctypes.size_t; if (RNPLib.rnp_locate_key(ffi, "grip", grip, handle.address())) { - throw "rnp_locate_key failed"; + throw new Error("rnp_locate_key failed"); } have_handle = true; if (RNPLib.rnp_key_is_sub(handle, is_subkey.address())) { - throw "rnp_key_is_sub failed"; + throw new Error("rnp_key_is_sub failed"); } if (is_subkey.value) { let primary_grip = new ctypes.char.ptr(); if (RNPLib.rnp_key_get_primary_grip(handle, primary_grip.address())) { - throw "rnp_key_get_primary_grip failed"; + throw new Error("rnp_key_get_primary_grip failed"); } /* Skip if we have primary key. Subkey will be processed together with primary */ if (!primary_grip.isNull()) { @@ -214,7 +214,7 @@ var RNP = { let key_revoked = new ctypes.bool; if (RNPLib.rnp_key_is_revoked(handle, key_revoked.address())) { - throw "rnp_key_is_revoked failed"; + throw new Error("rnp_key_is_revoked failed"); } if (key_revoked.value) { @@ -236,7 +236,7 @@ var RNP = { let primary_uid_set = false; if (RNPLib.rnp_key_get_uid_count(handle, uid_count.address())) { - throw "rnp_key_get_uid_count failed"; + throw new Error("rnp_key_get_uid_count failed"); } console.debug("rnp_key_get_uid_count: " + uid_count.value); for (let i = 0; i < uid_count.value; i++) { @@ -244,17 +244,17 @@ var RNP = { let is_revoked = new ctypes.bool; if (RNPLib.rnp_key_get_uid_handle_at(handle, i, uid_handle.address())) { - throw "rnp_key_get_uid_handle_at failed"; + throw new Error("rnp_key_get_uid_handle_at failed"); } if (RNPLib.rnp_uid_is_revoked(uid_handle, is_revoked.address())) { - throw "rnp_uid_is_revoked failed"; + throw new Error("rnp_uid_is_revoked failed"); } if (!is_revoked.value) { let uid_str = new ctypes.char.ptr; if (RNPLib.rnp_key_get_uid_at(handle, i, uid_str.address())) { - throw "rnp_key_get_uid_at failed"; + throw new Error("rnp_key_get_uid_at failed"); } if (!primary_uid_set) { @@ -280,13 +280,13 @@ var RNP = { } if (RNPLib.rnp_key_get_subkey_count(handle, sub_count.address())) { - throw "rnp_key_get_subkey_count failed"; + throw new Error("rnp_key_get_subkey_count failed"); } console.debug("rnp_key_get_subkey_count: " + sub_count.value); for (let i = 0; i < sub_count.value; i++) { let sub_handle = new RNPLib.rnp_key_handle_t; if (RNPLib.rnp_key_get_subkey_at(handle, i, sub_handle.address())) { - throw "rnp_key_get_subkey_at failed"; + throw new Error("rnp_key_get_subkey_at failed"); } let subKeyObj = {}; @@ -434,95 +434,95 @@ var RNP = { let genOp = new RNPLib.rnp_op_generate_t; if (RNPLib.rnp_op_generate_create(genOp.address(), RNPLib.ffi, primaryKeyType)) { - throw "rnp_op_generate_create primary failed"; + throw new Error("rnp_op_generate_create primary failed"); } if (RNPLib.rnp_op_generate_set_userid(genOp, userId)) { - throw "rnp_op_generate_set_userid failed"; + throw new Error("rnp_op_generate_set_userid failed"); } if (passphrase != null && passphrase.length != 0) { if (RNPLib.rnp_op_generate_set_protection_password(genOp, passphrase)) { - throw "rnp_op_generate_set_protection_password failed"; + throw new Error("rnp_op_generate_set_protection_password failed"); } } if (primaryKeyBits != 0) { if (RNPLib.rnp_op_generate_set_bits(genOp, primaryKeyBits)) { - throw "rnp_op_generate_set_bits primary failed"; + throw new Error("rnp_op_generate_set_bits primary failed"); } } if (primaryKeyCurve != null) { if (RNPLib.rnp_op_generate_set_curve(genOp, primaryKeyCurve)) { - throw "rnp_op_generate_set_curve primary failed"; + throw new Error("rnp_op_generate_set_curve primary failed"); } } if (expireSeconds != 0) { if (RNPLib.rnp_op_generate_set_expiration(genOp, expireSeconds)) { - throw "rnp_op_generate_set_expiration primary failed"; + throw new Error("rnp_op_generate_set_expiration primary failed"); } } if (RNPLib.rnp_op_generate_execute(genOp)) { - throw "rnp_op_generate_execute primary failed"; + throw new Error("rnp_op_generate_execute primary failed"); } let primaryKey = new RNPLib.rnp_key_handle_t; if (RNPLib.rnp_op_generate_get_key(genOp, primaryKey.address())) { - throw "rnp_op_generate_get_key primary failed"; + throw new Error("rnp_op_generate_get_key primary failed"); } RNPLib.rnp_op_generate_destroy(genOp); let ctypes_key_id = new ctypes.char.ptr; if (RNPLib.rnp_key_get_keyid(primaryKey, ctypes_key_id.address())) { - throw "rnp_key_get_keyid failed"; + throw new Error("rnp_key_get_keyid failed"); } newKeyId = ctypes_key_id.readString(); if (RNPLib.rnp_op_generate_subkey_create(genOp.address(), RNPLib.ffi, primaryKey, subKeyType)) { - throw "rnp_op_generate_subkey_create primary failed"; + throw new Error("rnp_op_generate_subkey_create primary failed"); } if (passphrase != null && passphrase.length != 0) { if (RNPLib.rnp_op_generate_set_protection_password(genOp, passphrase)) { - throw "rnp_op_generate_set_protection_password failed"; + throw new Error("rnp_op_generate_set_protection_password failed"); } } if (subKeyBits != 0) { if (RNPLib.rnp_op_generate_set_bits(genOp, subKeyBits)) { - throw "rnp_op_generate_set_bits sub failed"; + throw new Error("rnp_op_generate_set_bits sub failed"); } } if (subKeyCurve != null) { if (RNPLib.rnp_op_generate_set_curve(genOp, subKeyCurve)) { - throw "rnp_op_generate_set_curve sub failed"; + throw new Error("rnp_op_generate_set_curve sub failed"); } } if (expireSeconds != 0) { if (RNPLib.rnp_op_generate_set_expiration(genOp, expireSeconds)) { - throw "rnp_op_generate_set_expiration sub failed"; + throw new Error("rnp_op_generate_set_expiration sub failed"); } } try { if (passphrase != null && passphrase.length != 0) { if (RNPLib.rnp_key_unlock(primaryKey, passphrase)) { - throw "rnp_key_unlock failed"; + throw new Error("rnp_key_unlock failed"); } } if (RNPLib.rnp_op_generate_execute(genOp)) { - throw "rnp_op_generate_execute sub failed"; + throw new Error("rnp_op_generate_execute sub failed"); } } finally { if (RNPLib.rnp_key_lock(primaryKey)) { - throw "rnp_key_lock failed"; + throw new Error("rnp_key_lock failed"); } } @@ -599,7 +599,7 @@ var RNP = { let handle = new RNPLib.rnp_key_handle_t; if (RNPLib.rnp_locate_key(RNPLib.ffi, "fingerprint", keyFingerprint, handle.address())) { - throw "rnp_locate_key failed"; + throw new Error("rnp_locate_key failed"); } let flags = RNPLib.RNP_KEY_REMOVE_PUBLIC; @@ -620,14 +620,14 @@ var RNP = { let key = null; if (id.startsWith("<")) { - //throw "search by email address not yet implemented: " + id; + //throw new Error("search by email address not yet implemented: " + id); if (!id.endsWith(">")) { - throw "if search identifier starts with < then it must end with > : " + id; + throw new Error("if search identifier starts with < then it must end with > : " + id); } key = this.findKeyByEmail(id); } else { if (!id.startsWith("0x")) { - throw "unexpected identifier " + id; + throw new Error("unexpected identifier " + id); } else { // remove 0x id = id.substring(2); @@ -639,12 +639,12 @@ var RNP = { } else if (id.length == 40 || id.length == 32) { type = "fingerprint"; } else { - throw "key/fingerprint identifier of unexpected length: " + id; + throw new Error("key/fingerprint identifier of unexpected length: " + id); } key = new RNPLib.rnp_key_handle_t; if (RNPLib.rnp_locate_key(RNPLib.ffi, type, id, key.address())) { - throw "rnp_locate_key failed, " + type + ", " + id; + throw new Error("rnp_locate_key failed, " + type + ", " + id); } } @@ -655,7 +655,7 @@ var RNP = { let is_subkey = new ctypes.bool; let res = RNPLib.rnp_key_is_sub(key, is_subkey.address()); if (res) { - throw "rnp_key_is_sub failed: " + res; + throw new Error("rnp_key_is_sub failed: " + res); } console.debug("is_primary? " + !is_subkey.value); } @@ -666,7 +666,7 @@ var RNP = { isKeyUsableFor(key, usage) { let allowed = new ctypes.bool; if (RNPLib.rnp_key_allows_usage(key, usage, allowed.address())) { - throw "rnp_key_allows_usage failed"; + throw new Error("rnp_key_allows_usage failed"); } return allowed.value; }, @@ -675,23 +675,23 @@ var RNP = { let found_handle = null; let sub_count = new ctypes.size_t; if (RNPLib.rnp_key_get_subkey_count(primary, sub_count.address())) { - throw "rnp_key_get_subkey_count failed"; + throw new Error("rnp_key_get_subkey_count failed"); } for (let i = 0; i < sub_count.value; i++) { let sub_handle = new RNPLib.rnp_key_handle_t; if (RNPLib.rnp_key_get_subkey_at(primary, i, sub_handle.address())) { - throw "rnp_key_get_subkey_at failed"; + throw new Error("rnp_key_get_subkey_at failed"); } let expiration = new ctypes.uint32_t; if (RNPLib.rnp_key_get_expiration(sub_handle, expiration.address())) { - throw "rnp_key_get_expiration failed"; + throw new Error("rnp_key_get_expiration failed"); } let skip = false; if (expiration.value != 0) { let now_seconds = Math.floor(Date.now()/1000); let creation = new ctypes.uint32_t; if (RNPLib.rnp_key_get_creation(sub_handle, creation.address())) { - throw "rnp_key_get_expiration failed"; + throw new Error("rnp_key_get_expiration failed"); } let expiration_seconds = creation.value + expiration.value; console.debug("now: " + now_seconds + " vs. subkey creation+expiration in seconds: " + expiration_seconds); @@ -720,7 +720,7 @@ var RNP = { let fingerprint = new ctypes.char.ptr; if (RNPLib.rnp_key_get_fprint(found_handle, fingerprint.address())) { - throw "rnp_key_get_fprint failed"; + throw new Error("rnp_key_get_fprint failed"); } console.debug("found suitable subkey, fingerprint: " + fingerprint.readString()); break; @@ -740,14 +740,14 @@ var RNP = { console.debug("addSuitableEncryptKey primary not usable"); use_sub = this.getSuitableSubkey(key, str_encrypt); if (!use_sub) { - throw "no suitable subkey found for " + str_encrypt; + throw new Error("no suitable subkey found for " + str_encrypt); } else { console.debug("addSuitableEncryptKey using subkey"); } } if (RNPLib.rnp_op_encrypt_add_recipient(op, (use_sub != null) ? use_sub : key)) { - throw "rnp_op_encrypt_add_recipient sender failed"; + throw new Error("rnp_op_encrypt_add_recipient sender failed"); } if (use_sub) { RNPLib.rnp_key_handle_destroy(use_sub); @@ -771,7 +771,7 @@ var RNP = { let input = new RNPLib.rnp_input_t; if (RNPLib.rnp_input_from_memory(input.address(), plaintext_array, plaintext.length, false)) { - throw "rnp_input_from_memory failed"; + throw new Error("rnp_input_from_memory failed"); } let output = new RNPLib.rnp_output_t; @@ -782,25 +782,25 @@ var RNP = { op = new RNPLib.rnp_op_encrypt_t; if (RNPLib.rnp_op_encrypt_create(op.address(), RNPLib.ffi, input, output)) { - throw "rnp_op_encrypt_create failed"; + throw new Error("rnp_op_encrypt_create failed"); } } else if (args.sign) { op = new RNPLib.rnp_op_sign_t; if (args.sigTypeClear) { if (RNPLib.rnp_op_sign_cleartext_create(op.address(), RNPLib.ffi, input, output)) { - throw "rnp_op_sign_cleartext_create failed"; + throw new Error("rnp_op_sign_cleartext_create failed"); } } else if (args.sigTypeDetached) { if (RNPLib.rnp_op_sign_detached_create(op.address(), RNPLib.ffi, input, output)) { - throw "rnp_op_sign_detached_create failed"; + throw new Error("rnp_op_sign_detached_create failed"); } } else { - throw "not yet implemented scenario: signing, neither clear nor encrypt, without encryption"; + throw new Error("not yet implemented scenario: signing, neither clear nor encrypt, without encryption"); } } else { - throw "invalid parameters, neither encrypt nor sign"; + throw new Error("invalid parameters, neither encrypt nor sign"); } let senderKey = null; @@ -817,20 +817,20 @@ var RNP = { if (!this.isKeyUsableFor(senderKey, str_sign)) { use_sub = this.getSuitableSubkey(senderKey, str_sign); if (!use_sub) { - throw "no suitable subkey found for " + str_sign; + throw new Error("no suitable subkey found for " + str_sign); } } if (args.encrypt) { if (RNPLib.rnp_op_encrypt_add_signature(op, (use_sub != null) ? use_sub : senderKey, null)) { - throw "rnp_op_encrypt_add_signature failed"; + throw new Error("rnp_op_encrypt_add_signature failed"); } } else { if (RNPLib.rnp_op_sign_add_signature(op, use_sub ? use_sub : senderKey, null)) { - throw "rnp_op_sign_add_signature failed"; + throw new Error("rnp_op_sign_add_signature failed"); } } if (use_sub) { @@ -864,22 +864,22 @@ var RNP = { // TODO decide if our compatibility requirements allow us to // use AEAD if (RNPLib.rnp_op_encrypt_set_cipher(op, "AES256")) { - throw "rnp_op_encrypt_set_cipher failed"; + throw new Error("rnp_op_encrypt_set_cipher failed"); } // TODO, map args.signatureHash string to RNP and call // rnp_op_encrypt_set_hash if (RNPLib.rnp_op_encrypt_set_hash(op, "SHA256")) { - throw "rnp_op_encrypt_set_hash failed"; + throw new Error("rnp_op_encrypt_set_hash failed"); } if (RNPLib.rnp_op_encrypt_set_armor(op, args.armor)) { - throw "rnp_op_encrypt_set_armor failed"; + throw new Error("rnp_op_encrypt_set_armor failed"); } let rv = RNPLib.rnp_op_encrypt_execute(op); if (rv) { - throw "rnp_op_encrypt_execute failed: " + rv; + throw new Error("rnp_op_encrypt_execute failed: " + rv); } RNPLib.rnp_op_encrypt_destroy(op); @@ -932,7 +932,7 @@ var RNP = { findKeyByEmail(id) { if (!id.startsWith("<") || !id.endsWith(">")) { - throw "invalid parameter given to findKeyByEmail"; + throw new Error("invalid parameter given to findKeyByEmail"); } let keys = []; @@ -960,11 +960,11 @@ var RNP = { let uid_count = new ctypes.size_t; if (RNPLib.rnp_locate_key(RNPLib.ffi, "grip", grip, handle.address())) { - throw "rnp_locate_key failed"; + throw new Error("rnp_locate_key failed"); } have_handle = true; if (RNPLib.rnp_key_is_sub(handle, is_subkey.address())) { - throw "rnp_key_is_sub failed"; + throw new Error("rnp_key_is_sub failed"); } if (is_subkey.value) { continue; @@ -972,7 +972,7 @@ var RNP = { let key_revoked = new ctypes.bool; if (RNPLib.rnp_key_is_revoked(handle, key_revoked.address())) { - throw "rnp_key_is_revoked failed"; + throw new Error("rnp_key_is_revoked failed"); } if (key_revoked.value) { @@ -980,7 +980,7 @@ var RNP = { } if (RNPLib.rnp_key_get_uid_count(handle, uid_count.address())) { - throw "rnp_key_get_uid_count failed"; + throw new Error("rnp_key_get_uid_count failed"); } console.debug("rnp_key_get_uid_count: " + uid_count.value); for (let i = 0; i < uid_count.value; i++) { @@ -988,17 +988,17 @@ var RNP = { let is_revoked = new ctypes.bool; if (RNPLib.rnp_key_get_uid_handle_at(handle, i, uid_handle.address())) { - throw "rnp_key_get_uid_handle_at failed"; + throw new Error("rnp_key_get_uid_handle_at failed"); } if (RNPLib.rnp_uid_is_revoked(uid_handle, is_revoked.address())) { - throw "rnp_uid_is_revoked failed"; + throw new Error("rnp_uid_is_revoked failed"); } if (!is_revoked.value) { let uid_str = new ctypes.char.ptr; if (RNPLib.rnp_key_get_uid_at(handle, i, uid_str.address())) { - throw "rnp_key_get_uid_at failed"; + throw new Error("rnp_key_get_uid_at failed"); } let userId = uid_str.readString(); @@ -1043,7 +1043,7 @@ var RNP = { RNPLib.rnp_output_to_memory(output_to_memory.address(), 0); if (RNPLib.rnp_key_export(key, output_to_memory, flags)) { - throw "rnp_key_export failed"; + throw new Error("rnp_key_export failed"); } let result_buf = new ctypes.uint8_t.ptr(); diff --git a/mail/extensions/openpgp/content/modules/webKey.jsm b/mail/extensions/openpgp/content/modules/webKey.jsm index af4846f3cf..88a12eabba 100644 --- a/mail/extensions/openpgp/content/modules/webKey.jsm +++ b/mail/extensions/openpgp/content/modules/webKey.jsm @@ -84,7 +84,7 @@ var EnigmailWks = { this.isCanceled = true; }; - if (!ids) throw "error"; + if (!ids) throw new Error("error"); if (ids.senderIdentities.length === 0) { return new Promise(resolve => { diff --git a/mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js b/mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js index e01b2d49e4..d4a9ad94b5 100644 --- a/mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js +++ b/mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js @@ -2510,7 +2510,7 @@ Enigmail.msg = { passwd = EnigmailWindows.autocryptSetupPasswd(window, "input", res.passphraseFormat, passwd || res.passphraseHint); if ((!passwd) || passwd == "") { - throw "noPasswd"; + throw new Error("noPasswd"); } // TODO: return EnigmailAutocrypt.handleBackupMessage(passwd, res.attachmentData, currentHeaderData.from.headerValue);