add control socket serde code

This commit is contained in:
wucke13
2023-10-19 23:40:08 +02:00
parent c072b7825f
commit c2f8f9006a
2 changed files with 42 additions and 0 deletions

38
src/control_commands.rs Normal file
View File

@@ -0,0 +1,38 @@
//! Data structures representing the control messages going over the control socket
//!
//! This module uses the same de-/serialization mechanism as [crate::msgs].
//! If you want to interface with `rosenpassd`, this is where you can look up the format
//! of the messages that are accepted.
use crate::{data_lense, msgs::LenseView, RosenpassError};
data_lense! { ControlComand<C> :=
/// [MsgType] of this message
msg_type: 1
}
#[repr(u8)]
#[derive(Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
pub enum CommandType {
/// Add one peer
AddPeer = 0x10,
/// Remove all peers that match the given public key
RemovePeerPk = 0x11,
/// Remove all peers that match the given address
RemovePeerIp = 0x12,
}
impl TryFrom<u8> for CommandType {
type Error = RosenpassError;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Ok(match value {
0x10 => CommandType::AddPeer,
0x11 => CommandType::RemovePeerPk,
0x12 => CommandType::RemovePeerIp,
_ => return Err(RosenpassError::InvalidMessageType(value)),
})
}
}

View File

@@ -8,6 +8,7 @@ pub mod labeled_prf;
pub mod app_server;
pub mod cli;
pub mod config;
pub mod control_commands;
pub mod msgs;
pub mod pqkem;
pub mod prftree;
@@ -26,6 +27,9 @@ pub enum RosenpassError {
},
#[error("invalid message type")]
InvalidMessageType(u8),
#[error("invalid command type")]
InvalidCommandType(u8),
}
impl RosenpassError {