Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more Python FFI examples #89

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions mls-rs-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,66 @@ from mls_rs_uniffi import CipherSuite, generate_signature_keypair

signature_keypair = generate_signature_keypair(CipherSuite.CURVE25519_AES128)
assert signature_keypair.cipher_suite == CipherSuite.CURVE25519_AES128
"#,
)
}

#[test]
fn test_simple_scenario() -> Result<(), Box<dyn std::error::Error>> {
run_python(
r#"
from mls_rs_uniffi import CipherSuite, generate_signature_keypair, Client

key = generate_signature_keypair(CipherSuite.CURVE25519_AES128)
alice = Client(b'alice', key)

key = generate_signature_keypair(CipherSuite.CURVE25519_AES128)
bob = Client(b'bob', key)

alice = alice.create_group(None)
kp = bob.generate_key_package_message()
commit = alice.add_members([kp])
alice.process_incoming_message(commit.commit_message())
bob = bob.join_group(commit.welcome_messages()[0]).group

msg = alice.encrypt_application_message(b'hello, bob')
output = bob.process_incoming_message(msg)

assert output.data == b'hello, bob'
"#,
)
}
}

// TODO(mulmarta): it'll break if we use async trait which will be supported in
// the next UniFFI release
#[cfg(all(test, mls_build_async))]
mod async_tests {
use crate::test_utils::run_python;

#[test]
fn test_simple_scenario() -> Result<(), Box<dyn std::error::Error>> {
run_python(
r#"
from mls_rs_uniffi import CipherSuite, generate_signature_keypair, Client
from asyncio import run

key = run(generate_signature_keypair(CipherSuite.CURVE25519_AES128))
alice = Client(b'alice', key)

key = run(generate_signature_keypair(CipherSuite.CURVE25519_AES128))
bob = Client(b'bob', key)

alice = run(alice.create_group(None))
kp = run(bob.generate_key_package_message())
commit = run(alice.add_members([kp]))
run(alice.process_incoming_message(commit.commit_message()))
bob = run(bob.join_group(commit.welcome_messages()[0])).group

msg = run(alice.encrypt_application_message(b'hello, bob'))
output = run(bob.process_incoming_message(msg))

assert output.data == b'hello, bob'
"#,
)
}
Expand Down
Loading