From bd64aaf029e7b2abfb61acaec03699db6e0352c9 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 2 Sep 2020 17:37:13 +0200 Subject: [PATCH] create outbound olm session from account also better error handling --- src/matrix/e2ee/Account.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/matrix/e2ee/Account.js b/src/matrix/e2ee/Account.js index 0478112b..e5c03cbd 100644 --- a/src/matrix/e2ee/Account.js +++ b/src/matrix/e2ee/Account.js @@ -126,8 +126,24 @@ export class Account { createInboundOlmSession(senderKey, body) { const newSession = new this._olm.Session(); - newSession.create_inbound_from(this._account, senderKey, body); - return newSession; + try { + newSession.create_inbound_from(this._account, senderKey, body); + return newSession; + } catch (err) { + newSession.free(); + throw err; + } + } + + createOutboundOlmSession(theirIdentityKey, theirOneTimeKey) { + const newSession = new this._olm.Session(); + try { + newSession.create_outbound_from(this._account, theirIdentityKey, theirOneTimeKey); + return newSession; + } catch (err) { + newSession.free(); + throw err; + } } writeRemoveOneTimeKey(session, txn) {