webrtc_dtls/extension/
extension_supported_point_formats.rs

1#[cfg(test)]
2mod extension_supported_point_formats_test;
3
4use super::*;
5
6const EXTENSION_SUPPORTED_POINT_FORMATS_SIZE: usize = 5;
7
8pub type EllipticCurvePointFormat = u8;
9
10pub const ELLIPTIC_CURVE_POINT_FORMAT_UNCOMPRESSED: EllipticCurvePointFormat = 0;
11
12/// ## Specifications
13///
14/// * [RFC 4492 §5.1.2]
15///
16/// [RFC 4492 §5.1.2]: https://tools.ietf.org/html/rfc4492#section-5.1.2
17#[derive(Clone, Debug, PartialEq, Eq)]
18pub struct ExtensionSupportedPointFormats {
19    pub(crate) point_formats: Vec<EllipticCurvePointFormat>,
20}
21
22impl ExtensionSupportedPointFormats {
23    pub fn extension_value(&self) -> ExtensionValue {
24        ExtensionValue::SupportedPointFormats
25    }
26
27    pub fn size(&self) -> usize {
28        2 + 1 + self.point_formats.len()
29    }
30
31    pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
32        writer.write_u16::<BigEndian>(1 + self.point_formats.len() as u16)?;
33        writer.write_u8(self.point_formats.len() as u8)?;
34        for v in &self.point_formats {
35            writer.write_u8(*v)?;
36        }
37
38        Ok(writer.flush()?)
39    }
40
41    pub fn unmarshal<R: Read>(reader: &mut R) -> Result<Self> {
42        let _ = reader.read_u16::<BigEndian>()?;
43
44        let point_format_count = reader.read_u8()? as usize;
45        let mut point_formats = vec![];
46        for _ in 0..point_format_count {
47            let point_format = reader.read_u8()?;
48            point_formats.push(point_format);
49        }
50
51        Ok(ExtensionSupportedPointFormats { point_formats })
52    }
53}