pub fn encode_session(
ratchet: &mut RopeRatchet,
plaintext: &[u8],
) -> Result<RopePacket>Expand description
Encode plaintext with forward secrecy.
Advances the ratchet, derives a per-message key, and encrypts
the plaintext using the standard KK codec. The ratchet step
metadata is embedded in the returned RopePacket.
After this call, the old ratchet state is irreversibly destroyed. Even if the ratchet is later compromised, past message keys cannot be recovered.
ยงExample
use kk_crypto::session::{RopeRatchet, encode_session, decode_session};
let secret = b"shared-secret";
let mut sender = RopeRatchet::new(secret, b"a-to-b").unwrap();
let mut receiver = RopeRatchet::new(secret, b"a-to-b").unwrap();
let packet = encode_session(&mut sender, b"hello forward secrecy").unwrap();
let plaintext = decode_session(&mut receiver, &packet).unwrap();
assert_eq!(plaintext, b"hello forward secrecy");