Skip to content

Commit

Permalink
Implement Display for IsvProductIdDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
samdealy committed Apr 11, 2023
1 parent 4d378c9 commit e8bdd0b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion core/types/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ impl Display for ExtendedProductId {
#[repr(transparent)]
pub struct IsvProductId(sgx_prod_id_t);

impl_newtype! {
impl_newtype_no_display! {
IsvProductId, sgx_prod_id_t;
}

impl Display for IsvProductId {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "IsvProductId: ")?;
mc_sgx_util::fmt_hex(&self.0.to_be_bytes(), f)
}
}

/// The main body of a report from SGX
#[repr(transparent)]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Default)]
Expand Down Expand Up @@ -528,4 +535,15 @@ mod test {

assert_eq!(display_string, expected);
}

#[test]
fn display_isv_product_id() {
let sgx_prod_id_t = 60000u16;
let isv_product_id = IsvProductId::from(sgx_prod_id_t);

let display_string = format!("{}", isv_product_id);
let expected = format!("IsvProductId: {:X}", sgx_prod_id_t);

assert_eq!(display_string, expected);
}
}

0 comments on commit e8bdd0b

Please sign in to comment.