Skip to content

Commit 4d8a57a

Browse files
committed
Updating to fix serialization
- Removing tags from all enumerations - Using `#[serde(flatten)]` where appropriate - Swapping renames to numbers per the spec - Renamed methods to clarify raw values where appropriate. Signed-off-by: Larry Dewey <[email protected]>
1 parent 862b392 commit 4d8a57a

File tree

5 files changed

+102
-34
lines changed

5 files changed

+102
-34
lines changed

src/comid.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,24 @@ generate_tagged!((
114114
pub struct ConciseMidTag<'a> {
115115
/// Optional language identifier for the tag content
116116
#[serde(skip_serializing_if = "Option::is_none")]
117+
#[serde(rename = "0")]
117118
pub language: Option<Text<'a>>,
118119
/// Identity information for this tag
119-
#[serde(rename = "tag-identity")]
120+
#[serde(rename = "1")]
120121
pub tag_identity: TagIdentityMap<'a>,
121122
/// List of entities associated with this tag
123+
#[serde(rename = "2")]
122124
pub entities: OneOrMany<ComidEntityMap<'a>>,
123125
/// Optional references to other related tags
124126
#[serde(skip_serializing_if = "Option::is_none")]
125-
#[serde(rename = "linked-tags")]
127+
#[serde(rename = "3")]
126128
pub linked_tags: Option<OneOrMany<LinkedTagMap<'a>>>,
127129
/// Collection of triples describing the module
130+
#[serde(rename = "4")]
128131
pub triples: TriplesMap<'a>,
129132
/// Optional extensible attributes
130133
#[serde(skip_serializing_if = "Option::is_none")]
134+
#[serde(flatten)]
131135
pub extension: Option<ExtensionMap<'a>>,
132136
}
133137

@@ -189,10 +193,10 @@ impl<'a> ConciseMidTag<'a> {
189193
/// - If no reference triples exist, a new one is created
190194
/// - If a reference triple with the matching environment exists, the measurement is added to it
191195
/// - If reference triples exist but none match the environment, a new triple is added
192-
pub fn add_reference_value<T>(
196+
pub fn add_reference_raw_value<T>(
193197
&mut self,
194198
environment: &EnvironmentMap<'a>,
195-
mkey: Option<MeasuredElementTypeChoice<'a>>,
199+
mkey: MeasuredElementTypeChoice<'a>,
196200
value: &T,
197201
) -> Result<(), std::io::Error>
198202
where
@@ -204,7 +208,7 @@ impl<'a> ConciseMidTag<'a> {
204208
let raw_value = TaggedBytes::new(raw_bytes);
205209

206210
let measurement = MeasurementMap {
207-
mkey,
211+
mkey: Some(mkey),
208212
mval: MeasurementValuesMap {
209213
raw: Some(RawValueType {
210214
raw_value: raw_value.into(),
@@ -262,10 +266,10 @@ impl<'a> ConciseMidTag<'a> {
262266
}
263267
Ok(())
264268
}
265-
pub fn add_endorsement_value<T>(
269+
pub fn add_endorsement_raw_value<T>(
266270
&mut self,
267271
environment: &EnvironmentMap<'a>,
268-
mkey: Option<MeasuredElementTypeChoice<'a>>,
272+
mkey: MeasuredElementTypeChoice<'a>,
269273
value: &T,
270274
) -> Result<(), std::io::Error>
271275
where
@@ -277,7 +281,7 @@ impl<'a> ConciseMidTag<'a> {
277281
let raw_value = TaggedBytes::new(raw_bytes);
278282

279283
let measurement = MeasurementMap {
280-
mkey,
284+
mkey: Some(mkey),
281285
mval: MeasurementValuesMap {
282286
raw: Some(RawValueType {
283287
raw_value: raw_value.into(),
@@ -355,6 +359,7 @@ pub struct TagIdentityMap<'a> {
355359
/// Represents either a string or UUID tag identifier
356360
#[derive(Debug, Serialize, Deserialize, From, TryFrom, PartialEq, Eq, PartialOrd, Ord, Clone)]
357361
#[repr(C)]
362+
#[serde(untagged)]
358363
pub enum TagIdTypeChoice<'a> {
359364
/// Text string identifier
360365
Tstr(Tstr<'a>),
@@ -392,6 +397,7 @@ pub struct ComidEntityMap<'a> {
392397
/// Role types that can be assigned to entities
393398
#[derive(Debug, Serialize, Deserialize, From, TryFrom, PartialEq, Eq, PartialOrd, Ord, Clone)]
394399
#[repr(C)]
400+
#[serde(untagged)]
395401
pub enum ComidRoleTypeChoice {
396402
/// Entity that created the tag (value: 0)
397403
TagCreator = 0,
@@ -408,16 +414,17 @@ pub enum ComidRoleTypeChoice {
408414
#[repr(C)]
409415
pub struct LinkedTagMap<'a> {
410416
/// Identifier of the linked tag
411-
#[serde(rename = "linked-tag-id")]
417+
#[serde(rename = "0")]
412418
pub linked_tag_id: TagIdTypeChoice<'a>,
413419
/// Relationship type between the tags
414-
#[serde(rename = "tag-rel")]
420+
#[serde(rename = "1")]
415421
pub tag_rel: TagRelTypeChoice,
416422
}
417423

418424
/// Types of relationships between tags
419425
#[derive(Debug, Serialize, Deserialize, From, TryFrom, PartialEq, Eq, PartialOrd, Ord, Clone)]
420426
#[repr(C)]
427+
#[serde(untagged)]
421428
pub enum TagRelTypeChoice {
422429
/// This tag supplements the linked tag by providing additional information
423430
/// without replacing or invalidating the linked tag's content
@@ -433,48 +440,48 @@ pub enum TagRelTypeChoice {
433440
pub struct TriplesMap<'a> {
434441
/// Optional reference triples that link to external references
435442
#[serde(skip_serializing_if = "Option::is_none")]
436-
#[serde(rename = "reference-triples")]
443+
#[serde(rename = "0")]
437444
pub reference_triples: Option<OneOrMany<ReferenceTripleRecord<'a>>>,
438445

439446
/// Optional endorsement triples that contain verification information
440447
#[serde(skip_serializing_if = "Option::is_none")]
441-
#[serde(rename = "endorse-triples")]
448+
#[serde(rename = "1")]
442449
pub endorse_triples: Option<OneOrMany<EndorsedTripleRecord<'a>>>,
443450

444451
/// Optional identity triples that provide identity information
445452
#[serde(skip_serializing_if = "Option::is_none")]
446-
#[serde(rename = "identity-triples")]
453+
#[serde(rename = "2")]
447454
pub identity_triples: Option<OneOrMany<IdentityTripleRecord<'a>>>,
448455

449456
/// Optional attestation key triples containing cryptographic keys
450457
#[serde(skip_serializing_if = "Option::is_none")]
451-
#[serde(rename = "attest_key-triples")]
458+
#[serde(rename = "3")]
452459
pub attest_key_triples: Option<OneOrMany<AttestKeyTripleRecord<'a>>>,
453460

454461
/// Optional domain dependency triples describing relationships between domains
455462
#[serde(skip_serializing_if = "Option::is_none")]
456-
#[serde(rename = "dependency-triples")]
463+
#[serde(rename = "4")]
457464
pub dependency_triples: Option<OneOrMany<DomainDependencyTripleRecord<'a>>>,
458465

459466
/// Optional domain membership triples describing domain associations
460467
#[serde(skip_serializing_if = "Option::is_none")]
461-
#[serde(rename = "membership-triples")]
468+
#[serde(rename = "5")]
462469
pub membership_triples: Option<OneOrMany<DomainMembershipTripleRecord<'a>>>,
463470

464471
/// Optional SWID triples containing software identification data
465472
#[serde(skip_serializing_if = "Option::is_none")]
466-
#[serde(rename = "coswid-triples")]
473+
#[serde(rename = "6")]
467474
pub coswid_triples: Option<OneOrMany<CoswidTripleRecord<'a>>>,
468475

469476
/// Optional conditional endorsement series triples for complex endorsement chains
470477
#[serde(skip_serializing_if = "Option::is_none")]
471-
#[serde(rename = "conditional-endorsement-series-triples")]
478+
#[serde(rename = "8")]
472479
pub conditional_endorsement_series_triples:
473480
Option<OneOrMany<ConditionalEndorsementSeriesTripleRecord<'a>>>,
474481

475482
/// Optional conditional endorsement triples for conditional verification
476483
#[serde(skip_serializing_if = "Option::is_none")]
477-
#[serde(rename = "conditional-endorsement-triples")]
484+
#[serde(rename = "10")]
478485
pub conditional_endorsement_triples: Option<OneOrMany<ConditionalEndorsementTripleRecord<'a>>>,
479486

480487
/// Optional extensible attributes for future expansion

src/core.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,10 @@ pub struct MaskedRawValue {
343343
#[repr(C)]
344344
/// Container for raw values with optional masking
345345
pub struct RawValueType {
346+
#[serde(rename = "4")]
346347
pub raw_value: RawValueTypeChoice,
348+
#[serde(skip_serializing_if = "Option::is_none")]
349+
#[serde(rename = "5")]
347350
pub raw_value_mask: Option<RawValueMaskType>,
348351
}
349352

src/corim.rs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub type UnsignedCorimMap<'a> = CorimMap<'a>;
9393
/// A type choice representing either a signed or unsigned CoRIM manifest
9494
#[repr(C)]
9595
#[derive(Debug, Serialize, Deserialize, From, TryFrom)]
96+
#[serde(untagged)]
9697
pub enum ConciseRimTypeChoice<'a> {
9798
/// An unprotected CoRIM with CBOR tag 501
9899
TaggedUnsignedCorimMap(TaggedUnsignedCorimMap<'a>),
@@ -122,24 +123,29 @@ generate_tagged!(
122123
#[derive(
123124
Debug, Serialize, Deserialize, From, Constructor, PartialEq, Eq, PartialOrd, Ord, Clone,
124125
)]
126+
#[repr(C)]
125127
pub struct CorimMap<'a> {
126128
/// Unique identifier for the CoRIM
129+
#[serde(rename = "0")]
127130
pub id: CorimIdTypeChoice<'a>,
128131
/// Collection of tags contained in this CoRIM
132+
#[serde(rename = "1")]
129133
pub tags: OneOrMany<ConciseTagTypeChoice<'a>>,
130134
/// Optional references to other CoRIMs this one depends on
131135
#[serde(skip_serializing_if = "Option::is_none")]
132-
#[serde(rename = "dependent-rims")]
136+
#[serde(rename = "2")]
133137
pub dependent_rims: Option<Vec<CorimLocatorMap<'a>>>,
134138
/// Optional profile information
135139
#[serde(skip_serializing_if = "Option::is_none")]
140+
#[serde(rename = "3")]
136141
pub profile: Option<ProfileTypeChoice<'a>>,
137142
/// Optional validity period for the CoRIM
138143
#[serde(skip_serializing_if = "Option::is_none")]
139-
#[serde(rename = "rim-validity")]
144+
#[serde(rename = "4")]
140145
pub rim_validity: Option<ValidityMap>,
141146
/// Optional list of entities associated with this CoRIM
142147
#[serde(skip_serializing_if = "Option::is_none")]
148+
#[serde(rename = "5")]
143149
pub entities: Option<OneOrMany<CorimEntityMap<'a>>>,
144150
/// Optional extensible attributes
145151
#[serde(flatten)]
@@ -150,6 +156,8 @@ pub struct CorimMap<'a> {
150156
/// Represents either a string or UUID identifier for a CoRIM
151157
#[repr(C)]
152158
#[derive(Debug, Serialize, Deserialize, From, TryFrom, PartialEq, Eq, PartialOrd, Ord, Clone)]
159+
#[serde(untagged)]
160+
153161
pub enum CorimIdTypeChoice<'a> {
154162
/// Text string identifier
155163
Tstr(Tstr<'a>),
@@ -166,6 +174,7 @@ impl<'a> From<&'a str> for CorimIdTypeChoice<'a> {
166174
/// Types of tags that can be included in a CoRIM
167175
#[repr(C)]
168176
#[derive(Debug, Serialize, Deserialize, From, TryFrom, PartialEq, Eq, PartialOrd, Ord, Clone)]
177+
#[serde(untagged)]
169178
pub enum ConciseTagTypeChoice<'a> {
170179
/// A Concise Software Identity (CoSWID) tag
171180
Swid(TaggedConciseSwidTag<'a>),
@@ -245,15 +254,18 @@ impl<'a> From<ConciseTlTag<'a>> for ConciseTagTypeChoice<'a> {
245254
)]
246255
pub struct CorimLocatorMap<'a> {
247256
/// URI(s) where the dependent CoRIM can be found
257+
#[serde(rename = "0")]
248258
pub href: OneOrMany<Uri<'a>>,
249259
/// Optional cryptographic thumbprint for verification
250260
#[serde(skip_serializing_if = "Option::is_none")]
261+
#[serde(rename = "1")]
251262
pub thumbprint: Option<Digest<'a>>,
252263
}
253264

254265
/// Profile identifier that can be either a URI or OID
255266
#[repr(C)]
256267
#[derive(Debug, Serialize, Deserialize, From, TryFrom, PartialEq, Eq, PartialOrd, Ord, Clone)]
268+
#[serde(untagged)]
257269
pub enum ProfileTypeChoice<'a> {
258270
/// URI-based profile identifier
259271
Uri(Uri<'a>),
@@ -268,10 +280,10 @@ pub enum ProfileTypeChoice<'a> {
268280
)]
269281
pub struct ValidityMap {
270282
/// Optional start time of the validity period
271-
#[serde(rename = "not-before")]
283+
#[serde(rename = "0")]
272284
pub not_before: Option<Time>,
273285
/// Required end time of the validity period
274-
#[serde(rename = "not-after")]
286+
#[serde(rename = "1")]
275287
pub not_after: Time,
276288
}
277289

@@ -282,20 +294,25 @@ pub struct ValidityMap {
282294
)]
283295
pub struct CorimEntityMap<'a> {
284296
/// Name of the entity
285-
#[serde(rename = "entity-name")]
297+
#[serde(rename = "0")]
286298
pub entity_name: Text<'a>,
287299
/// Optional registration identifier for the entity
288-
#[serde(rename = "reg-id")]
300+
#[serde(skip_serializing_if = "Option::is_none")]
301+
#[serde(rename = "1")]
289302
pub reg_id: Option<Uri<'a>>,
290303
/// Role of the entity in relation to the CoRIM
304+
#[serde(rename = "2")]
291305
pub role: CorimRoleTypeChoice,
292306
/// Optional extensible attributes
307+
#[serde(flatten)]
308+
#[serde(skip_serializing_if = "Option::is_none")]
293309
pub extension: Option<ExtensionMap<'a>>,
294310
}
295311

296312
/// Roles that entities can have in relation to a CoRIM manifest
297313
#[derive(Debug, Serialize, Deserialize, From, TryFrom, PartialEq, Eq, PartialOrd, Ord, Clone)]
298314
#[repr(u8)]
315+
#[serde(untagged)]
299316
pub enum CorimRoleTypeChoice {
300317
/// Entity that created the manifest content
301318
ManifestCreator = 1,
@@ -334,19 +351,20 @@ pub struct COSESign1Corim<'a> {
334351
#[repr(C)]
335352
pub struct ProtectedCorimHeaderMap<'a> {
336353
/// Algorithm identifier for the signature
354+
#[serde(rename = "1")]
337355
pub alg: Int,
338356
/// Content type indicator (should be "application/rim+cbor")
339-
#[serde(rename = "content-type")]
357+
#[serde(rename = "3")]
340358
pub content_type: Text<'a>,
341359
/// Key identifier for the signing key
360+
#[serde(rename = "4")]
342361
pub kid: Bytes,
343362
/// CoRIM-specific metadata
344-
#[serde(rename = "corim-meta")]
363+
#[serde(rename = "8")]
345364
pub corim_meta: CorimMetaMap<'a>,
346365
/// Optional COSE header parameters
347366
#[serde(skip_serializing_if = "Option::is_none")]
348367
#[serde(flatten)]
349-
#[serde(rename = "cose-map")]
350368
pub cose_map: Option<CoseMap<'a>>,
351369
}
352370

@@ -357,9 +375,11 @@ pub struct ProtectedCorimHeaderMap<'a> {
357375
#[repr(C)]
358376
pub struct CorimMetaMap<'a> {
359377
/// Information about the signer
378+
#[serde(rename = "0")]
360379
pub signer: CorimSignerMap<'a>,
361380
/// Optional validity period for the signature
362-
#[serde(rename = "signature-validity")]
381+
#[serde(rename = "1")]
382+
#[serde(skip_serializing_if = "Option::is_none")]
363383
pub signature_validity: Option<ValidityMap>,
364384
}
365385

@@ -370,12 +390,14 @@ pub struct CorimMetaMap<'a> {
370390
#[repr(C)]
371391
pub struct CorimSignerMap<'a> {
372392
/// Name of the signing entity
373-
#[serde(rename = "signer-name")]
393+
#[serde(rename = "0")]
374394
pub signer_name: EntityNameTypeChoice<'a>,
375395
/// Optional URI identifying the signer
376-
#[serde(rename = "signer-uri")]
396+
#[serde(rename = "1")]
377397
pub signer_uri: Option<Uri<'a>>,
378398
/// Optional COSE-specific extensions
399+
#[serde(skip_serializing_if = "Option::is_none")]
400+
#[serde(flatten)]
379401
pub extension: Option<CoseMap<'a>>,
380402
}
381403

src/cotl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ They can be used to establish trust relationships and manage tag distribution."#
2222
#[repr(C)]
2323
pub struct ConciseTlTag<'a> {
2424
/// Identity information for this trust list tag
25-
#[serde(rename = "tag-identity")]
25+
#[serde(rename = "0")]
2626
pub tag_identity: TagIdentityMap<'a>,
2727

2828
/// List of trusted tags referenced by this trust list
29-
#[serde(rename = "tags-list")]
29+
#[serde(rename = "1")]
3030
pub tags_list: OneOrMany<TagIdentityMap<'a>>,
3131

3232
/// Validity period for this trust list
33-
#[serde(rename = "tl-validity")]
33+
#[serde(rename = "2")]
3434
pub tl_validity: ValidityMap,
3535
}

0 commit comments

Comments
 (0)