Conversation

Jarkko Sakkinen

Edited 4 months ago

A crate for #TPM 2.0 library protocol, or beginnings of it: https://gitlab.com/jarkkojs/tpm2_library/

Sub-crates:

  1. tpm2_call for TPM 2.0 library protocol shenanigans.
  2. 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.

#TPM2 #Rust #rustlang

1
1
0

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)    
    }    
}    
1
0
0

Jarkko Sakkinen

Edited 4 months ago

There should be TryFrom equivalent for Option tho. In this example not having that adds only extra complexity… Like MaybeFrom ?

0
0
0