use std::fmt::{self, Debug};
use super::{Command, Response};
use response::ResponseCode;
use {Adapter, CommandType, ObjectId, Session, SessionError};
pub fn get_audit_logs<A: Adapter>(session: &mut Session<A>) -> Result<AuditLogs, SessionError> {
session.send_command(GetLogsCommand {})
}
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct GetLogsCommand {}
impl Command for GetLogsCommand {
type ResponseType = AuditLogs;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct AuditLogs {
pub unlogged_boot_events: u16,
pub unlogged_auth_events: u16,
pub num_entries: u8,
pub entries: Vec<LogEntry>,
}
impl Response for AuditLogs {
const COMMAND_TYPE: CommandType = CommandType::GetLogs;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LogEntry {
pub item: u16,
pub cmd: CommandType,
pub length: u16,
pub session_key: ObjectId,
pub target_key: ObjectId,
pub second_key: ObjectId,
pub result: ResponseCode,
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(())
}
}