xref: /webrtc/dtls/src/change_cipher_spec/mod.rs (revision ffe74184)
1 #[cfg(test)]
2 mod change_cipher_spec_test;
3 
4 use byteorder::{ReadBytesExt, WriteBytesExt};
5 use std::io::{Read, Write};
6 
7 use super::content::*;
8 use super::error::*;
9 
10 // The change cipher spec protocol exists to signal transitions in
11 // ciphering strategies.  The protocol consists of a single message,
12 // which is encrypted and compressed under the current (not the pending)
13 // connection state.  The message consists of a single byte of value 1.
14 // https://tools.ietf.org/html/rfc5246#section-7.1
15 #[derive(Clone, PartialEq, Eq, Debug)]
16 pub struct ChangeCipherSpec;
17 
18 impl ChangeCipherSpec {
content_type(&self) -> ContentType19     pub fn content_type(&self) -> ContentType {
20         ContentType::ChangeCipherSpec
21     }
22 
size(&self) -> usize23     pub fn size(&self) -> usize {
24         1
25     }
26 
marshal<W: Write>(&self, writer: &mut W) -> Result<()>27     pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
28         writer.write_u8(0x01)?;
29 
30         Ok(writer.flush()?)
31     }
32 
unmarshal<R: Read>(reader: &mut R) -> Result<Self>33     pub fn unmarshal<R: Read>(reader: &mut R) -> Result<Self> {
34         let data = reader.read_u8()?;
35         if data != 0x01 {
36             return Err(Error::ErrInvalidCipherSpec);
37         }
38 
39         Ok(ChangeCipherSpec {})
40     }
41 }
42