tpm: refactor startup response check

Extract the TPM2_Startup(CLEAR) response-code check so the accepted
swtpm reset results can be covered directly.

Assisted-by: Copilot:GPT-5.5
Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu
2026-05-30 15:37:59 -07:00
committed by Rob Bradford
parent df41b03221
commit 934910b94d

View File

@@ -27,6 +27,10 @@ const TPM2_STARTUP_CLEAR: [u8; 12] = [
0x00, 0x00, // TPM_SU_CLEAR
];
fn startup_response_is_ok(response_code: u32) -> bool {
response_code == TPM_SUCCESS || response_code == TPM_RC_INITIALIZE
}
/* capability flags returned by PTM_GET_CAPABILITY */
const PTM_CAP_INIT: u64 = 1;
const PTM_CAP_SHUTDOWN: u64 = 1 << 1;
@@ -520,7 +524,7 @@ impl Emulator {
self.deliver_request(&mut cmd)?;
let response_code = u32::from_be_bytes(buffer[6..10].try_into().unwrap());
if response_code != TPM_SUCCESS && response_code != TPM_RC_INITIALIZE {
if !startup_response_is_ok(response_code) {
return Err(Error::DeliverRequest(anyhow!(
"TPM2_Startup(CLEAR) returned error code: {response_code:#X}"
)));