mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-10-27 16:00:49 +08:00
refactor: 将 DTLS 本地依赖迁移到 libs 目录
This commit is contained in:
46
libs/dtls/src/change_cipher_spec/mod.rs
Normal file
46
libs/dtls/src/change_cipher_spec/mod.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
#[cfg(test)]
|
||||
mod change_cipher_spec_test;
|
||||
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||
|
||||
use super::content::*;
|
||||
use super::error::*;
|
||||
|
||||
// The change cipher spec protocol exists to signal transitions in
|
||||
// ciphering strategies. The protocol consists of a single message,
|
||||
// which is encrypted and compressed under the current (not the pending)
|
||||
// connection state. The message consists of a single byte of value 1.
|
||||
/// ## Specifications
|
||||
///
|
||||
/// * [RFC 5246 §7.1]
|
||||
///
|
||||
/// [RFC 5246 §7.1]: https://tools.ietf.org/html/rfc5246#section-7.1
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct ChangeCipherSpec;
|
||||
|
||||
impl ChangeCipherSpec {
|
||||
pub fn content_type(&self) -> ContentType {
|
||||
ContentType::ChangeCipherSpec
|
||||
}
|
||||
|
||||
pub fn size(&self) -> usize {
|
||||
1
|
||||
}
|
||||
|
||||
pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
|
||||
writer.write_u8(0x01)?;
|
||||
|
||||
Ok(writer.flush()?)
|
||||
}
|
||||
|
||||
pub fn unmarshal<R: Read>(reader: &mut R) -> Result<Self> {
|
||||
let data = reader.read_u8()?;
|
||||
if data != 0x01 {
|
||||
return Err(Error::ErrInvalidCipherSpec);
|
||||
}
|
||||
|
||||
Ok(ChangeCipherSpec {})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user