From 0ac79b2275db2c5584db6e0608aa45277d76e4de Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Sun, 9 Feb 2020 20:15:03 -0800 Subject: [PATCH] convert logging to throws --- libloki/crypto.js | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/libloki/crypto.js b/libloki/crypto.js index 6bcf9ce01..436f8d9ea 100644 --- a/libloki/crypto.js +++ b/libloki/crypto.js @@ -49,10 +49,7 @@ async encrypt(plaintext) { const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); if (!myKeyPair) { - window.log.warn("encrypt, Can't load myKeyPair from storage"); - // FIXME: not sure what I should give on failure - // just going to stick with the same type of value - return {}; + throw new Error("Failed to get keypair for encryption"); } const myPrivateKey = myKeyPair.privKey; const symmetricKey = libsignal.Curve.calculateAgreement( @@ -70,10 +67,7 @@ async decrypt(ivAndCiphertext) { const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); if (!myKeyPair) { - window.log.warn("decrypt, Can't load myKeyPair from storage"); - // FIXME: not sure what I should give on failure - // just going to stick with the same type of value - return {}; + throw new Error("Failed to get keypair for decryption"); } const myPrivateKey = myKeyPair.privKey; const symmetricKey = libsignal.Curve.calculateAgreement( @@ -182,10 +176,7 @@ const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); if (!myKeyPair) { - window.log.warn("generateSignatureForPairing Can't load myKeyPair from storage"); - // FIXME: not sure what I should give on failure - // just going to stick with the same type of value - return {}; + throw new Error("Failed to get keypair for pairing signature generation"); } const signature = await libsignal.Curve.async.calculateSignature( myKeyPair.privKey, @@ -311,10 +302,7 @@ ); const { privKey } = await textsecure.storage.protocol.getIdentityKeyPair(); if (!privKey) { - window.log.warn("decryptToken, Can't load myKeyPair from storage"); - // FIXME: not sure what I should give on failure - // just going to stick with the same type of value - return {}; + throw new Error("Failed to get keypair for token decryption"); } const symmetricKey = libsignal.Curve.calculateAgreement( serverPubKey,