Skip to content

Commit 06155eb

Browse files
authored
feat: add Manifest::signature to get Cose_Sign1 signature (#1699)
* feat: add `Manifest::signature` to get Cose_Sign1 signature * fix: skip serializing signature value in manifest * fix: optionally include signature in manifest if parsable
1 parent c3d78c0 commit 06155eb

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

sdk/src/claim.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::{
2020

2121
use async_generic::async_generic;
2222
use chrono::{DateTime, Utc};
23+
use coset::CoseSign1;
2324
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
2425
use serde_json::{json, Map, Value};
2526
use uuid::Uuid;
@@ -1051,6 +1052,17 @@ impl Claim {
10511052
&self.signature_val
10521053
}
10531054

1055+
/// Returns the `COSE_Sign1_Tagged` structure found in the claim signature box.
1056+
pub fn cose_sign1(&self) -> Result<CoseSign1> {
1057+
let sig = self.signature_val();
1058+
let data = self.data()?;
1059+
let mut validation_log =
1060+
StatusTracker::with_error_behavior(ErrorBehavior::StopOnFirstError);
1061+
1062+
let sign1 = parse_cose_sign1(sig, &data, &mut validation_log)?;
1063+
Ok(sign1)
1064+
}
1065+
10541066
/// get claim generator
10551067
pub fn claim_generator(&self) -> Option<&str> {
10561068
self.claim_generator.as_deref()

sdk/src/manifest.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ pub struct Manifest {
118118
#[serde(skip_serializing_if = "Option::is_none")]
119119
label: Option<String>,
120120

121+
/// The [`CoseSign1::signature`] value.
122+
///
123+
/// [`CoseSign1::signature`]: coset::CoseSign1::signature
124+
#[serde(skip)]
125+
signature: Option<Vec<u8>>,
126+
121127
/// Indicates where a generated manifest goes
122128
#[serde(skip)]
123129
remote_manifest: Option<RemoteManifest>,
@@ -236,6 +242,12 @@ impl Manifest {
236242
self.signature_info.as_ref()
237243
}
238244

245+
/// Returns the signature field of the `COSE_Sign1_Tagged` structure found in the
246+
/// claim signature box.
247+
pub fn signature(&self) -> Option<&[u8]> {
248+
self.signature.as_deref()
249+
}
250+
239251
/// Returns the parent ingredient if it exists.
240252
pub fn parent(&self) -> Option<&Ingredient> {
241253
self.ingredients.iter().find(|i| i.is_parent())
@@ -368,6 +380,10 @@ impl Manifest {
368380
format: claim.format().map(|s| s.to_owned()),
369381
instance_id: claim.instance_id().to_owned(),
370382
label: Some(claim.label().to_owned()),
383+
signature: claim
384+
.cose_sign1()
385+
.ok()
386+
.map(|cose_sign1| cose_sign1.signature),
371387
..Default::default()
372388
};
373389

0 commit comments

Comments
 (0)