Skip to content

Commit

Permalink
Add SpacedStructName trait
Browse files Browse the repository at this point in the history
The `SpacedStructName` trait provides a textual representation of a
struct. Instead of the common pascal case names used in rust, it is
intended to provide a lowercase space separated name. Words or acronyms
that are capitalized will still be capitalized.
  • Loading branch information
nick-mobilecoin committed Mar 15, 2023
1 parent e8620db commit ffc227c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#![no_std]

mod report_body;
mod struct_name;

pub use report_body::{
AttributesVerifier, ConfigIdVerifier, ConfigSvnVerifier, CpuSvnVerifier,
ExtendedProductIdVerifier, FamilyIdVerifier, IsvProductIdVerifier, IsvSvnVerifier,
Expand Down
43 changes: 43 additions & 0 deletions verifier/src/struct_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2023 The MobileCoin Foundation

//! Provides a trait that provides a textual friendly version of a struct name.
//! The names are all lowercase and use spaces between the words.

use mc_sgx_core_types::{
Attributes, ConfigId, ConfigSvn, CpuSvn, ExtendedProductId, FamilyId, IsvProductId, IsvSvn,
MiscellaneousSelect, MrEnclave, MrSigner, ReportData,
};

macro_rules! spaced_struct_name {
($($item:ident, $name:literal;)*) => {$(
impl SpacedStructName for $item {
fn spaced_struct_name() -> &'static str {
$name
}
}
)*}
}

/// A textual name of a struct to be used in explanatory text.
///
/// Instead of the common pascal case names used in rust, a lowercase space
/// separated name is used. Words or acronyms that are capitalized will still be
/// capitalized.
pub trait SpacedStructName {
fn spaced_struct_name() -> &'static str;
}

spaced_struct_name! {
Attributes, "attributes";
CpuSvn, "CPU SVN";
MiscellaneousSelect, "miscellaneous select";
ExtendedProductId, "extended product ID";
MrEnclave, "MRENCLAVE";
MrSigner, "MRSIGNER key hash";
ConfigId, "config ID";
IsvProductId, "ISV product ID";
IsvSvn, "ISV SVN";
ConfigSvn, "config SVN";
FamilyId, "family ID";
ReportData, "report data";
}

0 comments on commit ffc227c

Please sign in to comment.