Skip to main content

cocoon_tpm_tpm2_interface/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2023-2025 SUSE LLC
3// Author: Nicolai Stange <nstange@suse.de>
4
5#![no_std]
6#![macro_use]
7
8mod interface;
9pub use interface::*;
10
11/// Convenience helper to instantiate [`TpmRc`].
12///
13/// # Example:
14///
15/// ```
16/// fn foo() -> TpmRc {
17///     tpm_rc!(MEMORY)
18/// }
19/// ```
20#[allow(unused)]
21macro_rules! tpm_rc {
22    ($rc:ident) => {
23        TpmRc::$rc
24    };
25}
26
27/// Convenience helper to instantiate [`TpmErr::Rc`].
28///
29/// # Example:
30///
31/// ```
32/// fn foo() -> TpmErr {
33///     tpm_err_rc!(MEMORY)
34/// }
35/// ```
36#[allow(unused)]
37macro_rules! tpm_err_rc {
38    ($rc:ident) => {
39        TpmErr::Rc(tpm_rc!($rc))
40    };
41}
42
43/// Convenience helper to instantiate [`TpmErr::InternalErr`].
44///
45/// Any attempts to instantiate a `[`TpmErr::InternalErr`] through this macro
46/// will cause a panic in debug builds.
47#[allow(unused)]
48macro_rules! tpm_err_internal {
49    () => {
50        if cfg!(debug_assertions) {
51            panic!("TpmErr::InternalErr");
52        } else {
53            TpmErr::InternalErr {}
54        }
55    };
56}