@@ -159,7 +159,7 @@ class FrameCryptor {
159
159
CryptorError lastError = CryptorError .kNew;
160
160
final DedicatedWorkerGlobalScope worker;
161
161
int currentKeyIndex = 0 ;
162
-
162
+ bool hasValidKey = false ;
163
163
Completer ? _ratchetCompleter;
164
164
165
165
List <KeySet ?> cryptoKeyRing = List .filled (KEYRING_SIZE , null );
@@ -242,6 +242,7 @@ class FrameCryptor {
242
242
keyOptions.ratchetSalt,
243
243
);
244
244
await setKeySetFromMaterial (keySet, keyIndex);
245
+ hasValidKey = true ;
245
246
}
246
247
247
248
Future <void > setKeySetFromMaterial (KeySet keySet, int keyIndex) async {
@@ -526,7 +527,7 @@ class FrameCryptor {
526
527
var initialKeySet = getKeySet (keyIndex);
527
528
initialKeyIndex = keyIndex;
528
529
529
- if (initialKeySet == null ) {
530
+ if (initialKeySet == null || ! hasValidKey ) {
530
531
if (lastError != CryptorError .kMissingKey) {
531
532
lastError = CryptorError .kMissingKey;
532
533
postMessage ({
@@ -635,6 +636,7 @@ class FrameCryptor {
635
636
/// yet and ratcheting, of course, did not solve the problem. So if we fail RATCHET_WINDOW_SIZE times,
636
637
/// we come back to the initial key.
637
638
await setKeySetFromMaterial (initialKeySet! , initialKeyIndex);
639
+ hasValidKey = false ;
638
640
}
639
641
}
640
642
}
0 commit comments