@@ -27,6 +27,55 @@ class KeyOptions {
27
27
}
28
28
}
29
29
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
+
30
79
const KEYRING_SIZE = 16 ;
31
80
32
81
class KeySet {
0 commit comments