From f0356532be34f3f57b0303926281dda2270028db Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 16 Sep 2022 09:08:04 +0200 Subject: [PATCH] feat: Add onSecretStored StreamController to SSSS --- lib/encryption/ssss.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/encryption/ssss.dart b/lib/encryption/ssss.dart index 1a4b5732..7b4c07e1 100644 --- a/lib/encryption/ssss.dart +++ b/lib/encryption/ssss.dart @@ -29,6 +29,7 @@ import 'package:matrix/encryption/encryption.dart'; import 'package:matrix/encryption/utils/base64_unpadded.dart'; import 'package:matrix/encryption/utils/ssss_cache.dart'; import 'package:matrix/matrix.dart'; +import 'package:matrix/src/utils/cached_stream_controller.dart'; import 'package:matrix/src/utils/crypto/crypto.dart' as uc; import 'package:matrix/src/utils/run_in_root.dart'; @@ -60,6 +61,10 @@ class SSSS { final _cacheCallbacks = Function(String)>{}; final Map _cache = {}; + /// Will be called when a new secret has been stored in the database + final CachedStreamController onSecretStored = + CachedStreamController(); + SSSS(this.encryption); // for testing @@ -326,6 +331,7 @@ class SSSS { if (cacheTypes.contains(type) && db != null) { // cache the thing await db.storeSSSSCache(type, keyId, enc['ciphertext'], decrypted); + onSecretStored.add(keyId); if (_cacheCallbacks.containsKey(type) && await getCached(type) == null) { _cacheCallbacks[type]!(decrypted); } @@ -357,6 +363,7 @@ class SSSS { if (cacheTypes.contains(type) && db != null) { // cache the thing await db.storeSSSSCache(type, keyId, encrypted.ciphertext, secret); + onSecretStored.add(keyId); if (_cacheCallbacks.containsKey(type) && await getCached(type) == null) { _cacheCallbacks[type]!(secret); } @@ -387,6 +394,7 @@ class SSSS { // cache the thing await client.database?.storeSSSSCache( type, keyId, content['encrypted'][keyId]['ciphertext'], secret); + onSecretStored.add(keyId); } } @@ -553,6 +561,7 @@ class SSSS { if (_cacheCallbacks.containsKey(request.type)) { _cacheCallbacks[request.type]!(secret); } + onSecretStored.add(keyId); } } }