1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![no_std]
#![feature(split_array, doc_cfg)]

#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

mod marshal;
mod polyfill;
mod traits;

pub mod commands;
pub mod error;
pub mod os;
pub mod types;

pub use commands::Command;
pub use error::Error;
pub use marshal::{MarshalFixed, UnmarshalAny, Marshal, Unmarshal};
pub use traits::{Tpm, TpmExt, TpmRaw};

#[cfg(test)]
mod test {
    use crate::{commands::*, types::tpm, *};
    use std::vec::Vec;

    #[test]
    fn can_exec() {
        #[allow(dead_code)]
        fn take_tpm(tpm: &mut dyn Tpm) -> Result<Vec<u8>, Error> {
            tpm.run(&Startup {
                startup_type: tpm::SU::Clear,
            })?;

            let rsp = tpm.run(&GetRandom {
                bytes_requested: 12,
            })?;
            let b = Vec::from(rsp.random_bytes);

            tpm.run(&Shutdown {
                shutdown_type: tpm::SU::Clear,
            })?;
            Ok(b)
        }
    }
}