rtc_dtls/change_cipher_spec/
mod.rs1#[cfg(test)]
2mod change_cipher_spec_test;
3
4use byteorder::{ReadBytesExt, WriteBytesExt};
5use std::io::{Read, Write};
6
7use super::content::*;
8use shared::error::*;
9
10#[derive(Clone, PartialEq, Eq, Debug)]
20pub struct ChangeCipherSpec;
21
22impl ChangeCipherSpec {
23 pub fn content_type(&self) -> ContentType {
24 ContentType::ChangeCipherSpec
25 }
26
27 pub fn size(&self) -> usize {
28 1
29 }
30
31 pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
32 writer.write_u8(0x01)?;
33
34 Ok(writer.flush()?)
35 }
36
37 pub fn unmarshal<R: Read>(reader: &mut R) -> Result<Self> {
38 let data = reader.read_u8()?;
39 if data != 0x01 {
40 return Err(Error::ErrInvalidCipherSpec);
41 }
42
43 Ok(ChangeCipherSpec {})
44 }
45}