A crate for #TPM 2.0 library protocol, or beginnings of it: https://gitlab.com/jarkkojs/tpm2_library/
Sub-crates:
tpm2_call
for TPM 2.0 library protocol shenanigans.tpm2_cli
for a command-line interfaces.Development process:
I aim to do cli first as Linux tied but it could also have e.g. Windows backend. tpm2_call
will be portable between operating systems.
For this type of rigid decoding Rust’s type system is pretty efficient:
pub struct ReturnCodeError;
impl TryFrom<u16> for ReturnCode {
type Error = ReturnCodeError;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::from_repr(if value & RC_FMT1 != 0 {
value & (0x3F + RC_FMT1)
} else if value & RC_WARN != 0 {
value & (0x7F + RC_WARN)
} else if value & RC_VER1 != 0 {
value & (0x7F + RC_VER1)
} else {
// RC_VER0
value & 0x7F
})
.ok_or(ReturnCodeError)
}
}
There should be TryFrom
equivalent for Option
tho. In this example not having that adds only extra complexity… Like MaybeFrom
?