@@ -98,12 +98,13 @@ fn create_tdx_report(report_data: &tdx_attest_rs::tdx_report_data_t) -> Result<t
9898///
9999/// # Returns
100100///
101- /// A `Vec<u8> ` containing the generated quote data
101+ /// A `Result ` containing the generated quote data as `Vec<u8>` on success.
102102///
103- /// # Exits
103+ /// # Errors
104104///
105- /// Exits with status code 1 if quote generation fails
106- fn create_quote ( report_data : & tdx_attest_rs:: tdx_report_data_t ) -> Vec < u8 > {
105+ /// * `QuoteGeneratorError::TdxQuoteFailed` - if the quote generation API call fails.
106+ /// * `QuoteGeneratorError::TdxQuoteEmpty` - if the API succeeds but returns no quote data.
107+ fn create_quote ( report_data : & tdx_attest_rs:: tdx_report_data_t ) -> Result < Vec < u8 > , QuoteGeneratorError > {
107108 let mut selected_att_key_id = tdx_attest_rs:: tdx_uuid_t {
108109 d : [ 0 ; TDX_UUID_SIZE ] ,
109110 } ;
@@ -113,20 +114,15 @@ fn create_quote(report_data: &tdx_attest_rs::tdx_report_data_t) -> Vec<u8> {
113114 Some ( & mut selected_att_key_id) ,
114115 0 ,
115116 ) ;
116- if result != tdx_attest_rs:: tdx_attest_error_t:: TDX_ATTEST_SUCCESS {
117- error ! ( "Failed to get the quote" ) ;
118- process:: exit ( 1 ) ;
119- }
120- match quote {
121- Some ( q) => {
122- debug ! ( "Successfully generated TDX quote with {} bytes" , q. len( ) ) ;
123- debug ! ( "Quote: {:?}" , q) ;
124- q
125- }
126- None => {
127- error ! ( "Failed to get the quote" ) ;
128- process:: exit ( 1 ) ;
129- }
117+
118+ match result {
119+ tdx_attest_rs:: tdx_attest_error_t:: TDX_ATTEST_SUCCESS => {
120+ match quote {
121+ Some ( q) => Ok ( q) ,
122+ None => Err ( QuoteGeneratorError :: TdxQuoteEmpty ) ,
123+ }
124+ } ,
125+ _ => Err ( QuoteGeneratorError :: TdxQuoteFailed ) ,
130126 }
131127}
132128
@@ -158,7 +154,8 @@ fn main() -> Result<(), QuoteGeneratorError> {
158154 debug ! ( "Report data: {:?}" , report_data. d) ;
159155 let tdx_report = create_tdx_report ( & report_data) ?; // Optional function
160156 debug ! ( "TDX report: {:?}" , tdx_report. d) ;
161- let quote = create_quote ( & report_data) ;
157+ let quote = create_quote ( & report_data) ?;
158+ debug ! ( "Quote: {:?}" , quote) ;
162159 fs:: write ( QUOTE_FILE_NAME , quote) . expect ( "Unable to write quote file" ) ;
163160 info ! ( "Quote successfully written to {}" , QUOTE_FILE_NAME ) ;
164161
0 commit comments