1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Make OlmDevice olmSession methods asynchronous

* OlmDevice.encryptMessage
* OlmDevice.decryptMessage
* OlmDevice.matchesSession
This commit is contained in:
Richard van der Hoff
2017-08-10 15:01:56 +01:00
parent 8f527a6212
commit e943a6e09c
3 changed files with 9 additions and 9 deletions

View File

@@ -435,9 +435,9 @@ OlmDevice.prototype.getSessionInfoForDevice = async function(deviceIdentityKey)
* @param {string} sessionId the id of the active session
* @param {string} payloadString payload to be encrypted and sent
*
* @return {string} ciphertext
* @return {Promise<string>} ciphertext
*/
OlmDevice.prototype.encryptMessage = function(
OlmDevice.prototype.encryptMessage = async function(
theirDeviceIdentityKey, sessionId, payloadString,
) {
const self = this;
@@ -460,9 +460,9 @@ OlmDevice.prototype.encryptMessage = function(
* @param {number} message_type message_type field from the received message
* @param {string} ciphertext base64-encoded body from the received message
*
* @return {string} decrypted payload.
* @return {Promise<string>} decrypted payload.
*/
OlmDevice.prototype.decryptMessage = function(
OlmDevice.prototype.decryptMessage = async function(
theirDeviceIdentityKey, sessionId, message_type, ciphertext,
) {
const self = this;
@@ -484,10 +484,10 @@ OlmDevice.prototype.decryptMessage = function(
* @param {number} message_type message_type field from the received message
* @param {string} ciphertext base64-encoded body from the received message
*
* @return {boolean} true if the received message is a prekey message which matches
* @return {Promise<boolean>} true if the received message is a prekey message which matches
* the given session.
*/
OlmDevice.prototype.matchesSession = function(
OlmDevice.prototype.matchesSession = async function(
theirDeviceIdentityKey, sessionId, message_type, ciphertext,
) {
if (message_type !== 0) {

View File

@@ -251,7 +251,7 @@ OlmDecryption.prototype._decryptMessage = async function(
for (let i = 0; i < sessionIds.length; i++) {
const sessionId = sessionIds[i];
try {
const payload = this._olmDevice.decryptMessage(
const payload = await this._olmDevice.decryptMessage(
theirDeviceIdentityKey, sessionId, message.type, message.body,
);
console.log(
@@ -260,7 +260,7 @@ OlmDecryption.prototype._decryptMessage = async function(
);
return payload;
} catch (e) {
const foundSession = this._olmDevice.matchesSession(
const foundSession = await this._olmDevice.matchesSession(
theirDeviceIdentityKey, sessionId, message.type, message.body,
);

View File

@@ -102,7 +102,7 @@ module.exports.encryptMessageForDevice = async function(
utils.extend(payload, payloadFields);
resultsObject[deviceKey] = olmDevice.encryptMessage(
resultsObject[deviceKey] = await olmDevice.encryptMessage(
deviceKey, sessionId, JSON.stringify(payload),
);
};