Skip to content

Commit 25f8dc4

Browse files
committed
fix(sign-doc): name + const
Signed-off-by: bkioshn <[email protected]>
1 parent b352830 commit 25f8dc4

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

rust/signed_doc/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use error::CatalystSignedDocError;
2121
pub use metadata::{DocumentRef, ExtraFields, Metadata, UuidV4, UuidV7};
2222
pub use minicbor::{decode, encode, Decode, Decoder, Encode};
2323
pub use signature::{KidUri, Signatures};
24-
use utils::context::SignDocContext;
24+
use utils::context::DecodeSignDocCtx;
2525

2626
/// Inner type that holds the Catalyst Signed Document with parsing errors.
2727
#[derive(Debug, Clone)]
@@ -112,15 +112,15 @@ impl TryFrom<&[u8]> for CatalystSignedDocument {
112112

113113
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
114114
let error_report = ProblemReport::new("Catalyst Signed Document");
115-
let mut ctx = SignDocContext { error_report };
115+
let mut ctx = DecodeSignDocCtx { error_report };
116116
let decoded: CatalystSignedDocument = minicbor::decode_with(value, &mut ctx)
117117
.map_err(|e| CatalystSignedDocError::new(ctx.error_report, e.into()))?;
118118
Ok(decoded)
119119
}
120120
}
121121

122-
impl Decode<'_, SignDocContext> for CatalystSignedDocument {
123-
fn decode(d: &mut Decoder<'_>, ctx: &mut SignDocContext) -> Result<Self, decode::Error> {
122+
impl Decode<'_, DecodeSignDocCtx> for CatalystSignedDocument {
123+
fn decode(d: &mut Decoder<'_>, ctx: &mut DecodeSignDocCtx) -> Result<Self, decode::Error> {
124124
let start = d.position();
125125
d.skip()?;
126126
let end = d.position();

rust/signed_doc/src/metadata/extra_fields.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ impl ExtraFields {
164164
pub(crate) fn from_protected_header(
165165
protected: &ProtectedHeader, error_report: &ProblemReport,
166166
) -> anyhow::Result<Self> {
167-
let context = "COSE ProtectedHeader to ExtraFields";
167+
/// Context for error messages.
168+
const CONTEXT: &str = "COSE ProtectedHeader to ExtraFields";
168169

169170
let mut extra = ExtraFields::default();
170171

@@ -180,7 +181,7 @@ impl ExtraFields {
180181
"CBOR COSE protected header doc ref",
181182
&format!("{cbor_doc_ref:?}"),
182183
&format!("Expected DocumentRef: {e}"),
183-
&format!("{context}, DocumentRef"),
184+
&format!("{CONTEXT}, DocumentRef"),
184185
);
185186
},
186187
}
@@ -198,7 +199,7 @@ impl ExtraFields {
198199
"CBOR COSE protected header document template",
199200
&format!("{cbor_doc_template:?}"),
200201
&format!("Expected DocumentRef: {e}"),
201-
&format!("{context}, DocumentRef"),
202+
&format!("{CONTEXT}, DocumentRef"),
202203
);
203204
},
204205
}
@@ -216,7 +217,7 @@ impl ExtraFields {
216217
"CBOR COSE protected header document reply",
217218
&format!("{cbor_doc_reply:?}"),
218219
&format!("Expected DocumentRef: {e}"),
219-
&format!("{context}, DocumentRef"),
220+
&format!("{CONTEXT}, DocumentRef"),
220221
);
221222
},
222223
}
@@ -234,7 +235,7 @@ impl ExtraFields {
234235
"COSE protected header document section",
235236
&format!("{cbor_doc_section:?}"),
236237
&format!("Expected String: {e:?}"),
237-
&format!("{context}, converting document section to String"),
238+
&format!("{CONTEXT}, converting document section to String"),
238239
);
239240
},
240241
}
@@ -256,7 +257,7 @@ impl ExtraFields {
256257
&format!("COSE protected header collaborator index {ids}"),
257258
&format!("{collaborator:?}"),
258259
&format!("Expected String: {e:?}"),
259-
&format!("{context}, converting collaborator to String"),
260+
&format!("{CONTEXT}, converting collaborator to String"),
260261
);
261262
},
262263
}
@@ -268,7 +269,7 @@ impl ExtraFields {
268269
"CBOR COSE protected header collaborators",
269270
&format!("{cbor_doc_collabs:?}"),
270271
&format!("Expected Array: {e:?}"),
271-
&format!("{context}, converting collaborators to Array"),
272+
&format!("{CONTEXT}, converting collaborators to Array"),
272273
);
273274
},
274275
}
@@ -286,7 +287,7 @@ impl ExtraFields {
286287
"CBOR COSE protected header brand ID",
287288
&format!("{cbor_doc_brand_id:?}"),
288289
&format!("Expected UUID: {e:?}"),
289-
&format!("{context}, decoding CBOR UUID for brand ID"),
290+
&format!("{CONTEXT}, decoding CBOR UUID for brand ID"),
290291
);
291292
},
292293
}
@@ -304,7 +305,7 @@ impl ExtraFields {
304305
"CBOR COSE protected header campaign ID",
305306
&format!("{cbor_doc_campaign_id:?}"),
306307
&format!("Expected UUID: {e:?}"),
307-
&format!("{context}, decoding CBOR UUID for campaign ID"),
308+
&format!("{CONTEXT}, decoding CBOR UUID for campaign ID"),
308309
);
309310
},
310311
}
@@ -322,7 +323,7 @@ impl ExtraFields {
322323
"CBOR COSE protected header election ID",
323324
&format!("{cbor_doc_election_id:?}"),
324325
&format!("Expected UUID: {e:?}"),
325-
&format!("{context}, decoding CBOR UUID for election ID"),
326+
&format!("{CONTEXT}, decoding CBOR UUID for election ID"),
326327
);
327328
},
328329
}
@@ -340,7 +341,7 @@ impl ExtraFields {
340341
"CBOR COSE protected header category ID",
341342
&format!("{cbor_doc_category_id:?}"),
342343
&format!("Expected UUID: {e:?}"),
343-
&format!("{context}, decoding CBOR UUID for category ID"),
344+
&format!("{CONTEXT}, decoding CBOR UUID for category ID"),
344345
);
345346
},
346347
}

rust/signed_doc/src/utils/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use catalyst_types::problem_report::ProblemReport;
44

5-
/// Sign Document Context.
6-
pub(crate) struct SignDocContext {
5+
/// Sign Document Decoding Context.
6+
pub(crate) struct DecodeSignDocCtx {
77
/// Error Report.
88
pub(crate) error_report: ProblemReport,
99
}

0 commit comments

Comments
 (0)