From f310632a83b892eb77ec770effe4666fe527ce03 Mon Sep 17 00:00:00 2001 From: Malin Errenst Date: Thu, 22 Jun 2023 17:18:10 +0200 Subject: [PATCH] fix: Assign correct type to signedOneTimeKeys --- lib/encryption/olm_manager.dart | 9 ++++++--- test/fake_matrix_api.dart | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/encryption/olm_manager.dart b/lib/encryption/olm_manager.dart index 054aa850..ce60c29b 100644 --- a/lib/encryption/olm_manager.dart +++ b/lib/encryption/olm_manager.dart @@ -144,7 +144,7 @@ class OlmManager { } _uploadKeysLock = true; - final signedOneTimeKeys = {}; + final signedOneTimeKeys = >{}; try { int? uploadedOneTimeKeysCount; if (oldKeyCount != null) { @@ -287,8 +287,11 @@ class OlmManager { try { final String identity = json.decode(olmAccount.identity_keys())['curve25519']; - session.create_outbound(_olmAccount!, identity, otk['key']); - olmAccount.remove_one_time_keys(session); + final key = otk.tryGet('key'); + if (key != null) { + session.create_outbound(_olmAccount!, identity, key); + olmAccount.remove_one_time_keys(session); + } } finally { session.free(); } diff --git a/test/fake_matrix_api.dart b/test/fake_matrix_api.dart index 852bb2b9..0cb417a2 100644 --- a/test/fake_matrix_api.dart +++ b/test/fake_matrix_api.dart @@ -26,6 +26,8 @@ import 'package:http/http.dart'; import 'package:matrix/matrix.dart' as sdk; import 'package:matrix/matrix.dart'; +T? tryCast(dynamic object) => object is T ? object : null; + Map decodeJson(dynamic data) { if (data is String) { return json.decode(data); @@ -2167,7 +2169,11 @@ class FakeMatrixApi extends BaseClient { 'one_time_key_counts': { 'curve25519': 10, 'signed_curve25519': - decodeJson(req)['one_time_keys']?.keys?.length ?? 0, + tryCast>(decodeJson(req)) + ?.tryGetMap('one_time_keys') + ?.keys + .length ?? + 0, } }, '/client/v3/keys/query': (var req) => {