File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ pub use serde_bytes::ByteBuf;
44
55pub struct Nsm ( i32 ) ;
66
7- #[ derive( Debug ) ]
7+ #[ derive( Debug , PartialEq ) ]
88pub enum Error {
99 AttestationError ( AttestationError ) ,
1010 BufferTooSmall ,
@@ -105,7 +105,6 @@ impl TryFrom<Response> for Pcr {
105105impl Nsm {
106106 pub fn new ( ) -> Result < Self , Error > {
107107 let fd = nsm_driver:: nsm_init ( ) ;
108-
109108 if fd < 0 {
110109 Err ( Error :: CannotOpenDriver )
111110 } else {
@@ -151,6 +150,18 @@ impl Nsm {
151150 _ => Err ( Error :: InvalidResponse ) ,
152151 }
153152 }
153+
154+ /// Lock PlatformConfigurationRegisters at indexes `[0, range)` from further modifications
155+ pub fn lock_pcrs ( & self , range : u16 ) -> Result < ( ) , Error > {
156+ let req = Request :: LockPCRs {
157+ range,
158+ } ;
159+ match nsm_driver:: nsm_process_request ( self . 0 , req) {
160+ Response :: LockPCRs => Ok ( ( ) ) ,
161+ Response :: Error ( code) => Err ( code. into ( ) ) ,
162+ _ => Err ( Error :: InvalidResponse ) ,
163+ }
164+ }
154165}
155166
156167impl Drop for Nsm {
Original file line number Diff line number Diff line change @@ -38,4 +38,10 @@ fn main() {
3838 nsm. lock_pcr ( 16 ) . unwrap ( ) ;
3939 println ! ( "pcr16 = {:?}" , nsm. describe_pcr( 10 ) ) ;
4040 assert_eq ! ( nsm. describe_pcr( 16 ) . unwrap( ) . locked, true ) ;
41+
42+ nsm. lock_pcrs ( 18 ) . unwrap ( ) ;
43+ for pcr in 0 ..=18 {
44+ println ! ( "#pcr{} = {:?}" , pcr, nsm. describe_pcr( pcr) ) ;
45+ assert_eq ! ( nsm. describe_pcr( pcr) . map( |val| val. locked) , Ok ( pcr < 18 ) ) ;
46+ }
4147}
You can’t perform that action at this time.
0 commit comments