feat: Add onSecretStored StreamController to SSSS
This commit is contained in:
parent
03cf6c8e06
commit
f0356532be
|
|
@ -29,6 +29,7 @@ import 'package:matrix/encryption/encryption.dart';
|
||||||
import 'package:matrix/encryption/utils/base64_unpadded.dart';
|
import 'package:matrix/encryption/utils/base64_unpadded.dart';
|
||||||
import 'package:matrix/encryption/utils/ssss_cache.dart';
|
import 'package:matrix/encryption/utils/ssss_cache.dart';
|
||||||
import 'package:matrix/matrix.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/crypto/crypto.dart' as uc;
|
||||||
import 'package:matrix/src/utils/run_in_root.dart';
|
import 'package:matrix/src/utils/run_in_root.dart';
|
||||||
|
|
||||||
|
|
@ -60,6 +61,10 @@ class SSSS {
|
||||||
final _cacheCallbacks = <String, FutureOr<void> Function(String)>{};
|
final _cacheCallbacks = <String, FutureOr<void> Function(String)>{};
|
||||||
final Map<String, SSSSCache> _cache = <String, SSSSCache>{};
|
final Map<String, SSSSCache> _cache = <String, SSSSCache>{};
|
||||||
|
|
||||||
|
/// Will be called when a new secret has been stored in the database
|
||||||
|
final CachedStreamController<String> onSecretStored =
|
||||||
|
CachedStreamController();
|
||||||
|
|
||||||
SSSS(this.encryption);
|
SSSS(this.encryption);
|
||||||
|
|
||||||
// for testing
|
// for testing
|
||||||
|
|
@ -326,6 +331,7 @@ class SSSS {
|
||||||
if (cacheTypes.contains(type) && db != null) {
|
if (cacheTypes.contains(type) && db != null) {
|
||||||
// cache the thing
|
// cache the thing
|
||||||
await db.storeSSSSCache(type, keyId, enc['ciphertext'], decrypted);
|
await db.storeSSSSCache(type, keyId, enc['ciphertext'], decrypted);
|
||||||
|
onSecretStored.add(keyId);
|
||||||
if (_cacheCallbacks.containsKey(type) && await getCached(type) == null) {
|
if (_cacheCallbacks.containsKey(type) && await getCached(type) == null) {
|
||||||
_cacheCallbacks[type]!(decrypted);
|
_cacheCallbacks[type]!(decrypted);
|
||||||
}
|
}
|
||||||
|
|
@ -357,6 +363,7 @@ class SSSS {
|
||||||
if (cacheTypes.contains(type) && db != null) {
|
if (cacheTypes.contains(type) && db != null) {
|
||||||
// cache the thing
|
// cache the thing
|
||||||
await db.storeSSSSCache(type, keyId, encrypted.ciphertext, secret);
|
await db.storeSSSSCache(type, keyId, encrypted.ciphertext, secret);
|
||||||
|
onSecretStored.add(keyId);
|
||||||
if (_cacheCallbacks.containsKey(type) && await getCached(type) == null) {
|
if (_cacheCallbacks.containsKey(type) && await getCached(type) == null) {
|
||||||
_cacheCallbacks[type]!(secret);
|
_cacheCallbacks[type]!(secret);
|
||||||
}
|
}
|
||||||
|
|
@ -387,6 +394,7 @@ class SSSS {
|
||||||
// cache the thing
|
// cache the thing
|
||||||
await client.database?.storeSSSSCache(
|
await client.database?.storeSSSSCache(
|
||||||
type, keyId, content['encrypted'][keyId]['ciphertext'], secret);
|
type, keyId, content['encrypted'][keyId]['ciphertext'], secret);
|
||||||
|
onSecretStored.add(keyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -553,6 +561,7 @@ class SSSS {
|
||||||
if (_cacheCallbacks.containsKey(request.type)) {
|
if (_cacheCallbacks.containsKey(request.type)) {
|
||||||
_cacheCallbacks[request.type]!(secret);
|
_cacheCallbacks[request.type]!(secret);
|
||||||
}
|
}
|
||||||
|
onSecretStored.add(keyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue