libFenrir/src/connection/mod.rs

44 lines
988 B
Rust
Raw Normal View History

//! Connection handling and send/receive queues
pub mod handshake;
mod packet;
use ::std::vec::Vec;
pub use handshake::Handshake;
pub use packet::ConnectionID as ID;
pub use packet::{Packet, PacketData};
/// Version of the fenrir protocol in use
#[derive(::num_derive::FromPrimitive, Debug, Copy, Clone)]
#[repr(u8)]
pub enum ProtocolVersion {
/// First Fenrir Protocol Version
V0 = 0,
}
impl ProtocolVersion {
/// actual length of the protocol version field
pub const fn len() -> usize {
1
}
/// Serialize into raw bytes
pub fn serialize(&self, out: &mut u8) {
*out = *self as u8;
}
}
/// A single connection and its data
#[derive(Debug)]
pub struct Connection {
/// Connection ID
pub id: ID,
/// The main hkdf used for all secrets in this connection
pub hkdf: crate::enc::hkdf::HkdfSha3,
}
impl Connection {
pub(crate) fn new(id: ID, hkdf: crate::enc::hkdf::HkdfSha3) -> Self {
Self { id, hkdf }
}
}