Skip to content

Commit ea0bebd

Browse files
committed
fix(rust/signed_doc): remove alg from top-level protected header
1 parent c41bbb5 commit ea0bebd

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

rust/signed_doc/examples/mk_signed_doc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ fn brotli_decompress_json(mut doc_bytes: &[u8]) -> anyhow::Result<serde_json::Va
186186

187187
fn cose_protected_header() -> coset::Header {
188188
coset::HeaderBuilder::new()
189-
.algorithm(coset::iana::Algorithm::EdDSA)
190189
.content_format(coset::iana::CoapContentFormat::Json)
191190
.text_value(
192191
CONTENT_ENCODING_KEY.to_string(),
@@ -269,7 +268,9 @@ fn load_public_key_from_file(pk_path: &PathBuf) -> anyhow::Result<ed25519_dalek:
269268
}
270269

271270
fn add_signature_to_cose(cose: &mut coset::CoseSign, sk: &ed25519_dalek::SigningKey, kid: String) {
272-
let protected_header = coset::HeaderBuilder::new().key_id(kid.into_bytes());
271+
let protected_header = coset::HeaderBuilder::new()
272+
.key_id(kid.into_bytes())
273+
.algorithm(coset::iana::Algorithm::EdDSA);
273274
let mut signature = coset::CoseSignatureBuilder::new()
274275
.protected(protected_header.build())
275276
.build();

rust/signed_doc/src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,44 +175,43 @@ impl CatalystSignedDocument {
175175
/// Return Document Type `UUIDv4`.
176176
#[must_use]
177177
pub fn doc_type(&self) -> uuid::Uuid {
178-
self.inner.metadata.r#type
178+
self.inner.metadata.doc_type()
179179
}
180180

181181
/// Return Document ID `UUIDv7`.
182182
#[must_use]
183183
pub fn doc_id(&self) -> uuid::Uuid {
184-
self.inner.metadata.id
184+
self.inner.metadata.doc_id()
185185
}
186186

187187
/// Return Document Version `UUIDv7`.
188188
#[must_use]
189189
pub fn doc_ver(&self) -> uuid::Uuid {
190-
self.inner.metadata.ver
190+
self.inner.metadata.doc_ver()
191191
}
192192

193193
/// Return Last Document Reference `Option<DocumentRef>`.
194194
#[must_use]
195195
pub fn doc_ref(&self) -> Option<DocumentRef> {
196-
self.inner.metadata.r#ref
196+
self.inner.metadata.doc_ref()
197197
}
198198

199199
/// Return Document Template `Option<DocumentRef>`.
200200
#[must_use]
201201
pub fn doc_template(&self) -> Option<DocumentRef> {
202-
self.inner.metadata.template
202+
self.inner.metadata.doc_template()
203203
}
204204

205205
/// Return Document Reply `Option<DocumentRef>`.
206206
#[must_use]
207207
pub fn doc_reply(&self) -> Option<DocumentRef> {
208-
self.inner.metadata.reply
208+
self.inner.metadata.doc_reply()
209209
}
210210
}
211211

212212
/// Generate the COSE protected header used by Catalyst Signed Document.
213213
fn cose_protected_header() -> coset::Header {
214214
coset::HeaderBuilder::new()
215-
.algorithm(coset::iana::Algorithm::EdDSA)
216215
.content_format(coset::iana::CoapContentFormat::Json)
217216
.text_value(
218217
CONTENT_ENCODING_KEY.to_string(),
@@ -267,10 +266,6 @@ fn metadata_from_cose_protected_header(cose: &coset::CoseSign) -> (Metadata, Con
267266
let expected_header = cose_protected_header();
268267
let mut errors = Vec::new();
269268

270-
if cose.protected.header.alg != expected_header.alg {
271-
errors.push("Invalid COSE document protected header `algorithm` field".to_string());
272-
}
273-
274269
if cose.protected.header.content_type != expected_header.content_type {
275270
errors.push("Invalid COSE document protected header `content-type` field".to_string());
276271
}

0 commit comments

Comments
 (0)