Skip to content

Commit 6c1f9eb

Browse files
Mr-Leshiystevenj
andauthored
remove alg field from the metadata (#252)
Co-authored-by: Steven Johnson <[email protected]>
1 parent 68a35f1 commit 6c1f9eb

File tree

6 files changed

+1
-89
lines changed

6 files changed

+1
-89
lines changed

rust/signed_doc/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ pub use catalyst_types::{
2222
};
2323
pub use content::Content;
2424
use coset::{CborSerializable, Header, TaggedCborSerializable};
25-
pub use metadata::{
26-
Algorithm, ContentEncoding, ContentType, DocumentRef, ExtraFields, Metadata, Section,
27-
};
25+
pub use metadata::{ContentEncoding, ContentType, DocumentRef, ExtraFields, Metadata, Section};
2826
use minicbor::{decode, encode, Decode, Decoder, Encode};
2927
pub use signature::{IdUri, Signatures};
3028

rust/signed_doc/src/metadata/algorithm.rs

-48
This file was deleted.

rust/signed_doc/src/metadata/mod.rs

-31
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
//! Catalyst Signed Document Metadata.
22
use std::fmt::{Display, Formatter};
33

4-
mod algorithm;
54
mod content_encoding;
65
mod content_type;
76
mod document_ref;
87
mod extra_fields;
98
mod section;
109
pub(crate) mod utils;
1110

12-
pub use algorithm::Algorithm;
1311
use catalyst_types::{
1412
problem_report::ProblemReport,
1513
uuid::{UuidV4, UuidV7},
@@ -42,8 +40,6 @@ pub struct Metadata(InnerMetadata);
4240
/// An actual representation of all metadata fields.
4341
#[derive(Clone, Debug, PartialEq, serde::Deserialize, Default)]
4442
pub(crate) struct InnerMetadata {
45-
/// Cryptographic Algorithm
46-
alg: Option<Algorithm>,
4743
/// Document Type `UUIDv4`.
4844
#[serde(rename = "type")]
4945
doc_type: Option<UuidV4>,
@@ -63,14 +59,6 @@ pub(crate) struct InnerMetadata {
6359
}
6460

6561
impl Metadata {
66-
/// Return Document Cryptographic Algorithm
67-
///
68-
/// # Errors
69-
/// - Missing 'alg' field.
70-
pub fn algorithm(&self) -> anyhow::Result<Algorithm> {
71-
self.0.alg.ok_or(anyhow::anyhow!("Missing 'alg' field"))
72-
}
73-
7462
/// Return Document Type `UUIDv4`.
7563
///
7664
/// # Errors
@@ -121,9 +109,6 @@ impl Metadata {
121109

122110
/// Build `Metadata` object from the metadata fields, doing all necessary validation.
123111
pub(crate) fn from_metadata_fields(metadata: InnerMetadata, report: &ProblemReport) -> Self {
124-
if metadata.alg.is_none() {
125-
report.missing_field("alg", "Missing alg field in COSE protected header");
126-
}
127112
if metadata.doc_type.is_none() {
128113
report.missing_field("type", "Missing type field in COSE protected header");
129114
}
@@ -181,20 +166,6 @@ impl InnerMetadata {
181166
..Self::default()
182167
};
183168

184-
if let Some(coset::RegisteredLabelWithPrivate::Assigned(alg)) = protected.header.alg {
185-
match Algorithm::try_from(alg) {
186-
Ok(alg) => metadata.alg = Some(alg),
187-
Err(e) => {
188-
report.conversion_error(
189-
"COSE protected header algorithm",
190-
&format!("{alg:?}"),
191-
&format!("Expected Algorithm: {e}"),
192-
&format!("{COSE_DECODING_CONTEXT}, Algorithm"),
193-
);
194-
},
195-
}
196-
}
197-
198169
if let Some(value) = protected.header.content_type.as_ref() {
199170
match ContentType::try_from(value) {
200171
Ok(ct) => metadata.content_type = Some(ct),
@@ -260,7 +231,6 @@ impl Display for Metadata {
260231
writeln!(f, " type: {:?},", self.0.doc_type)?;
261232
writeln!(f, " id: {:?},", self.0.id)?;
262233
writeln!(f, " ver: {:?},", self.0.ver)?;
263-
writeln!(f, " alg: {:?},", self.0.alg)?;
264234
writeln!(f, " content_type: {:?}", self.0.content_type)?;
265235
writeln!(f, " content_encoding: {:?}", self.0.content_encoding)?;
266236
writeln!(f, " additional_fields: {:?},", self.0.extra)?;
@@ -273,7 +243,6 @@ impl TryFrom<&Metadata> for coset::Header {
273243

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

279248
if let Some(content_encoding) = meta.content_encoding() {

rust/signed_doc/tests/comment.rs

-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ async fn test_valid_comment_doc() {
1313

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

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

102100
let uuid_v7 = UuidV7::new();
103101
let (doc, ..) = common::create_dummy_signed_doc(Some(serde_json::json!({
104-
"alg": Algorithm::EdDSA.to_string(),
105102
"content-type": ContentType::Json.to_string(),
106103
"content-encoding": ContentEncoding::Brotli.to_string(),
107104
"type": doc_types::COMMENT_DOCUMENT_UUID_TYPE,

rust/signed_doc/tests/common/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub fn test_metadata() -> (UuidV7, UuidV4, serde_json::Value) {
99
let uuid_v4 = UuidV4::new();
1010

1111
let metadata_fields = serde_json::json!({
12-
"alg": Algorithm::EdDSA.to_string(),
1312
"content-type": ContentType::Json.to_string(),
1413
"content-encoding": ContentEncoding::Brotli.to_string(),
1514
"type": uuid_v4.to_string(),

rust/signed_doc/tests/proposal.rs

-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ async fn test_valid_proposal_doc() {
1111

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

3938
let uuid_v7 = UuidV7::new();
4039
let (doc, ..) = common::create_dummy_signed_doc(Some(serde_json::json!({
41-
"alg": Algorithm::EdDSA.to_string(),
4240
"content-type": ContentType::Json.to_string(),
4341
"content-encoding": ContentEncoding::Brotli.to_string(),
4442
"type": doc_types::PROPOSAL_DOCUMENT_UUID_TYPE,
@@ -61,7 +59,6 @@ async fn test_valid_proposal_doc_with_empty_provider() {
6159
async fn test_invalid_proposal_doc() {
6260
let uuid_v7 = UuidV7::new();
6361
let (doc, ..) = common::create_dummy_signed_doc(Some(serde_json::json!({
64-
"alg": Algorithm::EdDSA.to_string(),
6562
"content-type": ContentType::Json.to_string(),
6663
"content-encoding": ContentEncoding::Brotli.to_string(),
6764
"type": doc_types::PROPOSAL_DOCUMENT_UUID_TYPE,

0 commit comments

Comments
 (0)