Skip to content

Commit b5b09a3

Browse files
committed
feat(rust/signed-doc): decode CoseSign from tagged or untagged bytes
1 parent 33ab474 commit b5b09a3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

rust/signed_doc/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
sync::Arc,
77
};
88

9-
use coset::CborSerializable;
9+
use coset::{CborSerializable, TaggedCborSerializable};
1010

1111
/// Catalyst Signed Document Content Encoding Key.
1212
const CONTENT_ENCODING_KEY: &str = "content encoding";
@@ -128,7 +128,9 @@ impl TryFrom<Vec<u8>> for CatalystSignedDocument {
128128
type Error = anyhow::Error;
129129

130130
fn try_from(cose_bytes: Vec<u8>) -> Result<Self, Self::Error> {
131-
let cose = coset::CoseSign::from_slice(&cose_bytes)
131+
// Try reading as a tagged COSE SIGN, otherwise try reading as untagged.
132+
let cose = coset::CoseSign::from_tagged_slice(&cose_bytes)
133+
.or(coset::CoseSign::from_slice(&cose_bytes))
132134
.map_err(|e| anyhow::anyhow!("Invalid COSE Sign document: {e}"))?;
133135

134136
let (metadata, content_errors) = metadata_from_cose_protected_header(&cose);

0 commit comments

Comments
 (0)