You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
Megolm: don't dereference nullable object
It is possible for `room` to be null when passed to MegolmEncryption.encryptMessage; we need to avoid dereferencing it. Instead, make sure that the EncryptionAlgorithm knows about the roomId it is targeting, and use that. Replace the increasingly-long argument list on the EncryptionAlgorithm constructor with a params list, and update DecryptionAlgorithm to match.
This commit is contained in:
@@ -625,7 +625,12 @@ Crypto.prototype.setRoomEncryption = function(roomId, config, roomMembers) {
|
||||
};
|
||||
this._sessionStore.storeEndToEndRoom(roomId, config);
|
||||
|
||||
var alg = new AlgClass(this._deviceId, this, this._olmDevice);
|
||||
var alg = new AlgClass({
|
||||
deviceId: this._deviceId,
|
||||
crypto: this,
|
||||
olmDevice: this._olmDevice,
|
||||
roomId: roomId,
|
||||
});
|
||||
this._roomAlgorithms[roomId] = alg;
|
||||
return alg.initRoomEncryption(roomMembers);
|
||||
};
|
||||
@@ -719,7 +724,9 @@ Crypto.prototype.isRoomEncrypted = function(roomId) {
|
||||
* Encrypt an event according to the configuration of the room, if necessary.
|
||||
*
|
||||
* @param {module:models/event.MatrixEvent} event event to be sent
|
||||
* @param {module:models/room} room destination room
|
||||
*
|
||||
* @param {module:models/room?} room destination room. Null if the destination
|
||||
* is not a room we have seen over the sync pipe.
|
||||
*/
|
||||
Crypto.prototype.encryptEventIfNeeded = function(event, room) {
|
||||
if (event.isEncrypted()) {
|
||||
@@ -752,7 +759,7 @@ Crypto.prototype.encryptEventIfNeeded = function(event, room) {
|
||||
}
|
||||
|
||||
var encryptedContent = alg.encryptMessage(
|
||||
room, event.getType(), event.getContent()
|
||||
room, event.getType(), event.getContent()
|
||||
);
|
||||
event.makeEncrypted("m.room.encrypted", encryptedContent);
|
||||
};
|
||||
@@ -772,7 +779,9 @@ Crypto.prototype.decryptEvent = function(event) {
|
||||
if (!AlgClass) {
|
||||
throw new algorithms.DecryptionError("Unable to decrypt " + content.algorithm);
|
||||
}
|
||||
var alg = new AlgClass(this._deviceId, this, this._olmDevice);
|
||||
var alg = new AlgClass({
|
||||
olmDevice: this._olmDevice,
|
||||
});
|
||||
return alg.decryptEvent(event);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user