1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +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:
Richard van der Hoff
2016-08-17 16:21:37 +01:00
parent 783b1feb70
commit 4d6f9da578
4 changed files with 52 additions and 53 deletions

View File

@@ -44,14 +44,17 @@ module.exports.DECRYPTION_CLASSES = {};
*
* @constructor
*
* @param {string} deviceId The identifier for this device.
* @param {module:crypto} crypto crypto core
* @param {module:OlmDevice} olmDevice olm.js wrapper
* @param {object} params parameters
* @param {string} params.deviceId The identifier for this device.
* @param {module:crypto} params.crypto crypto core
* @param {module:OlmDevice} params.olmDevice olm.js wrapper
* @param {string} params.roomId The ID of the room we will be sending to
*/
module.exports.EncryptionAlgorithm = function(deviceId, crypto, olmDevice) {
this._deviceId = deviceId;
this._crypto = crypto;
this._olmDevice = olmDevice;
module.exports.EncryptionAlgorithm = function(params) {
this._deviceId = params.deviceId;
this._crypto = params.crypto;
this._olmDevice = params.olmDevice;
this._roomId = params.roomId;
};
/**
@@ -70,7 +73,7 @@ module.exports.EncryptionAlgorithm = function(deviceId, crypto, olmDevice) {
* @method module:crypto-algorithms/base.EncryptionAlgorithm#encryptMessage
* @abstract
*
* @param {module:models/room} room
* @param {module:models/room?} room
* @param {string} eventType
* @param {object} plaintext event content
*
@@ -82,14 +85,11 @@ module.exports.EncryptionAlgorithm = function(deviceId, crypto, olmDevice) {
* base type for decryption implementations
*
* @constructor
* @param {string} deviceId The identifier for this device.
* @param {module:crypto} crypto crypto core
* @param {module:OlmDevice} olmDevice olm.js wrapper
* @param {object} params parameters
* @param {module:OlmDevice} params.olmDevice olm.js wrapper
*/
module.exports.DecryptionAlgorithm = function(deviceId, crypto, olmDevice) {
this._deviceId = deviceId;
this._crypto = crypto;
this._olmDevice = olmDevice;
module.exports.DecryptionAlgorithm = function(params) {
this._olmDevice = params.olmDevice;
};
/**