@@ -159,7 +159,7 @@ class FrameCryptor {
159159 CryptorError lastError = CryptorError .kNew;
160160 final DedicatedWorkerGlobalScope worker;
161161 int currentKeyIndex = 0 ;
162-
162+ bool hasValidKey = false ;
163163 Completer ? _ratchetCompleter;
164164
165165 List <KeySet ?> cryptoKeyRing = List .filled (KEYRING_SIZE , null );
@@ -242,6 +242,7 @@ class FrameCryptor {
242242 keyOptions.ratchetSalt,
243243 );
244244 await setKeySetFromMaterial (keySet, keyIndex);
245+ hasValidKey = true ;
245246 }
246247
247248 Future <void > setKeySetFromMaterial (KeySet keySet, int keyIndex) async {
@@ -526,7 +527,7 @@ class FrameCryptor {
526527 var initialKeySet = getKeySet (keyIndex);
527528 initialKeyIndex = keyIndex;
528529
529- if (initialKeySet == null ) {
530+ if (initialKeySet == null || ! hasValidKey ) {
530531 if (lastError != CryptorError .kMissingKey) {
531532 lastError = CryptorError .kMissingKey;
532533 postMessage ({
@@ -635,6 +636,7 @@ class FrameCryptor {
635636 /// yet and ratcheting, of course, did not solve the problem. So if we fail RATCHET_WINDOW_SIZE times,
636637 /// we come back to the initial key.
637638 await setKeySetFromMaterial (initialKeySet! , initialKeyIndex);
639+ hasValidKey = false ;
638640 }
639641 }
640642}
0 commit comments