You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Make crypto.decryptMessage return decryption results
... instead of having it call event.setClearData. The main advantage of this is that it fixes a race condition, wherein apps could see `event.isDecrypting()` to be true, but in fact the event had been decrypted (and there was no `Event.decrypted` event on its way). We're also fixing another race, wherein if the first attempt to decrypt failed, a call to `attemptDecryption` would race against the first call and a second attempt to decrypt would never happen. This also gives a cleaner interface to MatrixEvent, at the expense of making the `megolm` unit test a bit more hoop-jumpy.
This commit is contained in:
@@ -117,7 +117,8 @@ class DecryptionAlgorithm {
|
||||
*
|
||||
* @param {MatrixEvent} event undecrypted event
|
||||
*
|
||||
* @return {Promise} resolves once we have finished decrypting. Rejects with an
|
||||
* @return {Promise<module:crypto~EventDecryptionResult>} promise which
|
||||
* resolves once we have finished decrypting. Rejects with an
|
||||
* `algorithms.DecryptionError` if there is a problem decrypting the event.
|
||||
*/
|
||||
|
||||
|
||||
@@ -535,9 +535,10 @@ utils.inherits(MegolmDecryption, base.DecryptionAlgorithm);
|
||||
*
|
||||
* @param {MatrixEvent} event
|
||||
*
|
||||
* returns a promise which resolves once we have finished decrypting, or
|
||||
* rejects with an `algorithms.DecryptionError` if there is a problem
|
||||
* decrypting the event.
|
||||
* returns a promise which resolves to a
|
||||
* {@link module:crypto~EventDecryptionResult} once we have finished
|
||||
* decrypting, or rejects with an `algorithms.DecryptionError` if there is a
|
||||
* problem decrypting the event.
|
||||
*/
|
||||
MegolmDecryption.prototype.decryptEvent = async function(event) {
|
||||
const content = event.getWireContent();
|
||||
@@ -588,8 +589,12 @@ MegolmDecryption.prototype.decryptEvent = async function(event) {
|
||||
);
|
||||
}
|
||||
|
||||
event.setClearData(payload, res.senderKey, res.keysClaimed.ed25519,
|
||||
res.forwardingCurve25519KeyChain);
|
||||
return {
|
||||
clearEvent: payload,
|
||||
senderCurve25519Key: res.senderKey,
|
||||
claimedEd25519Key: res.keysClaimed.ed25519,
|
||||
forwardingCurve25519KeyChain: res.forwardingCurve25519KeyChain,
|
||||
};
|
||||
};
|
||||
|
||||
MegolmDecryption.prototype._requestKeysForEvent = function(event) {
|
||||
|
||||
@@ -157,8 +157,10 @@ utils.inherits(OlmDecryption, base.DecryptionAlgorithm);
|
||||
*
|
||||
* @param {MatrixEvent} event
|
||||
*
|
||||
* returns a promise which resolves once we have finished decrypting. Rejects with an
|
||||
* `algorithms.DecryptionError` if there is a problem decrypting the event.
|
||||
* returns a promise which resolves to a
|
||||
* {@link module:crypto~EventDecryptionResult} once we have finished
|
||||
* decrypting. Rejects with an `algorithms.DecryptionError` if there is a
|
||||
* problem decrypting the event.
|
||||
*/
|
||||
OlmDecryption.prototype.decryptEvent = async function(event) {
|
||||
const content = event.getWireContent();
|
||||
@@ -227,9 +229,13 @@ OlmDecryption.prototype.decryptEvent = async function(event) {
|
||||
}
|
||||
|
||||
const claimedKeys = payload.keys || {};
|
||||
event.setClearData(payload, deviceKey, claimedKeys.ed25519 || null);
|
||||
};
|
||||
|
||||
return {
|
||||
clearEvent: payload,
|
||||
senderCurve25519Key: deviceKey,
|
||||
claimedEd25519Key: claimedKeys.ed25519 || null,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempt to decrypt an Olm message
|
||||
|
||||
Reference in New Issue
Block a user