tss_esapi/structures/clock/
clock_info.rs

1// Copyright 2021 Contributors to the Parsec project.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::{interface_types::YesNo, tss2_esys::TPMS_CLOCK_INFO, Error, Result};
5use std::convert::TryFrom;
6
7/// Information related to the internal temporal
8/// state of the TPM.
9///
10/// # Details
11/// Corresponds to `TPMS_CLOCK_INFO`
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub struct ClockInfo {
14    clock: u64,
15    reset_count: u32,
16    restart_count: u32,
17    safe: YesNo,
18}
19
20impl ClockInfo {
21    /// Returns the clock value
22    pub const fn clock(&self) -> u64 {
23        self.clock
24    }
25
26    /// Returns the reset count value
27    pub const fn reset_count(&self) -> u32 {
28        self.reset_count
29    }
30
31    /// Returns the restart count value
32    pub const fn restart_count(&self) -> u32 {
33        self.restart_count
34    }
35
36    /// Returns safe
37    pub fn safe(&self) -> bool {
38        self.safe.into()
39    }
40}
41
42impl TryFrom<TPMS_CLOCK_INFO> for ClockInfo {
43    type Error = Error;
44
45    fn try_from(tss: TPMS_CLOCK_INFO) -> Result<Self> {
46        Ok(ClockInfo {
47            clock: tss.clock,
48            reset_count: tss.resetCount,
49            restart_count: tss.restartCount,
50            safe: YesNo::try_from(tss.safe)?,
51        })
52    }
53}
54
55impl From<ClockInfo> for TPMS_CLOCK_INFO {
56    fn from(native: ClockInfo) -> Self {
57        TPMS_CLOCK_INFO {
58            clock: native.clock,
59            resetCount: native.reset_count,
60            restartCount: native.restart_count,
61            safe: native.safe.into(),
62        }
63    }
64}