pub struct CryptState<EncodeDst: VoicePacketDst, DecodeDst: VoicePacketDst> { /* private fields */ }
Expand description
Implements OCB2-AES128 for encryption and authentication of the voice packets when transmitted over UDP. Also provides statistics about good, late and lost packets.
Implements a Codec
which parses a stream of encrypted data chunks into VoicePackets.
Note that OCB is covered by patents, however a license has been granted for use in “most” software. See: http://web.cs.ucdavis.edu/~rogaway/ocb/license.htm
Based on https://github.com/mumble-voip/mumble/blob/e31d267a11b4ed0597ad41309a7f6b715837141f/src/CryptState.cpp
Implementations§
Source§impl<EncodeDst: VoicePacketDst, DecodeDst: VoicePacketDst> CryptState<EncodeDst, DecodeDst>
impl<EncodeDst: VoicePacketDst, DecodeDst: VoicePacketDst> CryptState<EncodeDst, DecodeDst>
Sourcepub fn generate_new() -> Self
pub fn generate_new() -> Self
Creates a new CryptState with randomly generated key and initial encrypt- and decrypt-nonce.
Sourcepub fn new_from(
key: [u8; 16],
encrypt_nonce: [u8; 16],
decrypt_nonce: [u8; 16],
) -> Self
pub fn new_from( key: [u8; 16], encrypt_nonce: [u8; 16], decrypt_nonce: [u8; 16], ) -> Self
Creates a new CryptState from previously generated key, encrypt- and decrypt-nonce.
Sourcepub fn get_late(&self) -> u32
pub fn get_late(&self) -> u32
Returns the amount of packets which were transmitted successfully but arrived late.
Sourcepub fn get_encrypt_nonce(&self) -> [u8; 16]
pub fn get_encrypt_nonce(&self) -> [u8; 16]
Returns the nonce used for encrypting.
Sourcepub fn get_decrypt_nonce(&self) -> [u8; 16]
pub fn get_decrypt_nonce(&self) -> [u8; 16]
Returns the nonce used for decrypting.
Sourcepub fn set_decrypt_nonce(&mut self, nonce: &[u8; 16])
pub fn set_decrypt_nonce(&mut self, nonce: &[u8; 16])
Updates the nonce used for decrypting.
Sourcepub fn encrypt(&mut self, packet: VoicePacket<EncodeDst>, dst: &mut BytesMut)
pub fn encrypt(&mut self, packet: VoicePacket<EncodeDst>, dst: &mut BytesMut)
Encrypts an encoded voice packet and returns the resulting bytes.
Sourcepub fn decrypt(
&mut self,
buf: &mut BytesMut,
) -> Result<Result<VoicePacket<DecodeDst>, Error>, DecryptError>
pub fn decrypt( &mut self, buf: &mut BytesMut, ) -> Result<Result<VoicePacket<DecodeDst>, Error>, DecryptError>
Decrypts a voice packet and (if successful) returns the Result
of parsing the packet.