Skip to content

Commit 516fd44

Browse files
committed
Fix events to be consistent with native.
1 parent 605a656 commit 516fd44

File tree

4 files changed

+247
-118
lines changed

4 files changed

+247
-118
lines changed

lib/src/e2ee.worker/e2ee.keyhandler.dart

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,55 @@ class KeyOptions {
2727
}
2828
}
2929

30+
class KeyProvider {
31+
KeyProvider(this.worker, this.id, this.keyProviderOptions);
32+
final DedicatedWorkerGlobalScope worker;
33+
final String id;
34+
final KeyOptions keyProviderOptions;
35+
var participantKeys = <String, ParticipantKeyHandler>{};
36+
ParticipantKeyHandler? sharedKeyHandler;
37+
var sharedKey = Uint8List(0);
38+
39+
ParticipantKeyHandler getParticipantKeyHandler(String participantIdentity) {
40+
if (keyProviderOptions.sharedKey) {
41+
return getSharedKeyHandler();
42+
}
43+
var keys = participantKeys[participantIdentity];
44+
if (keys == null) {
45+
keys = ParticipantKeyHandler(
46+
worker: worker,
47+
participantIdentity: participantIdentity,
48+
keyOptions: keyProviderOptions,
49+
);
50+
if (sharedKey.isNotEmpty) {
51+
keys.setKey(sharedKey);
52+
}
53+
//keys.on(KeyHandlerEvent.KeyRatcheted, emitRatchetedKeys);
54+
participantKeys[participantIdentity] = keys;
55+
}
56+
return keys;
57+
}
58+
59+
ParticipantKeyHandler getSharedKeyHandler() {
60+
sharedKeyHandler ??= ParticipantKeyHandler(
61+
worker: worker,
62+
participantIdentity: 'shared-key',
63+
keyOptions: keyProviderOptions,
64+
);
65+
return sharedKeyHandler!;
66+
}
67+
68+
void setSharedKey(Uint8List key, {int keyIndex = 0}) {
69+
logger.info('setting shared key');
70+
sharedKey = key;
71+
getSharedKeyHandler().setKey(key, keyIndex: keyIndex);
72+
}
73+
74+
void setSifTrailer(Uint8List sifTrailer) {
75+
keyProviderOptions.uncryptedMagicBytes = sifTrailer;
76+
}
77+
}
78+
3079
const KEYRING_SIZE = 16;
3180

3281
class KeySet {

0 commit comments

Comments
 (0)