@@ -30,7 +30,7 @@ pub struct TcbInfo {
3030pub struct TcbLevel {
3131 pub tcb : Tcb ,
3232 pub tcb_date : String ,
33- pub tcb_status : String ,
33+ pub tcb_status : TcbStatus ,
3434 #[ serde( rename = "advisoryIDs" , default ) ]
3535 pub advisory_ids : Vec < String > ,
3636}
@@ -56,43 +56,68 @@ pub struct TcbComponents {
5656 pub svn : u8 ,
5757}
5858
59+ #[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , Serialize , Deserialize ) ]
60+ #[ cfg_attr( feature = "borsh" , derive( BorshSerialize , BorshDeserialize ) ) ]
61+ #[ cfg_attr( feature = "borsh_schema" , derive( BorshSchema ) ) ]
62+ pub enum TcbStatus {
63+ UpToDate ,
64+ OutOfDateConfigurationNeeded ,
65+ OutOfDate ,
66+ ConfigurationAndSWHardeningNeeded ,
67+ ConfigurationNeeded ,
68+ SWHardeningNeeded ,
69+ Revoked ,
70+ }
71+
72+ impl TcbStatus {
73+ fn severity ( & self ) -> u8 {
74+ match self {
75+ Self :: UpToDate => 0 ,
76+ Self :: SWHardeningNeeded => 1 ,
77+ Self :: ConfigurationNeeded => 2 ,
78+ Self :: ConfigurationAndSWHardeningNeeded => 3 ,
79+ Self :: OutOfDate => 4 ,
80+ Self :: OutOfDateConfigurationNeeded => 5 ,
81+ Self :: Revoked => 6 ,
82+ }
83+ }
84+
85+ pub fn is_valid ( & self ) -> bool {
86+ match self {
87+ Self :: UpToDate => true ,
88+ Self :: SWHardeningNeeded => true ,
89+ Self :: ConfigurationNeeded => true ,
90+ Self :: ConfigurationAndSWHardeningNeeded => true ,
91+ Self :: OutOfDate => true ,
92+ Self :: OutOfDateConfigurationNeeded => true ,
93+ Self :: Revoked => false ,
94+ }
95+ }
96+ }
97+
5998/// TCB status with advisory IDs
6099///
61100/// This is the result of matching a TCB level, used by both
62101/// platform TCB matching and QE Identity verification.
63- #[ derive( Clone , Debug , Default ) ]
64- pub struct TcbStatus {
65- pub status : String ,
102+ #[ derive( Clone , Debug ) ]
103+ pub struct TcbStatusWithAdvisory {
104+ pub status : TcbStatus ,
66105 pub advisory_ids : Vec < String > ,
67106}
68107
69- impl TcbStatus {
108+ impl TcbStatusWithAdvisory {
70109 /// Create a new TcbStatus with the given status and advisory IDs
71- pub fn new ( status : impl Into < String > , advisory_ids : Vec < String > ) -> Self {
110+ pub fn new ( status : TcbStatus , advisory_ids : Vec < String > ) -> Self {
72111 Self {
73- status : status . into ( ) ,
112+ status,
74113 advisory_ids,
75114 }
76115 }
77116
78- /// Create an unknown status (no matching TCB level found)
79- pub fn unknown ( ) -> Self {
80- Self {
81- status : "Unknown" . into ( ) ,
82- advisory_ids : vec ! [ ] ,
83- }
84- }
85-
86- /// Check if the TCB status is unknown
87- pub fn is_unknown ( & self ) -> bool {
88- self . status == "Unknown"
89- }
90-
91117 /// Merge two TCB statuses, taking the worse status and combining advisory IDs
92- pub fn merge ( self , other : & TcbStatus ) -> Self {
93- let final_status = if tcb_status_severity ( & other. status ) > tcb_status_severity ( & self . status )
94- {
95- other. status . clone ( )
118+ pub fn merge ( self , other : & TcbStatusWithAdvisory ) -> Self {
119+ let final_status = if other. status . severity ( ) > self . status . severity ( ) {
120+ other. status
96121 } else {
97122 self . status
98123 } ;
@@ -111,48 +136,35 @@ impl TcbStatus {
111136 }
112137}
113138
114- /// TCB status severity ordering (higher number = worse status)
115- fn tcb_status_severity ( status : & str ) -> u8 {
116- match status {
117- "UpToDate" => 0 ,
118- "SWHardeningNeeded" => 1 ,
119- "ConfigurationNeeded" => 2 ,
120- "ConfigurationAndSWHardeningNeeded" => 3 ,
121- "OutOfDate" => 4 ,
122- "OutOfDateConfigurationNeeded" => 5 ,
123- "Revoked" => 6 ,
124- _ => 100 , // Unknown status treated as worst
125- }
126- }
127-
128139#[ cfg( test) ]
129140mod tests {
130141 use super :: * ;
142+ use TcbStatus :: * ;
131143
132144 #[ test]
133145 fn test_tcb_status_merge_both_up_to_date ( ) {
134- let a = TcbStatus :: new ( " UpToDate" , vec ! [ ] ) ;
135- let b = TcbStatus :: new ( " UpToDate" , vec ! [ ] ) ;
146+ let a = TcbStatusWithAdvisory :: new ( UpToDate , vec ! [ ] ) ;
147+ let b = TcbStatusWithAdvisory :: new ( UpToDate , vec ! [ ] ) ;
136148 let result = a. merge ( & b) ;
137- assert_eq ! ( result. status, " UpToDate" ) ;
149+ assert_eq ! ( result. status, UpToDate ) ;
138150 assert ! ( result. advisory_ids. is_empty( ) ) ;
139151 }
140152
141153 #[ test]
142154 fn test_tcb_status_merge_takes_worse ( ) {
143- let a = TcbStatus :: new ( " UpToDate" , vec ! [ ] ) ;
144- let b = TcbStatus :: new ( " OutOfDate" , vec ! [ "INTEL-SA-00001" . into( ) ] ) ;
155+ let a = TcbStatusWithAdvisory :: new ( UpToDate , vec ! [ ] ) ;
156+ let b = TcbStatusWithAdvisory :: new ( OutOfDate , vec ! [ "INTEL-SA-00001" . into( ) ] ) ;
145157 let result = a. merge ( & b) ;
146- assert_eq ! ( result. status, " OutOfDate" ) ;
158+ assert_eq ! ( result. status, OutOfDate ) ;
147159 assert_eq ! ( result. advisory_ids, vec![ "INTEL-SA-00001" ] ) ;
148160 }
149161
150162 #[ test]
151163 fn test_tcb_status_merge_combines_advisories ( ) {
152- let a = TcbStatus :: new ( " OutOfDate" , vec ! [ "INTEL-SA-00001" . into( ) ] ) ;
153- let b = TcbStatus :: new ( " SWHardeningNeeded" , vec ! [ "INTEL-SA-00002" . into( ) ] ) ;
164+ let a = TcbStatusWithAdvisory :: new ( OutOfDate , vec ! [ "INTEL-SA-00001" . into( ) ] ) ;
165+ let b = TcbStatusWithAdvisory :: new ( SWHardeningNeeded , vec ! [ "INTEL-SA-00002" . into( ) ] ) ;
154166 let result = a. merge ( & b) ;
155- assert_eq ! ( result. status, " OutOfDate" ) ;
167+ assert_eq ! ( result. status, OutOfDate ) ;
156168 assert_eq ! (
157169 result. advisory_ids,
158170 vec![ "INTEL-SA-00001" , "INTEL-SA-00002" ]
@@ -161,31 +173,9 @@ mod tests {
161173
162174 #[ test]
163175 fn test_tcb_status_merge_deduplicates_advisories ( ) {
164- let a = TcbStatus :: new ( " OutOfDate" , vec ! [ "INTEL-SA-00001" . into( ) ] ) ;
165- let b = TcbStatus :: new ( " OutOfDate" , vec ! [ "INTEL-SA-00001" . into( ) ] ) ;
176+ let a = TcbStatusWithAdvisory :: new ( OutOfDate , vec ! [ "INTEL-SA-00001" . into( ) ] ) ;
177+ let b = TcbStatusWithAdvisory :: new ( OutOfDate , vec ! [ "INTEL-SA-00001" . into( ) ] ) ;
166178 let result = a. merge ( & b) ;
167179 assert_eq ! ( result. advisory_ids, vec![ "INTEL-SA-00001" ] ) ;
168180 }
169-
170- #[ test]
171- fn test_tcb_status_severity_ordering ( ) {
172- assert ! ( tcb_status_severity( "UpToDate" ) < tcb_status_severity( "SWHardeningNeeded" ) ) ;
173- assert ! (
174- tcb_status_severity( "SWHardeningNeeded" ) < tcb_status_severity( "ConfigurationNeeded" )
175- ) ;
176- assert ! (
177- tcb_status_severity( "ConfigurationNeeded" )
178- < tcb_status_severity( "ConfigurationAndSWHardeningNeeded" )
179- ) ;
180- assert ! (
181- tcb_status_severity( "ConfigurationAndSWHardeningNeeded" )
182- < tcb_status_severity( "OutOfDate" )
183- ) ;
184- assert ! (
185- tcb_status_severity( "OutOfDate" ) < tcb_status_severity( "OutOfDateConfigurationNeeded" )
186- ) ;
187- assert ! (
188- tcb_status_severity( "OutOfDateConfigurationNeeded" ) < tcb_status_severity( "Revoked" )
189- ) ;
190- }
191181}
0 commit comments