mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-11-01 10:20:50 +08:00
refactor: 将 DTLS 本地依赖迁移到 libs 目录
This commit is contained in:
53
libs/dtls/src/extension/renegotiation_info.rs
Normal file
53
libs/dtls/src/extension/renegotiation_info.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
#[cfg(test)]
|
||||
mod renegotiation_info_test;
|
||||
|
||||
use super::*;
|
||||
use crate::error::Error::ErrInvalidPacketLength;
|
||||
|
||||
const RENEGOTIATION_INFO_HEADER_SIZE: usize = 5;
|
||||
|
||||
/// RenegotiationInfo allows a Client/Server to
|
||||
/// communicate their renegotiation support
|
||||
///
|
||||
/// ## Specifications
|
||||
///
|
||||
/// * [RFC 5746]
|
||||
///
|
||||
/// [RFC 5746]: https://tools.ietf.org/html/rfc5746
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ExtensionRenegotiationInfo {
|
||||
pub(crate) renegotiated_connection: u8,
|
||||
}
|
||||
|
||||
impl ExtensionRenegotiationInfo {
|
||||
// TypeValue returns the extension TypeValue
|
||||
pub fn extension_value(&self) -> ExtensionValue {
|
||||
ExtensionValue::RenegotiationInfo
|
||||
}
|
||||
|
||||
pub fn size(&self) -> usize {
|
||||
3
|
||||
}
|
||||
|
||||
/// marshal encodes the extension
|
||||
pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
|
||||
writer.write_u16::<BigEndian>(1)?; //length
|
||||
writer.write_u8(self.renegotiated_connection)?;
|
||||
|
||||
Ok(writer.flush()?)
|
||||
}
|
||||
|
||||
/// Unmarshal populates the extension from encoded data
|
||||
pub fn unmarshal<R: Read>(reader: &mut R) -> Result<Self> {
|
||||
let l = reader.read_u16::<BigEndian>()?; //length
|
||||
if l != 1 {
|
||||
return Err(ErrInvalidPacketLength);
|
||||
}
|
||||
|
||||
let renegotiated_connection = reader.read_u8()?;
|
||||
|
||||
Ok(ExtensionRenegotiationInfo {
|
||||
renegotiated_connection,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user