Skip to content

Commit 2392ed5

Browse files
committed
wip(rust/signed_doc): implement verification method
* verify extra fields
1 parent bd4561d commit 2392ed5

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

rust/signed_doc/src/lib.rs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl CatalystSignedDocument {
112112
/// # Errors
113113
///
114114
/// Returns a report of verification failures and the source error.
115-
#[allow(clippy::indexing_slicing)]
115+
#[allow(clippy::indexing_slicing, clippy::too_many_lines)]
116116
pub fn verify<P>(&self, pk_getter: P) -> Result<(), CatalystSignedDocError>
117117
where P: Fn(&KidUri) -> VerifyingKey {
118118
let error_report = ProblemReport::new("Catalyst Signed Document Verification");
@@ -147,6 +147,70 @@ impl CatalystSignedDocument {
147147
);
148148
}
149149

150+
let extra = self.doc_meta();
151+
if let Some(doc_ref) = extra.doc_ref() {
152+
if !doc_ref.is_valid() {
153+
error_report.functional_validation(
154+
&format!("Document Reference {doc_ref:?} is invalid"),
155+
"During Document Reference UUID verification",
156+
);
157+
}
158+
}
159+
160+
if let Some(template) = extra.template() {
161+
if !template.is_valid() {
162+
error_report.functional_validation(
163+
&format!("Document Template {template:?} is invalid"),
164+
"During Document Template UUID verification",
165+
);
166+
}
167+
}
168+
169+
if let Some(reply) = extra.reply() {
170+
if !reply.is_valid() {
171+
error_report.functional_validation(
172+
&format!("Document Reply {reply:?} is invalid"),
173+
"During Document Reply UUID verification",
174+
);
175+
}
176+
}
177+
178+
if let Some(brand_id) = extra.brand_id() {
179+
if !brand_id.is_valid() {
180+
error_report.functional_validation(
181+
&format!("Document Brand ID {brand_id:?} is invalid"),
182+
"During Document Brand ID UUID verification",
183+
);
184+
}
185+
}
186+
187+
if let Some(campaign_id) = extra.campaign_id() {
188+
if !campaign_id.is_valid() {
189+
error_report.functional_validation(
190+
&format!("Document Campaign ID {campaign_id:?} is invalid"),
191+
"During Document Campaign ID UUID verification",
192+
);
193+
}
194+
}
195+
196+
if let Some(election_id) = extra.election_id() {
197+
if !election_id.is_valid() {
198+
error_report.functional_validation(
199+
&format!("Document Election ID {election_id:?} is invalid"),
200+
"During Document Election ID UUID verification",
201+
);
202+
}
203+
}
204+
205+
if let Some(category_id) = extra.category_id() {
206+
if !category_id.is_valid() {
207+
error_report.functional_validation(
208+
&format!("Document Category ID {category_id:?} is invalid"),
209+
"During Document Category ID UUID verification",
210+
);
211+
}
212+
}
213+
150214
match self.as_cose_sign() {
151215
Ok(cose_sign) => {
152216
let signatures = self.signatures().cose_signatures();

rust/signed_doc/src/metadata/document_ref.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ pub struct DocumentRef {
1313
pub ver: Option<UuidV7>,
1414
}
1515

16+
impl DocumentRef {
17+
/// Determine if internal `UUID`s are valid.
18+
#[must_use]
19+
pub fn is_valid(&self) -> bool {
20+
match self.ver {
21+
Some(ver) => self.id.is_valid() && ver.is_valid() && ver >= self.id,
22+
None => self.id.is_valid(),
23+
}
24+
}
25+
}
26+
1627
impl TryFrom<DocumentRef> for Value {
1728
type Error = anyhow::Error;
1829

0 commit comments

Comments
 (0)