Page MenuHomePhabricator

D13025.id43253.diff
No OneTemporary

D13025.id43253.diff

diff --git a/lib/utils/olm-utils.js b/lib/utils/olm-utils.js
--- a/lib/utils/olm-utils.js
+++ b/lib/utils/olm-utils.js
@@ -127,6 +127,12 @@
// Otherwise, it could mean that the receiver chain advance beyond and the key
// to decrypt that message was discarded.
messageAlreadyDecrypted: 'OLM_ALREADY_DECRYPTED_OR_KEYS_SKIPPED',
+ // Error thrown when attempting to encrypt/decrypt, indicating that
+ // the session for a given deviceID is not created.
+ // This definition should remain in sync with the value defined in
+ // the corresponding .cpp file
+ // at `native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp`.
+ sessionNotExists: 'SESSION_NOT_EXISTS',
});
function hasHigherDeviceID(
diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
--- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
+++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
@@ -12,6 +12,10 @@
namespace comm {
namespace crypto {
+// This definition should remain in sync with the value defined in
+// the corresponding JavaScript file at `lib/utils/olm-utils.js`.
+const std::string SESSION_NOT_EXISTS_ERROR{"SESSION_NOT_EXISTS"};
+
CryptoModule::CryptoModule(std::string id) : id{id} {
this->createAccount();
}
@@ -381,7 +385,7 @@
const std::string &targetDeviceId,
const std::string &content) {
if (!this->hasSessionFor(targetDeviceId)) {
- throw std::runtime_error{"error encrypt => uninitialized session"};
+ throw std::runtime_error{SESSION_NOT_EXISTS_ERROR};
}
return this->sessions.at(targetDeviceId)->encrypt(content);
}
@@ -390,7 +394,7 @@
const std::string &targetDeviceId,
EncryptedData &encryptedData) {
if (!this->hasSessionFor(targetDeviceId)) {
- throw std::runtime_error{"error decrypt => uninitialized session"};
+ throw std::runtime_error{SESSION_NOT_EXISTS_ERROR};
}
return this->sessions.at(targetDeviceId)->decrypt(encryptedData);
}
diff --git a/web/shared-worker/worker/worker-crypto.js b/web/shared-worker/worker/worker-crypto.js
--- a/web/shared-worker/worker/worker-crypto.js
+++ b/web/shared-worker/worker/worker-crypto.js
@@ -555,7 +555,8 @@
}
const olmSession = cryptoStore.contentSessions[deviceID];
if (!olmSession) {
- throw new Error(`No session for deviceID: ${deviceID}`);
+ console.log(`No session for deviceID: ${deviceID}`);
+ throw new Error(olmSessionErrors.sessionNotExists);
}
const encryptedContent = olmSession.session.encrypt(content);
@@ -576,7 +577,8 @@
}
const olmSession = cryptoStore.contentSessions[deviceID];
if (!olmSession) {
- throw new Error(`No session for deviceID: ${deviceID}`);
+ console.log(`No session for deviceID: ${deviceID}`);
+ throw new Error(olmSessionErrors.sessionNotExists);
}
const encryptedContent = olmSession.session.encrypt(content);
@@ -630,7 +632,8 @@
const olmSession = cryptoStore.contentSessions[deviceID];
if (!olmSession) {
- throw new Error(`No session for deviceID: ${deviceID}`);
+ console.log(`No session for deviceID: ${deviceID}`);
+ throw new Error(olmSessionErrors.sessionNotExists);
}
const result = olmSession.session.decrypt(
@@ -653,7 +656,8 @@
const olmSession = cryptoStore.contentSessions[deviceID];
if (!olmSession) {
- throw new Error(`No session for deviceID: ${deviceID}`);
+ console.log(`No session for deviceID: ${deviceID}`);
+ throw new Error(olmSessionErrors.sessionNotExists);
}
const result = olmSession.session.decrypt(

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 19, 11:16 AM (21 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2319701
Default Alt Text
D13025.id43253.diff (3 KB)

Event Timeline