Skip to content

Commit 14b48a1

Browse files
committed
fix(signed-doc): remove problem report in encoder
Signed-off-by: bkioshn <bkioshn@gmail.com>
1 parent 98656f9 commit 14b48a1

File tree

3 files changed

+23
-63
lines changed

3 files changed

+23
-63
lines changed

rust/signed_doc/src/metadata/document_refs/doc_locator.rs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,32 +114,14 @@ impl Decode<'_, ProblemReport> for DocLocator {
114114
}
115115
}
116116

117-
impl Encode<ProblemReport> for DocLocator {
117+
impl Encode<()> for DocLocator {
118118
fn encode<W: minicbor::encode::Write>(
119-
&self, e: &mut minicbor::Encoder<W>, report: &mut ProblemReport,
119+
&self, e: &mut minicbor::Encoder<W>, _: &mut (),
120120
) -> Result<(), minicbor::encode::Error<W::Error>> {
121-
const CONTEXT: &str = "DocLocator encoding";
122-
e.map(DOC_LOC_MAP_ITEM).map_err(|_| {
123-
report.invalid_encoding(
124-
"Map",
125-
"Invalid length",
126-
&DOC_LOC_MAP_ITEM.to_string(),
127-
CONTEXT,
128-
);
129-
minicbor::encode::Error::message(format!("{CONTEXT}: Unable to encode map length"))
130-
})?;
131-
e.str(CID_MAP_KEY).map_err(|_| {
132-
report.invalid_encoding("Key", "Invalid string", " String", CONTEXT);
133-
minicbor::encode::Error::message(format!("{CONTEXT}: Unable to encode key"))
134-
})?;
135-
e.tag(minicbor::data::Tag::new(CID_TAG)).map_err(|_| {
136-
report.invalid_encoding("CBOR tag", "Invalid tag", &CID_TAG.to_string(), CONTEXT);
137-
minicbor::encode::Error::message(format!("{CONTEXT}: Unable to encode CBOR tag"))
138-
})?;
139-
e.bytes(&self.0).map_err(|_| {
140-
report.invalid_encoding("CID", "Invalid bytes", "Valid CBOR byte", CONTEXT);
141-
minicbor::encode::Error::message(format!("{CONTEXT}: Unable to encode CID bytes"))
142-
})?;
121+
e.map(DOC_LOC_MAP_ITEM)?;
122+
e.str(CID_MAP_KEY)?;
123+
e.tag(minicbor::data::Tag::new(CID_TAG))?;
124+
e.bytes(&self.0)?;
143125
Ok(())
144126
}
145127
}
@@ -157,7 +139,7 @@ mod tests {
157139
let locator = DocLocator(vec![1, 2, 3, 4]);
158140
let mut buffer = Vec::new();
159141
let mut encoder = Encoder::new(&mut buffer);
160-
locator.encode(&mut encoder, &mut report).unwrap();
142+
locator.encode(&mut encoder, &mut ()).unwrap();
161143
let mut decoder = Decoder::new(&buffer);
162144
let decoded_doc_loc = DocLocator::decode(&mut decoder, &mut report).unwrap();
163145
assert_eq!(locator, decoded_doc_loc);
@@ -170,7 +152,7 @@ mod tests {
170152
let locator = DocLocator(vec![]);
171153
let mut buffer = Vec::new();
172154
let mut encoder = Encoder::new(&mut buffer);
173-
locator.encode(&mut encoder, &mut report).unwrap();
155+
locator.encode(&mut encoder, &mut ()).unwrap();
174156
let mut decoder = Decoder::new(&buffer);
175157
let decoded_doc_loc = DocLocator::decode(&mut decoder, &mut report).unwrap();
176158
assert_eq!(locator, decoded_doc_loc);

rust/signed_doc/src/metadata/document_refs/doc_ref.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
33
use std::fmt::Display;
44

5-
use catalyst_types::{
6-
problem_report::ProblemReport,
7-
uuid::{CborContext, UuidV7},
8-
};
5+
use catalyst_types::uuid::{CborContext, UuidV7};
96
use coset::cbor::Value;
107
use minicbor::{Decode, Decoder, Encode};
118

@@ -135,29 +132,14 @@ impl Decode<'_, DecodeContext<'_>> for DocumentRef {
135132
}
136133
}
137134

138-
impl Encode<ProblemReport> for DocumentRef {
135+
impl Encode<()> for DocumentRef {
139136
fn encode<W: minicbor::encode::Write>(
140-
&self, e: &mut minicbor::Encoder<W>, report: &mut ProblemReport,
137+
&self, e: &mut minicbor::Encoder<W>, ctx: &mut (),
141138
) -> Result<(), minicbor::encode::Error<W::Error>> {
142-
const CONTEXT: &str = "DocumentRef encoding";
143139
e.array(DOC_REF_ARR_ITEM)?;
144-
self.id.encode(e, &mut CborContext::Tagged).map_err(|_| {
145-
report.invalid_encoding("ID", &self.id.to_string(), "Valid UUIDv7", CONTEXT);
146-
minicbor::encode::Error::message(format!("{CONTEXT}: ID UUIDv7 encoding failed"))
147-
})?;
148-
self.ver.encode(e, &mut CborContext::Tagged).map_err(|_| {
149-
report.invalid_encoding("Ver", &self.id.to_string(), "Valid UUIDv7", CONTEXT);
150-
minicbor::encode::Error::message(format!("{CONTEXT}: Ver UUIDv7 encoding failed"))
151-
})?;
152-
self.doc_locator.encode(e, report).map_err(|e| {
153-
report.invalid_encoding(
154-
"Doc locator",
155-
&self.doc_locator.to_string(),
156-
"Valid doc locator",
157-
CONTEXT,
158-
);
159-
e.with_message("{CONTEXT}: Failed to encode doc locator")
160-
})?;
140+
self.id.encode(e, &mut CborContext::Tagged)?;
141+
self.ver.encode(e, &mut CborContext::Tagged)?;
142+
self.doc_locator.encode(e, ctx)?;
161143
Ok(())
162144
}
163145
}

rust/signed_doc/src/metadata/document_refs/mod.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,25 @@ impl Decode<'_, DecodeContext<'_>> for DocumentRefs {
147147
}
148148
}
149149

150-
impl Encode<ProblemReport> for DocumentRefs {
150+
impl Encode<()> for DocumentRefs {
151151
fn encode<W: minicbor::encode::Write>(
152-
&self, e: &mut minicbor::Encoder<W>, report: &mut ProblemReport,
152+
&self, e: &mut minicbor::Encoder<W>, ctx: &mut (),
153153
) -> Result<(), minicbor::encode::Error<W::Error>> {
154154
const CONTEXT: &str = "DocumentRefs encoding";
155155
if self.0.is_empty() {
156-
report.invalid_value(
157-
"DocumentRefs",
158-
"empty",
159-
"DocumentRefs cannot be empty",
160-
CONTEXT,
161-
);
162156
return Err(minicbor::encode::Error::message(format!(
163157
"{CONTEXT}: DocumentRefs cannot be empty"
164158
)));
165159
}
166-
e.array(self.0.len().try_into().map_err(|_| {
167-
report.invalid_encoding("Array", "Invalid array", "Valid array", CONTEXT);
168-
minicbor::encode::Error::message(format!("{CONTEXT}, unable to encode array length"))
169-
})?)?;
160+
e.array(
161+
self.0
162+
.len()
163+
.try_into()
164+
.map_err(|e| minicbor::encode::Error::message(format!("{CONTEXT}, {e}")))?,
165+
)?;
170166

171167
for doc_ref in &self.0 {
172-
doc_ref.encode(e, report)?;
168+
doc_ref.encode(e, ctx)?;
173169
}
174170
Ok(())
175171
}

0 commit comments

Comments
 (0)