pub struct Context { /* private fields */ }Expand description
One direction of one SRTP stream.
Directional on purpose: RFC 3711 keys each direction separately, and a context used for both would have two senders sharing one replay window and one rollover counter.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(master_key: &[u8], master_salt: &[u8]) -> Result<Self, SrtpError>
pub fn new(master_key: &[u8], master_salt: &[u8]) -> Result<Self, SrtpError>
A context from a master key and salt.
Sourcepub fn protect(&mut self, packet: &[u8]) -> Result<Vec<u8>, SrtpError>
pub fn protect(&mut self, packet: &[u8]) -> Result<Vec<u8>, SrtpError>
Encrypt and authenticate an RTP packet in place, returning it with the tag appended.
packet is a complete serialized RTP packet. The header is left readable — a relay has
to see the sequence number and SSRC to do its job — and authenticated, so it cannot be
altered without detection.
Sourcepub fn unprotect(&mut self, packet: &[u8]) -> Result<Vec<u8>, SrtpError>
pub fn unprotect(&mut self, packet: &[u8]) -> Result<Vec<u8>, SrtpError>
Authenticate and decrypt an RTP packet, returning the plaintext packet.
Authentication happens before decryption and before the replay window is updated: a packet that fails it never touches this context’s state, which is what stops an attacker advancing the window with forgeries.