| 1 |
// Copyright (c) 2024 Mozilla Corporation and contributors. |
| 2 |
// SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 3 |
|
| 4 |
use mls_platform_api::PlatformError; |
| 5 |
|
| 6 |
// |
| 7 |
// Scenario |
| 8 |
// |
| 9 |
// * Alice, Bob, Charlie and Diana create signing identity (generate_signature_keypair) |
| 10 |
// * Alice, Bob, Charlie and Diana create credentials (generate_credential_basic) |
| 11 |
// * Bob and Charlie create key packages (generate_key_package) |
| 12 |
// * Alice creates a group (group_create) |
| 13 |
|
| 14 |
#[test] |
| 15 |
fn test_group_create() -> Result<(), PlatformError> { |
| 16 |
// Default group configuration |
| 17 |
let group_config = mls_platform_api::GroupConfig::default(); |
| 18 |
|
| 19 |
// Storage states |
| 20 |
let mut state_global = mls_platform_api::state_access("global.db", &[0u8; 32])?; |
| 21 |
|
| 22 |
// Credentials |
| 23 |
let alice_cred = mls_platform_api::mls_generate_credential_basic("alice".as_bytes())?; |
| 24 |
|
| 25 |
println!("\nAlice credential: {}", hex::encode(&alice_cred)); |
| 26 |
|
| 27 |
// Create signature keypairs and store them in the state |
| 28 |
let alice_id = |
| 29 |
mls_platform_api::mls_generate_identity(&state_global, group_config.ciphersuite)?; |
| 30 |
|
| 31 |
println!("\nAlice identifier: {}", hex::encode(&alice_id)); |
| 32 |
|
| 33 |
// Create a group with Alice |
| 34 |
let gide = mls_platform_api::mls_group_create( |
| 35 |
&mut state_global, |
| 36 |
&alice_id, |
| 37 |
&alice_cred, |
| 38 |
None, |
| 39 |
None, |
| 40 |
&Default::default(), |
| 41 |
)?; |
| 42 |
|
| 43 |
println!("\nGroup created by Alice: {}", hex::encode(&gide.group_id)); |
| 44 |
|
| 45 |
// List the members of the group |
| 46 |
let members = mls_platform_api::mls_group_details(&state_global, &gide.group_id, &alice_id)?; |
| 47 |
println!("Members (alice, empty group): {members:?}"); |
| 48 |
|
| 49 |
Ok(()) |
| 50 |
} |