Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rust/signed-doc): Remove alg field from the metadata #252

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions rust/signed_doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ pub use catalyst_types::{
};
pub use content::Content;
use coset::{CborSerializable, Header, TaggedCborSerializable};
pub use metadata::{
Algorithm, ContentEncoding, ContentType, DocumentRef, ExtraFields, Metadata, Section,
};
pub use metadata::{ContentEncoding, ContentType, DocumentRef, ExtraFields, Metadata, Section};
use minicbor::{decode, encode, Decode, Decoder, Encode};
pub use signature::{IdUri, Signatures};

Expand Down
48 changes: 0 additions & 48 deletions rust/signed_doc/src/metadata/algorithm.rs

This file was deleted.

31 changes: 0 additions & 31 deletions rust/signed_doc/src/metadata/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
//! Catalyst Signed Document Metadata.
use std::fmt::{Display, Formatter};

mod algorithm;
mod content_encoding;
mod content_type;
mod document_ref;
mod extra_fields;
mod section;
pub(crate) mod utils;

pub use algorithm::Algorithm;
use catalyst_types::{
problem_report::ProblemReport,
uuid::{UuidV4, UuidV7},
Expand Down Expand Up @@ -42,8 +40,6 @@ pub struct Metadata(InnerMetadata);
/// An actual representation of all metadata fields.
#[derive(Clone, Debug, PartialEq, serde::Deserialize, Default)]
pub(crate) struct InnerMetadata {
/// Cryptographic Algorithm
alg: Option<Algorithm>,
/// Document Type `UUIDv4`.
#[serde(rename = "type")]
doc_type: Option<UuidV4>,
Expand All @@ -63,14 +59,6 @@ pub(crate) struct InnerMetadata {
}

impl Metadata {
/// Return Document Cryptographic Algorithm
///
/// # Errors
/// - Missing 'alg' field.
pub fn algorithm(&self) -> anyhow::Result<Algorithm> {
self.0.alg.ok_or(anyhow::anyhow!("Missing 'alg' field"))
}

/// Return Document Type `UUIDv4`.
///
/// # Errors
Expand Down Expand Up @@ -121,9 +109,6 @@ impl Metadata {

/// Build `Metadata` object from the metadata fields, doing all necessary validation.
pub(crate) fn from_metadata_fields(metadata: InnerMetadata, report: &ProblemReport) -> Self {
if metadata.alg.is_none() {
report.missing_field("alg", "Missing alg field in COSE protected header");
}
if metadata.doc_type.is_none() {
report.missing_field("type", "Missing type field in COSE protected header");
}
Expand Down Expand Up @@ -181,20 +166,6 @@ impl InnerMetadata {
..Self::default()
};

if let Some(coset::RegisteredLabelWithPrivate::Assigned(alg)) = protected.header.alg {
match Algorithm::try_from(alg) {
Ok(alg) => metadata.alg = Some(alg),
Err(e) => {
report.conversion_error(
"COSE protected header algorithm",
&format!("{alg:?}"),
&format!("Expected Algorithm: {e}"),
&format!("{COSE_DECODING_CONTEXT}, Algorithm"),
);
},
}
}

if let Some(value) = protected.header.content_type.as_ref() {
match ContentType::try_from(value) {
Ok(ct) => metadata.content_type = Some(ct),
Expand Down Expand Up @@ -260,7 +231,6 @@ impl Display for Metadata {
writeln!(f, " type: {:?},", self.0.doc_type)?;
writeln!(f, " id: {:?},", self.0.id)?;
writeln!(f, " ver: {:?},", self.0.ver)?;
writeln!(f, " alg: {:?},", self.0.alg)?;
writeln!(f, " content_type: {:?}", self.0.content_type)?;
writeln!(f, " content_encoding: {:?}", self.0.content_encoding)?;
writeln!(f, " additional_fields: {:?},", self.0.extra)?;
Expand All @@ -273,7 +243,6 @@ impl TryFrom<&Metadata> for coset::Header {

fn try_from(meta: &Metadata) -> Result<Self, Self::Error> {
let mut builder = coset::HeaderBuilder::new()
.algorithm(meta.algorithm()?.into())
.content_format(CoapContentFormat::from(meta.content_type()?));

if let Some(content_encoding) = meta.content_encoding() {
Expand Down
3 changes: 0 additions & 3 deletions rust/signed_doc/tests/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ async fn test_valid_comment_doc() {

let uuid_v7 = UuidV7::new();
let (doc, ..) = common::create_dummy_signed_doc(Some(serde_json::json!({
"alg": Algorithm::EdDSA.to_string(),
"content-type": ContentType::Json.to_string(),
"content-encoding": ContentEncoding::Brotli.to_string(),
"type": doc_types::COMMENT_DOCUMENT_UUID_TYPE,
Expand Down Expand Up @@ -63,7 +62,6 @@ async fn test_valid_comment_doc_with_reply() {

let uuid_v7 = UuidV7::new();
let (doc, ..) = common::create_dummy_signed_doc(Some(serde_json::json!({
"alg": Algorithm::EdDSA.to_string(),
"content-type": ContentType::Json.to_string(),
"content-encoding": ContentEncoding::Brotli.to_string(),
"type": doc_types::COMMENT_DOCUMENT_UUID_TYPE,
Expand Down Expand Up @@ -101,7 +99,6 @@ async fn test_invalid_comment_doc() {

let uuid_v7 = UuidV7::new();
let (doc, ..) = common::create_dummy_signed_doc(Some(serde_json::json!({
"alg": Algorithm::EdDSA.to_string(),
"content-type": ContentType::Json.to_string(),
"content-encoding": ContentEncoding::Brotli.to_string(),
"type": doc_types::COMMENT_DOCUMENT_UUID_TYPE,
Expand Down
1 change: 0 additions & 1 deletion rust/signed_doc/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub fn test_metadata() -> (UuidV7, UuidV4, serde_json::Value) {
let uuid_v4 = UuidV4::new();

let metadata_fields = serde_json::json!({
"alg": Algorithm::EdDSA.to_string(),
"content-type": ContentType::Json.to_string(),
"content-encoding": ContentEncoding::Brotli.to_string(),
"type": uuid_v4.to_string(),
Expand Down
3 changes: 0 additions & 3 deletions rust/signed_doc/tests/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ async fn test_valid_proposal_doc() {

let uuid_v7 = UuidV7::new();
let (doc, ..) = common::create_dummy_signed_doc(Some(serde_json::json!({
"alg": Algorithm::EdDSA.to_string(),
"content-type": ContentType::Json.to_string(),
"content-encoding": ContentEncoding::Brotli.to_string(),
"type": doc_types::PROPOSAL_DOCUMENT_UUID_TYPE,
Expand All @@ -38,7 +37,6 @@ async fn test_valid_proposal_doc_with_empty_provider() {

let uuid_v7 = UuidV7::new();
let (doc, ..) = common::create_dummy_signed_doc(Some(serde_json::json!({
"alg": Algorithm::EdDSA.to_string(),
"content-type": ContentType::Json.to_string(),
"content-encoding": ContentEncoding::Brotli.to_string(),
"type": doc_types::PROPOSAL_DOCUMENT_UUID_TYPE,
Expand All @@ -61,7 +59,6 @@ async fn test_valid_proposal_doc_with_empty_provider() {
async fn test_invalid_proposal_doc() {
let uuid_v7 = UuidV7::new();
let (doc, ..) = common::create_dummy_signed_doc(Some(serde_json::json!({
"alg": Algorithm::EdDSA.to_string(),
"content-type": ContentType::Json.to_string(),
"content-encoding": ContentEncoding::Brotli.to_string(),
"type": doc_types::PROPOSAL_DOCUMENT_UUID_TYPE,
Expand Down