Skip to content

Commit

Permalink
Implement Display for IsvSvn
Browse files Browse the repository at this point in the history
  • Loading branch information
samdealy committed Apr 4, 2023
1 parent 285e546 commit c87a8d8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions core/types/src/svn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022-2023 The MobileCoin Foundation
//! SGX core SVN (Security Version Numbers)
use crate::{impl_newtype, impl_newtype_for_bytestruct_no_display};
use crate::{impl_newtype, impl_newtype_for_bytestruct_no_display, impl_newtype_no_display};
use core::fmt::{Display, Formatter};
use mc_sgx_core_sys_types::{sgx_config_svn_t, sgx_cpu_svn_t, sgx_isv_svn_t, SGX_CPUSVN_SIZE};

Expand All @@ -19,10 +19,17 @@ impl_newtype! {
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Default)]
pub struct IsvSvn(sgx_isv_svn_t);

impl_newtype! {
impl_newtype_no_display! {
IsvSvn, sgx_isv_svn_t;
}

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

/// CPU security version number (SVN)
#[repr(transparent)]
#[derive(Default, Debug, Clone, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -54,4 +61,15 @@ mod test {

assert_eq!(display_string, expected_string);
}

#[test]
fn isv_svn_display() {
let sgx_isv_svn_t = 3459;
let isv_svn = IsvSvn::from(sgx_isv_svn_t);

let display_string = format!("{}", isv_svn);
let expected_string = "IsvSvn: 0D83";

assert_eq!(display_string, expected_string);
}
}

0 comments on commit c87a8d8

Please sign in to comment.