@@ -107,7 +107,9 @@ generate_tagged!((
107107 "A Concise Module Identifier (CoMID) structured tag"
108108) , ) ;
109109/// A Concise Module Identifier (CoMID) tag structure tagged with CBOR tag 506
110- #[ derive( Debug , Serialize , Deserialize , From , Constructor , PartialEq , Eq , PartialOrd , Ord ) ]
110+ #[ derive(
111+ Debug , Serialize , Deserialize , From , Constructor , PartialEq , Eq , PartialOrd , Ord , Clone ,
112+ ) ]
111113#[ repr( C ) ]
112114pub struct ConciseMidTag < ' a > {
113115 /// Optional language identifier for the tag content
@@ -189,7 +191,7 @@ impl<'a> ConciseMidTag<'a> {
189191 /// - If reference triples exist but none match the environment, a new triple is added
190192 pub fn add_reference_value < T > (
191193 & mut self ,
192- environment : EnvironmentMap < ' a > ,
194+ environment : & EnvironmentMap < ' a > ,
193195 mkey : Option < MeasuredElementTypeChoice < ' a > > ,
194196 value : & T ,
195197 ) -> Result < ( ) , std:: io:: Error >
@@ -216,13 +218,13 @@ impl<'a> ConciseMidTag<'a> {
216218 match & mut self . triples . reference_triples {
217219 None => {
218220 let new_record = ReferenceTripleRecord {
219- ref_env : environment,
221+ ref_env : environment. clone ( ) ,
220222 ref_claims : measurement. into ( ) ,
221223 } ;
222224 self . triples . reference_triples = Some ( OneOrMany :: One ( new_record) ) ;
223225 }
224226 Some ( OneOrMany :: One ( record) ) => {
225- if record. ref_env == environment {
227+ if record. ref_env == * environment {
226228 match & mut record. ref_claims {
227229 OneOrMany :: One ( original_claim) => {
228230 record. ref_claims =
@@ -232,7 +234,7 @@ impl<'a> ConciseMidTag<'a> {
232234 }
233235 } else {
234236 let new_record: ReferenceTripleRecord < ' a > = ReferenceTripleRecord {
235- ref_env : environment,
237+ ref_env : environment. clone ( ) ,
236238 ref_claims : measurement. into ( ) ,
237239 } ;
238240
@@ -241,7 +243,7 @@ impl<'a> ConciseMidTag<'a> {
241243 }
242244 }
243245 Some ( OneOrMany :: Many ( vec) ) => {
244- if let Some ( record) = vec. iter_mut ( ) . find ( |r| r. ref_env == environment) {
246+ if let Some ( record) = vec. iter_mut ( ) . find ( |r| r. ref_env == * environment) {
245247 match & mut record. ref_claims {
246248 OneOrMany :: One ( claim) => {
247249 record. ref_claims =
@@ -251,7 +253,7 @@ impl<'a> ConciseMidTag<'a> {
251253 }
252254 } else {
253255 let new_record = ReferenceTripleRecord {
254- ref_env : environment,
256+ ref_env : environment. clone ( ) ,
255257 ref_claims : measurement. into ( ) ,
256258 } ;
257259 vec. push ( new_record) ;
@@ -260,10 +262,85 @@ impl<'a> ConciseMidTag<'a> {
260262 }
261263 Ok ( ( ) )
262264 }
265+ pub fn add_endorsement_value < T > (
266+ & mut self ,
267+ environment : & EnvironmentMap < ' a > ,
268+ mkey : Option < MeasuredElementTypeChoice < ' a > > ,
269+ value : & T ,
270+ ) -> Result < ( ) , std:: io:: Error >
271+ where
272+ T : ?Sized + Serialize ,
273+ {
274+ let mut raw_bytes = vec ! [ ] ;
275+ ciborium:: into_writer ( value, & mut raw_bytes)
276+ . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e. to_string ( ) ) ) ?;
277+ let raw_value = TaggedBytes :: new ( raw_bytes) ;
278+
279+ let measurement = MeasurementMap {
280+ mkey,
281+ mval : MeasurementValuesMap {
282+ raw : Some ( RawValueType {
283+ raw_value : raw_value. into ( ) ,
284+ raw_value_mask : None ,
285+ } ) ,
286+ ..Default :: default ( )
287+ } ,
288+ authorized_by : None ,
289+ } ;
290+
291+ match & mut self . triples . endorse_triples {
292+ None => {
293+ let new_record = EndorsedTripleRecord {
294+ condition : environment. clone ( ) ,
295+ endorsement : measurement. into ( ) ,
296+ } ;
297+ self . triples . endorse_triples = Some ( OneOrMany :: One ( new_record) ) ;
298+ }
299+ Some ( OneOrMany :: One ( record) ) => {
300+ if record. condition == * environment {
301+ match & mut record. endorsement {
302+ OneOrMany :: One ( original_claim) => {
303+ record. endorsement =
304+ OneOrMany :: Many ( vec ! [ std:: mem:: take( original_claim) , measurement] )
305+ }
306+ OneOrMany :: Many ( claims) => claims. push ( measurement) ,
307+ }
308+ } else {
309+ let new_record: EndorsedTripleRecord < ' a > = EndorsedTripleRecord {
310+ condition : environment. clone ( ) ,
311+ endorsement : measurement. into ( ) ,
312+ } ;
313+
314+ let many = vec ! [ std:: mem:: take( record) , new_record] ;
315+ self . triples . endorse_triples = Some ( OneOrMany :: Many ( many) ) ;
316+ }
317+ }
318+ Some ( OneOrMany :: Many ( vec) ) => {
319+ if let Some ( record) = vec. iter_mut ( ) . find ( |r| r. condition == * environment) {
320+ match & mut record. endorsement {
321+ OneOrMany :: One ( claim) => {
322+ record. endorsement =
323+ OneOrMany :: Many ( vec ! [ std:: mem:: take( claim) , measurement] )
324+ }
325+ OneOrMany :: Many ( claims) => claims. push ( measurement) ,
326+ }
327+ } else {
328+ let new_record = EndorsedTripleRecord {
329+ condition : environment. clone ( ) ,
330+ endorsement : measurement. into ( ) ,
331+ } ;
332+ vec. push ( new_record) ;
333+ }
334+ }
335+ }
336+ Ok ( ( ) )
337+ }
263338}
264339
265340/// Identification information for a tag
266- #[ derive( Debug , Serialize , Deserialize , From , Constructor , PartialEq , Eq , PartialOrd , Ord ) ]
341+ #[ derive(
342+ Debug , Serialize , Deserialize , From , Constructor , PartialEq , Eq , PartialOrd , Ord , Clone ,
343+ ) ]
267344#[ repr( C ) ]
268345pub struct TagIdentityMap < ' a > {
269346 /// Unique identifier for the tag
@@ -276,7 +353,7 @@ pub struct TagIdentityMap<'a> {
276353}
277354
278355/// Represents either a string or UUID tag identifier
279- #[ derive( Debug , Serialize , Deserialize , From , TryFrom , PartialEq , Eq , PartialOrd , Ord ) ]
356+ #[ derive( Debug , Serialize , Deserialize , From , TryFrom , PartialEq , Eq , PartialOrd , Ord , Clone ) ]
280357#[ repr( C ) ]
281358pub enum TagIdTypeChoice < ' a > {
282359 /// Text string identifier
@@ -292,7 +369,9 @@ impl<'a> From<&'a str> for TagIdTypeChoice<'a> {
292369}
293370
294371/// Information about an entity associated with the tag
295- #[ derive( Debug , Serialize , Deserialize , From , Constructor , PartialEq , Eq , PartialOrd , Ord ) ]
372+ #[ derive(
373+ Debug , Serialize , Deserialize , From , Constructor , PartialEq , Eq , PartialOrd , Ord , Clone ,
374+ ) ]
296375#[ repr( C ) ]
297376pub struct ComidEntityMap < ' a > {
298377 /// Name of the entity
@@ -311,7 +390,7 @@ pub struct ComidEntityMap<'a> {
311390}
312391
313392/// Role types that can be assigned to entities
314- #[ derive( Debug , Serialize , Deserialize , From , TryFrom , PartialEq , Eq , PartialOrd , Ord ) ]
393+ #[ derive( Debug , Serialize , Deserialize , From , TryFrom , PartialEq , Eq , PartialOrd , Ord , Clone ) ]
315394#[ repr( C ) ]
316395pub enum ComidRoleTypeChoice {
317396 /// Entity that created the tag (value: 0)
@@ -323,7 +402,9 @@ pub enum ComidRoleTypeChoice {
323402}
324403
325404/// Reference to another tag and its relationship to this one
326- #[ derive( Debug , Serialize , Deserialize , From , Constructor , PartialEq , Eq , PartialOrd , Ord ) ]
405+ #[ derive(
406+ Debug , Serialize , Deserialize , From , Constructor , PartialEq , Eq , PartialOrd , Ord , Clone ,
407+ ) ]
327408#[ repr( C ) ]
328409pub struct LinkedTagMap < ' a > {
329410 /// Identifier of the linked tag
@@ -335,7 +416,7 @@ pub struct LinkedTagMap<'a> {
335416}
336417
337418/// Types of relationships between tags
338- #[ derive( Debug , Serialize , Deserialize , From , TryFrom , PartialEq , Eq , PartialOrd , Ord ) ]
419+ #[ derive( Debug , Serialize , Deserialize , From , TryFrom , PartialEq , Eq , PartialOrd , Ord , Clone ) ]
339420#[ repr( C ) ]
340421pub enum TagRelTypeChoice {
341422 /// This tag supplements the linked tag by providing additional information
@@ -347,7 +428,7 @@ pub enum TagRelTypeChoice {
347428}
348429
349430/// Collection of different types of triples describing the module characteristics
350- #[ derive( Default , Debug , Serialize , Deserialize , From , PartialEq , Eq , PartialOrd , Ord ) ]
431+ #[ derive( Default , Debug , Serialize , Deserialize , From , PartialEq , Eq , PartialOrd , Ord , Clone ) ]
351432#[ repr( C ) ]
352433pub struct TriplesMap < ' a > {
353434 /// Optional reference triples that link to external references
0 commit comments