I sorted this out for the moment that changed the dependency to the form expected by cargo publish
: https://crates.io/crates/tpm2_cli
So, main goal for 0.1.2 is to fix this glitch ;-)
There should be TryFrom
equivalent for Option
tho. In this example not having that adds only extra complexity… Like MaybeFrom
?
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)
}
}
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.
So for my TPM2 crate I was thinking to rename the project Git as tpm2_library
and have sub-crates tpm2_call
for protoco and tpm2_cli
with a sub-command tpm2cli rc
.
Is it acceptable to name for consistency sake the sub-crate directory as tpm2_cli
but generate an executable as tpm2cli
?
Root project’s name inherits from https://trustedcomputinggroup.org/resource/tpm-library-specification/
I initiated my own #TPM2 #Rust crate partly because the output given by tpm2_rc_decode does not give back the mnemonic of a return code.
Here’s the example from its man page:
tpm2_rc_decode 0x1d5
tpm:parameter(1):structure is the wrong size
So I wrote my return code decoder, and here’s how it works with the previous example:
target/debug/examples/tpm2rc 0x1d5
TPM_RC_SIZE
The Git-repository is available here: https://gitlab.com/jarkkojs/tpm2_call
I’m not going to add any code this crate dealing with /dev/tpm0
. Instead the plan is to implement command buffer builder and parser with similar high-level ideas as I’ve done in the #Linux #kernel.
📣 Only 2 days (today and tomorrow) left to get your talk proposals in for the All Systems Go! 2024 CFP.
The clock ⏲️ is ticking!
🏃♂️ Hurry over to get yours in: https://cfp.all-systems-go.io/all-systems-go-2024/cfp