use crate::{interface_types::YesNo, tss2_esys::TPMS_CLOCK_INFO, Error, Result};
use std::convert::TryFrom;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ClockInfo {
clock: u64,
reset_count: u32,
restart_count: u32,
safe: YesNo,
}
impl ClockInfo {
pub const fn clock(&self) -> u64 {
self.clock
}
pub const fn reset_count(&self) -> u32 {
self.reset_count
}
pub const fn restart_count(&self) -> u32 {
self.restart_count
}
pub fn safe(&self) -> bool {
self.safe.into()
}
}
impl TryFrom<TPMS_CLOCK_INFO> for ClockInfo {
type Error = Error;
fn try_from(tss: TPMS_CLOCK_INFO) -> Result<Self> {
Ok(ClockInfo {
clock: tss.clock,
reset_count: tss.resetCount,
restart_count: tss.restartCount,
safe: YesNo::try_from(tss.safe)?,
})
}
}
impl From<ClockInfo> for TPMS_CLOCK_INFO {
fn from(native: ClockInfo) -> Self {
TPMS_CLOCK_INFO {
clock: native.clock,
resetCount: native.reset_count,
restartCount: native.restart_count,
safe: native.safe.into(),
}
}
}