Skip to content

Commit 8bfdf2a

Browse files
committed
Add startup method wrapper
Signed-off-by: Patrick Uiterwijk <[email protected]>
1 parent ab577b4 commit 8bfdf2a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/context.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
algorithm::{Cipher, HashingAlgorithm},
77
tags::PropertyTag,
88
tss::{TPMA_SESSION_DECRYPT, TPMA_SESSION_ENCRYPT},
9-
types::{capability::CapabilityType, session::SessionType},
9+
types::{capability::CapabilityType, session::SessionType, startup::StartupType},
1010
},
1111
handles::{
1212
handle_conversion::TryIntoNotNone, AuthHandle, KeyHandle, NvIndexHandle, ObjectHandle,
@@ -130,6 +130,18 @@ impl Context {
130130
}
131131
}
132132

133+
/// Send a TPM2_STARTUP command to the TPM
134+
pub fn startup(&mut self, startup_type: StartupType) -> Result<()> {
135+
let ret = unsafe { Esys_Startup(self.mut_context(), startup_type.into()) };
136+
let ret = Error::from_tss_rc(ret);
137+
if ret.is_success() {
138+
Ok(())
139+
} else {
140+
error!("Error while starting up TPM: {}", ret);
141+
Err(ret)
142+
}
143+
}
144+
133145
/// Start new authentication session and return the Session object
134146
/// associated with the session.
135147
///

tests/context_tests.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use tss_esapi::{
3939
algorithm::{Cipher, HashingAlgorithm},
4040
tags::PropertyTag,
4141
tss::*,
42-
types::{capability::CapabilityType, session::SessionType},
42+
types::{capability::CapabilityType, session::SessionType, startup::StartupType},
4343
},
4444
handles::{
4545
AuthHandle, KeyHandle, NvIndexHandle, NvIndexTpmHandle, ObjectHandle, PcrHandle,
@@ -475,6 +475,16 @@ mod test_clear {
475475
}
476476
}
477477

478+
mod test_startup {
479+
use super::*;
480+
481+
#[test]
482+
fn test_startup() {
483+
let mut context = create_ctx_without_session();
484+
context.startup(StartupType::Clear).unwrap();
485+
}
486+
}
487+
478488
mod test_pcr_extend_reset {
479489
use super::*;
480490

0 commit comments

Comments
 (0)