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
use crate::{
constants::StartupType,
tss2_esys::{Esys_Shutdown, Esys_Startup},
Context, Error, Result,
};
use log::error;
impl Context {
pub fn startup(&mut self, startup_type: StartupType) -> Result<()> {
let ret = unsafe { Esys_Startup(self.mut_context(), startup_type.into()) };
let ret = Error::from_tss_rc(ret);
if ret.is_success() {
Ok(())
} else {
error!("Error while starting up TPM: {}", ret);
Err(ret)
}
}
pub fn shutdown(&mut self, shutdown_type: StartupType) -> Result<()> {
let ret = unsafe {
Esys_Shutdown(
self.mut_context(),
self.optional_session_1(),
self.optional_session_2(),
self.optional_session_3(),
shutdown_type.into(),
)
};
let ret = Error::from_tss_rc(ret);
if ret.is_success() {
Ok(())
} else {
error!("Error while shutting down TPM: {}", ret);
Err(ret)
}
}
}