mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-11-01 18:30:51 +08:00
refactor: 将 DTLS 本地依赖迁移到 libs 目录
This commit is contained in:
41
libs/dtls/src/application_data.rs
Normal file
41
libs/dtls/src/application_data.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use super::content::*;
|
||||
use crate::error::Result;
|
||||
|
||||
// Application data messages are carried by the record layer and are
|
||||
// fragmented, compressed, and encrypted based on the current connection
|
||||
// state. The messages are treated as transparent data to the record
|
||||
// layer.
|
||||
/// ## Specifications
|
||||
///
|
||||
/// * [RFC 5246 §10]
|
||||
///
|
||||
/// [RFC 5246 §10]: https://tools.ietf.org/html/rfc5246#section-10
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct ApplicationData {
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl ApplicationData {
|
||||
pub fn content_type(&self) -> ContentType {
|
||||
ContentType::ApplicationData
|
||||
}
|
||||
|
||||
pub fn size(&self) -> usize {
|
||||
self.data.len()
|
||||
}
|
||||
|
||||
pub fn marshal<W: Write>(&self, writer: &mut W) -> Result<()> {
|
||||
writer.write_all(&self.data)?;
|
||||
|
||||
Ok(writer.flush()?)
|
||||
}
|
||||
|
||||
pub fn unmarshal<R: Read>(reader: &mut R) -> Result<Self> {
|
||||
let mut data: Vec<u8> = vec![];
|
||||
reader.read_to_end(&mut data)?;
|
||||
|
||||
Ok(ApplicationData { data })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user