Skip to content

Commit 317c6dd

Browse files
committed
attestation: add versioned projection to V1
1 parent 67fdba7 commit 317c6dd

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

dstack-attest/src/attestation.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,20 @@ impl VersionedAttestation {
490490
self.to_bytes()
491491
}
492492

493+
/// Try to project any version into the V1 attestation schema.
494+
pub fn try_into_v1(self) -> Result<SchemaAttestation> {
495+
match self {
496+
Self::V0 { attestation } => Ok(attestation.into_v1()),
497+
Self::V1 { attestation } => Ok(attestation),
498+
}
499+
}
500+
501+
/// Turn into V1 attestation schema.
502+
pub fn into_v1(self) -> SchemaAttestation {
503+
self.try_into_v1()
504+
.or_panic("VersionedAttestation should project into V1 attestation")
505+
}
506+
493507
/// Try to project any version into the legacy attestation structure.
494508
pub fn try_into_inner(self) -> Result<Attestation> {
495509
match self {
@@ -1182,4 +1196,25 @@ mod tests {
11821196
));
11831197
assert!(matches!(upgraded.stack, SchemaStackEvidence::Dstack { .. }));
11841198
}
1199+
1200+
#[test]
1201+
fn versioned_v0_projects_to_v1() {
1202+
let projected = dummy_tdx_attestation([5u8; 64]).into_versioned().into_v1();
1203+
assert!(matches!(
1204+
projected.platform,
1205+
SchemaPlatformEvidence::Tdx { .. }
1206+
));
1207+
match projected.stack {
1208+
SchemaStackEvidence::Dstack {
1209+
report_data,
1210+
runtime_events,
1211+
config,
1212+
} => {
1213+
assert_eq!(report_data, vec![5u8; 64]);
1214+
assert!(runtime_events.is_empty());
1215+
assert_eq!(config, "{}");
1216+
}
1217+
_ => panic!("expected dstack stack"),
1218+
}
1219+
}
11851220
}

0 commit comments

Comments
 (0)