mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-02-10 08:53:08 +00:00
* feat: shared storage crate * chore: remove backup codes * chore: remove feature gates * chore: clean out of order demo * chore: refactor create session * chore: shorten error name * chore: clean errors * chore: remove table exist check * chore: remove unused traits * chore: remove unused functions. * chore: use tempfile for examples
30 lines
970 B
Rust
30 lines
970 B
Rust
use double_ratchets::{InstallationKeyPair, RatchetState};
|
|
|
|
fn main() {
|
|
// === Initial shared secret (X3DH / prekey result in real systems) ===
|
|
let shared_secret = [42u8; 32];
|
|
|
|
let bob_dh = InstallationKeyPair::generate();
|
|
|
|
let mut alice: RatchetState = RatchetState::init_sender(shared_secret, bob_dh.public().clone());
|
|
let mut bob: RatchetState = RatchetState::init_receiver(shared_secret, bob_dh);
|
|
|
|
let (ciphertext, header) = alice.encrypt_message(b"Hello Bob!");
|
|
|
|
// === Bob receives ===
|
|
let plaintext = bob.decrypt_message(&ciphertext, header);
|
|
println!(
|
|
"Bob received: {}",
|
|
String::from_utf8_lossy(&plaintext.unwrap())
|
|
);
|
|
|
|
// === Bob replies (triggers DH ratchet) ===
|
|
let (ciphertext, header) = bob.encrypt_message(b"Hi Alice!");
|
|
|
|
let plaintext = alice.decrypt_message(&ciphertext, header);
|
|
println!(
|
|
"Alice received: {}",
|
|
String::from_utf8_lossy(&plaintext.unwrap())
|
|
);
|
|
}
|