Skip to content

Commit 8589577

Browse files
committed
fix
1 parent 256c3aa commit 8589577

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

rust/signed_doc/src/validator/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn proposal_rule() -> Rules {
5858
collaborators: CollaboratorsRule::NotSpecified,
5959
content: ContentRule::NotNil,
6060
kid: SignatureKidRule {
61-
allowed_roles: vec![RoleId::Proposer],
61+
allowed_roles: [RoleId::Proposer].into_iter().collect(),
6262
},
6363
signature: SignatureRule { mutlisig: false },
6464
original_author: OriginalAuthorRule,
@@ -105,7 +105,7 @@ fn proposal_comment_rule() -> Rules {
105105
collaborators: CollaboratorsRule::NotSpecified,
106106
content: ContentRule::NotNil,
107107
kid: SignatureKidRule {
108-
allowed_roles: vec![RoleId::Role0],
108+
allowed_roles: [RoleId::Role0].into_iter().collect(),
109109
},
110110
signature: SignatureRule { mutlisig: false },
111111
original_author: OriginalAuthorRule,
@@ -158,7 +158,7 @@ fn proposal_submission_action_rule() -> Rules {
158158
collaborators: CollaboratorsRule::NotSpecified,
159159
content: ContentRule::StaticSchema(ContentSchema::Json(proposal_action_json_schema)),
160160
kid: SignatureKidRule {
161-
allowed_roles: vec![RoleId::Proposer],
161+
allowed_roles: [RoleId::Proposer].into_iter().collect(),
162162
},
163163
signature: SignatureRule { mutlisig: false },
164164
original_author: OriginalAuthorRule,

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Catalyst Signed Document COSE signature `kid` (Catalyst Id) role validation
22
3+
use std::collections::HashSet;
4+
35
use catalyst_signed_doc_spec::signers::roles::{AdminRole, Roles, UserRole};
46
use catalyst_types::catalyst_id::role_index::RoleId;
57

@@ -9,13 +11,13 @@ use crate::CatalystSignedDocument;
911
#[derive(Debug)]
1012
pub(crate) struct SignatureKidRule {
1113
/// expected `RoleId` values for the `kid` field
12-
pub(crate) allowed_roles: Vec<RoleId>,
14+
pub(crate) allowed_roles: HashSet<RoleId>,
1315
}
1416

1517
impl SignatureKidRule {
1618
/// Generating `SignatureKidRule` from specs
1719
pub(crate) fn new(spec: &Roles) -> anyhow::Result<Self> {
18-
let allowed_roles: Vec<_> = spec
20+
let allowed_roles: HashSet<_> = spec
1921
.user
2022
.iter()
2123
.map(|v| {
@@ -92,7 +94,9 @@ mod tests {
9294
#[tokio::test]
9395
async fn signature_kid_rule_test() {
9496
let mut rule = SignatureKidRule {
95-
allowed_roles: vec![RoleId::Role0, RoleId::DelegatedRepresentative],
97+
allowed_roles: [RoleId::Role0, RoleId::DelegatedRepresentative]
98+
.into_iter()
99+
.collect(),
96100
};
97101

98102
let sk = ed25519_dalek::SigningKey::generate(&mut rand::rngs::OsRng);
@@ -111,7 +115,7 @@ mod tests {
111115

112116
assert!(rule.check(&doc).await.unwrap());
113117

114-
rule.allowed_roles = vec![RoleId::Proposer];
118+
rule.allowed_roles = [RoleId::Proposer].into_iter().collect();
115119
assert!(!rule.check(&doc).await.unwrap());
116120
}
117121
}

0 commit comments

Comments
 (0)