1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Add decryption error codes to base.DecryptionError

These should roughly follow 9732cf5932/MatrixSDK/Crypto/Algorithms/MXDecryptionResult.h (L21-L39)
This commit is contained in:
Luke Barnard
2018-07-04 11:50:34 +01:00
parent 0415f821eb
commit c74d2d831b
5 changed files with 25 additions and 4 deletions

View File

@@ -618,7 +618,10 @@ MegolmDecryption.prototype.decryptEvent = async function(event) {
if (!content.sender_key || !content.session_id ||
!content.ciphertext
) {
throw new base.DecryptionError("Missing fields in input");
throw new base.DecryptionError(
"MEGOLM_MISSING_FIELDS",
"Missing fields in input",
);
}
// we add the event to the pending list *before* we start decryption.
@@ -639,6 +642,7 @@ MegolmDecryption.prototype.decryptEvent = async function(event) {
this._requestKeysForEvent(event);
}
throw new base.DecryptionError(
"OLM_UNKNOWN_MESSAGE_INDEX",
e.toString(), {
session: content.sender_key + '|' + content.session_id,
},
@@ -655,6 +659,7 @@ MegolmDecryption.prototype.decryptEvent = async function(event) {
// scheduled, so we needn't send out the request here.)
this._requestKeysForEvent(event);
throw new base.DecryptionError(
"MEGOLM_UNKNOWN_INBOUND_SESSION_ID",
"The sender's device has not sent us the keys for this message.",
{
session: content.sender_key + '|' + content.session_id,
@@ -673,6 +678,7 @@ MegolmDecryption.prototype.decryptEvent = async function(event) {
// room, so neither the sender nor a MITM can lie about the room_id).
if (payload.room_id !== event.getRoomId()) {
throw new base.DecryptionError(
"MEGOLM_BAD_ROOM",
"Message intended for room " + payload.room_id,
);
}