use crate::{
command::{self, Command},
object,
response::{self, Response},
};
use serde::{Deserialize, Serialize};
use std::fmt::{self, Debug};
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct GetLogEntriesCommand {}
impl Command for GetLogEntriesCommand {
type ResponseType = LogEntries;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LogEntries {
pub unlogged_boot_events: u16,
pub unlogged_auth_events: u16,
pub num_entries: u8,
pub entries: Vec<LogEntry>,
}
impl Response for LogEntries {
const COMMAND_CODE: command::Code = command::Code::GetLogEntries;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LogEntry {
pub item: u16,
pub cmd: command::Code,
pub length: u16,
pub session_key: object::Id,
pub target_key: object::Id,
pub second_key: object::Id,
pub result: response::Code,
pub tick: u32,
pub digest: LogDigest,
}
pub const LOG_DIGEST_SIZE: usize = 16;
#[derive(Serialize, Deserialize)]
pub struct LogDigest(pub [u8; LOG_DIGEST_SIZE]);
impl AsRef<[u8]> for LogDigest {
fn as_ref(&self) -> &[u8] {
&self.0[..]
}
}
impl Debug for LogDigest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "LogDigest(")?;
for (i, byte) in self.0.iter().enumerate() {
write!(f, "{:02x}", byte)?;
write!(f, "{}", if i == LOG_DIGEST_SIZE - 1 { ")" } else { ":" })?;
}
Ok(())
}
}