1#![deny(clippy::all)]
6#![deny(clippy::pedantic)]
7
8pub mod auth;
9pub mod cli;
10pub mod command;
11pub mod crypto;
12pub mod device;
13pub mod handle;
14pub mod io;
15pub mod job;
16pub mod key;
17pub mod pcr;
18pub mod policy;
19pub mod print;
20pub mod spinner;
21pub mod template;
22pub mod vtpm;
23
24pub static TEARDOWN: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
30
31pub fn write_object<T: tpm2_protocol::TpmBuild>(
37 obj: &T,
38) -> Result<Vec<u8>, tpm2_protocol::TpmError> {
39 let mut buf = vec![0u8; tpm2_protocol::constant::TPM_MAX_COMMAND_SIZE];
40 let len = {
41 let mut writer = tpm2_protocol::TpmWriter::new(&mut buf);
42 obj.build(&mut writer)?;
43 writer.len()
44 };
45 buf.truncate(len);
46 Ok(buf)
47}
48
49pub fn parse_hex_u32(hex_str: &str) -> Result<u32, std::num::ParseIntError> {
55 let hex_str = hex_str.strip_prefix("0x").unwrap_or(hex_str);
56 u32::from_str_radix(hex_str, 16)
57}