-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into uniffi-roster-update
- Loading branch information
Showing
19 changed files
with
153 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from dataclasses import dataclass, field | ||
|
||
from mls_rs_uniffi import CipherSuite, generate_signature_keypair, Client, \ | ||
GroupStateStorage, EpochRecord, ClientConfig, ProtocolVersion | ||
|
||
|
||
@dataclass | ||
class GroupStateData: | ||
state: bytes | ||
epoch_data: list[EpochRecord] = field(default_factory=list) | ||
|
||
|
||
class PythonGroupStateStorage(GroupStateStorage): | ||
|
||
def __init__(self): | ||
self.groups: dict[str, GroupStateData] = {} | ||
|
||
def state(self, group_id: bytes): | ||
group = self.groups.get(group_id.hex()) | ||
if group == None: | ||
return None | ||
|
||
return group.state | ||
|
||
def epoch(self, group_id: bytes, epoch_id: int): | ||
group = self.groups.get(group_id.hex()) | ||
if group == None: | ||
return None | ||
|
||
for epoch in group.epoch_data: | ||
if epoch.id == epoch_id: | ||
return epoch | ||
|
||
return None | ||
|
||
def write(self, group_id: bytes, group_state: bytes, | ||
epoch_inserts: list[EpochRecord], | ||
epoch_updates: list[EpochRecord]): | ||
if group_id.hex() not in self.groups: | ||
self.groups[group_id.hex()] = GroupStateData(group_state) | ||
group = self.groups[group_id.hex()] | ||
|
||
for insert in epoch_inserts: | ||
group.epoch_data.append(insert) | ||
|
||
for update in epoch_updates: | ||
for i in range(len(group.epoch_data)): | ||
if group.epoch_data[i].id == update.id: | ||
group.epoch_data[i] = update | ||
|
||
def max_epoch_id(self, group_id: bytes): | ||
group = self.groups.get(group_id.hex()) | ||
if group == None: | ||
return None | ||
|
||
last = group.epoch_data.last() | ||
|
||
if last == None: | ||
return None | ||
|
||
return last.id | ||
|
||
|
||
group_state_storage = PythonGroupStateStorage() | ||
client_config = ClientConfig(group_state_storage, | ||
use_ratchet_tree_extension=True) | ||
|
||
key = generate_signature_keypair(CipherSuite.CURVE25519_AES128) | ||
alice = Client(b'alice', key, client_config) | ||
|
||
key = generate_signature_keypair(CipherSuite.CURVE25519_AES128) | ||
bob = Client(b'bob', key, client_config) | ||
|
||
alice = alice.create_group(None) | ||
message = bob.generate_key_package_message() | ||
|
||
output = alice.add_members([message]) | ||
alice.process_incoming_message(output.commit_message) | ||
bob = bob.join_group(None, output.welcome_messages[0]).group | ||
|
||
msg = alice.encrypt_application_message(b'hello, bob') | ||
output = bob.process_incoming_message(msg) | ||
|
||
alice.write_to_storage() | ||
|
||
assert output.data == b'hello, bob' | ||
assert len(group_state_storage.groups) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.