Skip to content

Commit 54c83b8

Browse files
committed
Adding methods to unwrap enums
Signed-off-by: Larry Dewey <[email protected]>
1 parent b931dd2 commit 54c83b8

File tree

6 files changed

+1027
-30
lines changed

6 files changed

+1027
-30
lines changed

src/comid.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,37 @@ impl<'a> ConciseMidTag<'a> {
242242
}
243243
Ok(())
244244
}
245+
/// Adds an endorsement value to the CoMID tag's endorsed triples.
246+
///
247+
/// This method serializes the provided value to CBOR bytes and adds it as a raw measurement value
248+
/// within an endorsed triple. If an endorsed triple with the same environment already exists,
249+
/// the measurement is added to that triple. Otherwise, a new endorsed triple is created.
250+
///
251+
/// # Arguments
252+
///
253+
/// * `environment` - The environment map that describes the context for this endorsement value
254+
/// * `mkey` - Measurement element type that identifies what is being measured
255+
/// * `value` - The value to serialize and store as the endorsement value
256+
///
257+
/// # Returns
258+
///
259+
/// Returns `Ok(())` if successful, or an `std::io::Error` if serialization fails.
260+
///
261+
/// # Example
262+
///
263+
/// ```ignore
264+
/// use corim_rs::{
265+
/// comid::ConciseMidTag,
266+
/// triples::{EnvironmentMap, MeasuredElementTypeChoice},
267+
/// };
268+
///
269+
/// let mut comid = ConciseMidTag::default();
270+
/// let env = EnvironmentMap::default();
271+
/// let mkey = MeasuredElementTypeChoice::SoftwareComponent;
272+
/// let endorsement_data = "example endorsement value";
273+
/// comid.add_endorsement_raw_value(&env, mkey, &endorsement_data)
274+
/// .expect("Failed to add endorsement value");
275+
/// ```
245276
pub fn add_endorsement_raw_value<T>(
246277
&mut self,
247278
environment: &EnvironmentMap<'a>,
@@ -309,6 +340,10 @@ pub struct TagIdentityMap<'a> {
309340
}
310341

311342
/// Represents either a string or UUID tag identifier
343+
///
344+
/// This enum allows CoMID tags to be identified by either a text string
345+
/// or a UUID, following the schema definition in the CoRIM specification.
346+
/// Tag identifiers are used in the tag identity map and for linking between tags.
312347
#[derive(Debug, Serialize, Deserialize, From, TryFrom, PartialEq, Eq, PartialOrd, Ord, Clone)]
313348
#[repr(C)]
314349
#[serde(untagged)]
@@ -319,6 +354,22 @@ pub enum TagIdTypeChoice<'a> {
319354
Uuid(UuidType),
320355
}
321356

357+
impl<'a> TagIdTypeChoice<'a> {
358+
/// Returns the tag identifier as a string, if it is a text value
359+
pub fn as_str(&self) -> Option<&str> {
360+
match self {
361+
Self::Tstr(tstr) => Some(tstr),
362+
_ => None,
363+
}
364+
}
365+
366+
pub fn as_uuid(&self) -> Option<UuidType> {
367+
match self {
368+
Self::Uuid(uuid) => Some((*uuid).clone()),
369+
_ => None,
370+
}
371+
}
372+
}
322373

323374
impl<'a> From<&'a str> for TagIdTypeChoice<'a> {
324375
fn from(value: &'a str) -> Self {

0 commit comments

Comments
 (0)