Skip to content

Commit 93644b3

Browse files
committed
chore: check version
1 parent 172559d commit 93644b3

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub(crate) struct IdRule;

rust/signed_doc/src/validator/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! Catalyst Signed Documents validation logic
22
3-
pub(crate) mod ver;
3+
pub(crate) mod id;
44
pub(crate) mod json_schema;
55
pub(crate) mod rules;
66
pub(crate) mod utils;
7+
pub(crate) mod ver;
78

89
use std::{
910
collections::HashMap,
@@ -22,7 +23,11 @@ use crate::{
2223
doc_types::{
2324
BRAND_PARAMETERS, CAMPAIGN_PARAMETERS, CATEGORY_PARAMETERS, PROPOSAL, PROPOSAL_COMMENT,
2425
PROPOSAL_COMMENT_FORM_TEMPLATE, PROPOSAL_FORM_TEMPLATE, PROPOSAL_SUBMISSION_ACTION,
25-
}, metadata::DocType, providers::{CatalystSignedDocumentProvider, VerifyingKeyProvider}, signature::{tbs_data, Signature}, CatalystSignedDocument, ContentEncoding, ContentType
26+
},
27+
metadata::DocType,
28+
providers::{CatalystSignedDocumentProvider, VerifyingKeyProvider},
29+
signature::{tbs_data, Signature},
30+
CatalystSignedDocument, ContentEncoding, ContentType,
2631
};
2732

2833
/// A table representing a full set or validation rules per document id.

rust/signed_doc/src/validator/rules/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
44
use futures::FutureExt;
55

6-
use crate::{providers::CatalystSignedDocumentProvider, validator::id_and_ver::{IdRule, VerRule}, CatalystSignedDocument};
6+
use crate::{
7+
providers::CatalystSignedDocumentProvider,
8+
validator::{id::IdRule, ver::VerRule},
9+
CatalystSignedDocument,
10+
};
711

812
mod content_encoding;
913
mod content_type;
Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,40 @@
11
//! Validator for Signed Document Version
22
3-
use std::time::{Duration, SystemTime};
4-
5-
use crate::{providers::CatalystSignedDocumentProvider, CatalystSignedDocument};
3+
use crate::CatalystSignedDocument;
64

75
pub(crate) struct VerRule;
86

97
impl VerRule {
10-
pub(crate) fn check<Provider>(
8+
pub(crate) fn check(
119
&self,
1210
doc: &CatalystSignedDocument,
13-
_provider: &Provider,
14-
) -> anyhow::Result<bool>
15-
where
16-
Provider: CatalystSignedDocumentProvider,
17-
{
18-
let id = doc.doc_id().ok();
19-
let ver = doc.doc_ver().ok();
20-
21-
if id.is_none() {
11+
) -> anyhow::Result<bool> {
12+
let Ok(id) = doc.doc_id() else {
2213
doc.report().missing_field(
2314
"id",
2415
"Can't get a document id during the validation process",
2516
);
26-
}
27-
if ver.is_none() {
17+
return Ok(false);
18+
};
19+
20+
let Ok(ver) = doc.doc_ver() else {
2821
doc.report().missing_field(
2922
"ver",
3023
"Can't get a document ver during the validation process",
3124
);
32-
}
25+
return Ok(false);
26+
};
3327

34-
match (id, ver) {
35-
(Some(id), Some(ver)) => {
36-
if ver < id {
37-
doc.report().invalid_value(
38-
"ver",
39-
&ver.to_string(),
40-
"ver < id",
41-
&format!(
42-
"Document Version {ver} cannot be smaller than Document ID {id}"
43-
),
44-
);
45-
Ok(false)
46-
} else {
47-
Ok(true)
48-
}
49-
}
50-
_ => Ok(false),
28+
if ver < id {
29+
doc.report().invalid_value(
30+
"ver",
31+
&ver.to_string(),
32+
"ver < id",
33+
&format!("Document Version {ver} cannot be smaller than Document ID {id}"),
34+
);
35+
Ok(false)
36+
} else {
37+
Ok(true)
5138
}
5239
}
5340
}

0 commit comments

Comments
 (0)