File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,34 @@ impl From<ErrorCode> for Error {
7474 }
7575}
7676
77+ #[ derive( Debug , Eq , PartialEq ) ]
78+ pub struct Pcr {
79+ pub locked : bool ,
80+ pub data : Vec < u8 > ,
81+ }
82+
83+ impl Pcr {
84+ fn new ( locked : bool , data : Vec < u8 > ) -> Self {
85+ Pcr {
86+ locked,
87+ data,
88+ }
89+ }
90+ }
91+
92+ impl TryFrom < Response > for Pcr {
93+ type Error = Error ;
94+
95+ fn try_from ( req : Response ) -> Result < Self , Self :: Error > {
96+ match req {
97+ Response :: DescribePCR { lock, data } => Ok ( Pcr :: new ( lock, data) ) ,
98+ Response :: ExtendPCR { data } => Ok ( Pcr :: new ( false , data) ) /* Only unlocked PCRs can get extended */ ,
99+ Response :: Error ( code) => Err ( code. into ( ) ) ,
100+ _ => Err ( Error :: InvalidResponse ) ,
101+ }
102+ }
103+ }
104+
77105impl Nsm {
78106 pub fn new ( ) -> Result < Self , Error > {
79107 let fd = nsm_driver:: nsm_init ( ) ;
@@ -97,6 +125,13 @@ impl Nsm {
97125 _ => Err ( Error :: InvalidResponse ) ,
98126 }
99127 }
128+
129+ pub fn describe_pcr ( & mut self , idx_pcr : u16 ) -> Result < Pcr , Error > {
130+ let req = Request :: DescribePCR {
131+ index : idx_pcr,
132+ } ;
133+ nsm_driver:: nsm_process_request ( self . 0 , req) . try_into ( )
134+ }
100135}
101136
102137impl Drop for Nsm {
Original file line number Diff line number Diff line change @@ -21,4 +21,10 @@ fn main() {
2121 assert_eq ! ( doc. user_data. unwrap( ) , user_data) ;
2222 println ! ( "nonce: {:?}" , doc. nonce) ;
2323 assert_eq ! ( doc. nonce. unwrap( ) , nonce) ;
24+
25+ for idx in 0 ..32 {
26+ let pcr = nsm. describe_pcr ( idx) . unwrap ( ) ;
27+ println ! ( "# pcr{} = {:?}" , idx, pcr) ;
28+ assert_eq ! ( pcr. locked, idx <= 15 ) ;
29+ }
2430}
You can’t perform that action at this time.
0 commit comments