webrtc_dtls/extension/
renegotiation_info.rs

1#[cfg(test)]
2mod renegotiation_info_test;
3
4use super::*;
5use crate::error::Error::ErrInvalidPacketLength;
6
7const RENEGOTIATION_INFO_HEADER_SIZE: usize = 5;
8
9/// RenegotiationInfo allows a Client/Server to
10/// communicate their renegotiation support
11///
12/// ## Specifications
13///
14/// * [RFC 5746]
15///
16/// [RFC 5746]: https://tools.ietf.org/html/rfc5746
17#[derive(Clone, Debug, PartialEq, Eq)]
18pub struct ExtensionRenegotiationInfo {
19    pub(crate) renegotiated_connection: u8,
20}
21
22impl ExtensionRenegotiationInfo {
23    // TypeValue returns the extension TypeValue
24    pub fn extension_value(&self) -> ExtensionValue {
25        ExtensionValue::RenegotiationInfo
26    }
27
28    pub fn size(&self) -> usize {
29        3
30    }
31
32    /// marshal encodes the extension
33    pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
34        writer.write_u16::<BigEndian>(1)?; //length
35        writer.write_u8(self.renegotiated_connection)?;
36
37        Ok(writer.flush()?)
38    }
39
40    /// Unmarshal populates the extension from encoded data
41    pub fn unmarshal<R: Read>(reader: &mut R) -> Result<Self> {
42        let l = reader.read_u16::<BigEndian>()?; //length
43        if l != 1 {
44            return Err(ErrInvalidPacketLength);
45        }
46
47        let renegotiated_connection = reader.read_u8()?;
48
49        Ok(ExtensionRenegotiationInfo {
50            renegotiated_connection,
51        })
52    }
53}