use alloc::string::String;
use crate::protocol::MythicMessageError;
#[derive(Debug)]
pub enum MythicError<E> {
Protocol(MythicMessageError),
Transport(E),
}
impl<E: core::fmt::Display> core::fmt::Display for MythicError<E> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Protocol(e) => write!(f, "protocol error: {e}"),
Self::Transport(e) => write!(f, "transport error: {e}"),
}
}
}
impl<E> From<MythicMessageError> for MythicError<E> {
fn from(e: MythicMessageError) -> Self {
Self::Protocol(e)
}
}
pub trait C2Transport {
type Error;
fn checkin(&self, packed: &str) -> Result<String, Self::Error>;
fn get_tasking(&self, packed: &str) -> Result<String, Self::Error>;
fn post_response(&self, packed: &str) -> Result<String, Self::Error>;
fn staging_rsa(&self, packed: &str) -> Result<String, Self::Error> {
self.checkin(packed)
}
fn staging_translation(&self, packed: &str) -> Result<String, Self::Error> {
self.checkin(packed)
}
}
pub struct NoopC2;
impl C2Transport for NoopC2 {
type Error = core::convert::Infallible;
fn checkin(&self, _packed: &str) -> Result<String, Self::Error> {
Ok(String::new())
}
fn get_tasking(&self, _packed: &str) -> Result<String, Self::Error> {
Ok(String::new())
}
fn post_response(&self, _packed: &str) -> Result<String, Self::Error> {
Ok(String::new())
}
}