Skip to content

Commit 3704bfa

Browse files
committed
refactor: update create_tdx_report to return Result type
1 parent 88370bd commit 3704bfa

File tree

1 file changed

+13
-13
lines changed
  • cvmassistants/quote-generator/src

1 file changed

+13
-13
lines changed

cvmassistants/quote-generator/src/main.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,27 @@ fn create_report_data(input_bytes: &[u8]) -> Result<tdx_attest_rs::tdx_report_da
6464
Ok(report_data)
6565
}
6666

67-
/// Generates and displays a TDX report for the given report data.
68-
///
69-
/// This function creates a TDX report and logs it at debug level.
70-
/// The report is only visible when the logger is configured to show debug messages.
67+
/// Creates a TDX report from the given report data.
7168
///
7269
/// # Arguments
7370
///
7471
/// * `report_data` - The report data to use for generating the TDX report
7572
///
76-
/// # Exits
73+
/// # Returns
74+
///
75+
/// A `Result` containing the `tdx_report_t` structure on success.
76+
///
77+
/// # Errors
7778
///
78-
/// Exits with status code 1 if the report generation fails
79-
fn display_tdx_report(report_data: &tdx_attest_rs::tdx_report_data_t) {
79+
/// Returns `QuoteGeneratorError::TdxReportFailed` if the report generation fails.
80+
fn create_tdx_report(report_data: &tdx_attest_rs::tdx_report_data_t) -> Result<tdx_attest_rs::tdx_report_t, QuoteGeneratorError> {
8081
let mut tdx_report = tdx_attest_rs::tdx_report_t {
8182
d: [0; REPORT_SIZE],
8283
};
83-
let result = tdx_attest_rs::tdx_att_get_report(Some(report_data), &mut tdx_report);
84-
if result != tdx_attest_rs::tdx_attest_error_t::TDX_ATTEST_SUCCESS {
85-
error!("Failed to get the report");
86-
process::exit(1);
84+
match tdx_attest_rs::tdx_att_get_report(Some(report_data), &mut tdx_report) {
85+
tdx_attest_rs::tdx_attest_error_t::TDX_ATTEST_SUCCESS => Ok(tdx_report),
86+
_ => Err(QuoteGeneratorError::TdxReportFailed),
8787
}
88-
debug!("TDX report: {:?}", tdx_report.d);
8988
}
9089

9190
/// Creates a TDX attestation quote from the given report data.
@@ -156,7 +155,8 @@ fn main() -> Result<(), QuoteGeneratorError> {
156155
report_bytes[..input_bytes.len()].copy_from_slice(input_bytes);
157156

158157
let report_data = create_report_data(&report_bytes)?;
159-
display_tdx_report(&report_data); // Report is only displayed on debug mode - this function is optional
158+
let tdx_report = create_tdx_report(&report_data)?; // Optional function
159+
debug!("TDX report: {:?}", tdx_report.d);
160160
let quote = create_quote(&report_data);
161161
fs::write(QUOTE_FILE_NAME, quote).expect("Unable to write quote file");
162162
info!("Quote successfully written to {}", QUOTE_FILE_NAME);

0 commit comments

Comments
 (0)