Skip to content

Commit 99aebda

Browse files
committed
fix suggestions
1 parent f930f44 commit 99aebda

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed

rust/rbac-registration/src/cardano/cip509/cip509.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl Cip509 {
240240
/// Would return only signing public keys for the present certificates,
241241
/// if certificate marked as deleted or undefined it would be skipped.
242242
#[must_use]
243-
pub fn signing_pk_for_role(
243+
pub fn signing_public_key_for_role(
244244
&self,
245245
role: RoleId,
246246
) -> Option<VerifyingKey> {

rust/rbac-registration/src/cardano/cip509/types/cert_or_pk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum CertOrPk {
2121

2222
impl CertOrPk {
2323
/// Extract public key from the given certificate or public key.
24-
pub(crate) fn extract_pk(&self) -> Option<VerifyingKey> {
24+
pub(crate) fn extract_public_key(&self) -> Option<VerifyingKey> {
2525
match self {
2626
CertOrPk::X509(Some(x509)) => extract_key::x509_key(x509).ok(),
2727
CertOrPk::C509(Some(c509)) => extract_key::c509_key(c509).ok(),

rust/rbac-registration/src/cardano/cip509/utils/cip134_uri_set.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,16 @@ impl Cip0134UriSet {
9292
pub(crate) fn role_uris(
9393
&self,
9494
role: usize,
95-
) -> HashSet<Cip0134Uri> {
96-
let mut result = HashSet::new();
97-
98-
if let Some(uris) = self.x_uris().get(&role) {
99-
result.extend(uris.iter().cloned());
100-
}
101-
if let Some(uris) = self.c_uris().get(&role) {
102-
result.extend(uris.iter().cloned());
103-
}
104-
105-
result
95+
) -> impl Iterator<Item = &Cip0134Uri> {
96+
let x_iter = self
97+
.x_uris()
98+
.get(&role)
99+
.map_or_else(|| [].iter(), |uris| uris.iter());
100+
let c_iter = self
101+
.c_uris()
102+
.get(&role)
103+
.map_or_else(|| [].iter(), |uris| uris.iter());
104+
x_iter.chain(c_iter)
106105
}
107106

108107
/// Returns a set of stake addresses by the given role.
@@ -112,7 +111,6 @@ impl Cip0134UriSet {
112111
role: usize,
113112
) -> HashSet<StakeAddress> {
114113
self.role_uris(role)
115-
.iter()
116114
.filter_map(|uri| {
117115
match uri.address() {
118116
Address::Stake(a) => Some(a.clone().into()),
@@ -401,7 +399,7 @@ mod tests {
401399
let set = cip509.certificate_uris().unwrap();
402400
assert!(!set.is_empty());
403401
assert!(set.c_uris().is_empty());
404-
assert_eq!(set.role_uris(0).len(), 1);
402+
assert_eq!(set.role_uris(0).count(), 1);
405403
assert_eq!(set.role_stake_addresses(0).len(), 1);
406404
assert_eq!(set.stake_addresses().len(), 1);
407405

rust/rbac-registration/src/cardano/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub trait RbacChainsState {
3131

3232
/// Returns a corresponding to the RBAC chain's Catalyst ID corresponding by the given
3333
/// signing public key.
34-
fn chain_catalyst_id_from_signing_pk(
34+
fn chain_catalyst_id_from_signing_public_key(
3535
&self,
3636
key: &VerifyingKey,
3737
) -> impl Future<Output = anyhow::Result<Option<CatalystId>>> + Send;
@@ -40,6 +40,6 @@ pub trait RbacChainsState {
4040
/// RBAC chain's by the given `CatalystId`.
4141
fn take_stake_address_from_chains(
4242
&mut self,
43-
addresses: impl Iterator<Item = StakeAddress> + Send,
43+
addresses: impl IntoIterator<Item = StakeAddress> + Send,
4444
) -> impl Future<Output = anyhow::Result<()>> + Send;
4545
}

rust/rbac-registration/src/registration/cardano/mod.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ impl RegistrationChain {
7171
);
7272
}
7373

74-
check_signing_pk(cat_id, cip509, state).await?;
74+
check_signing_public_key(cat_id, cip509, state).await?;
7575
}
7676

7777
if cip509.report().is_problematic() {
7878
return Ok(None);
7979
}
8080

8181
state
82-
.take_stake_address_from_chains(cip509.stake_addresses().into_iter())
82+
.take_stake_address_from_chains(cip509.stake_addresses())
8383
.await?;
8484

8585
Ok(Some(new_chain))
@@ -133,7 +133,7 @@ impl RegistrationChain {
133133
}
134134
}
135135

136-
check_signing_pk(self.catalyst_id(), cip509, state).await?;
136+
check_signing_public_key(self.catalyst_id(), cip509, state).await?;
137137

138138
if cip509.report().is_problematic() {
139139
Ok(None)
@@ -151,7 +151,7 @@ impl RegistrationChain {
151151
&self,
152152
cip509: &Cip509,
153153
) -> Option<Self> {
154-
let latest_signing_pk = self.get_latest_signing_pk_for_role(RoleId::Role0);
154+
let latest_signing_pk = self.get_latest_signing_public_key_for_role(RoleId::Role0);
155155
let new_inner = if let Some((signing_pk, _)) = latest_signing_pk {
156156
self.inner.update(cip509, signing_pk)?
157157
} else {
@@ -247,11 +247,11 @@ impl RegistrationChain {
247247
/// Get the latest signing public key for a role.
248248
/// Returns the public key and the rotation,`None` if not found.
249249
#[must_use]
250-
pub fn get_latest_signing_pk_for_role(
250+
pub fn get_latest_signing_public_key_for_role(
251251
&self,
252252
role: RoleId,
253253
) -> Option<(VerifyingKey, KeyRotation)> {
254-
self.inner.get_latest_signing_pk_for_role(role)
254+
self.inner.get_latest_signing_public_key_for_role(role)
255255
}
256256

257257
/// Get the latest encryption public key for a role.
@@ -261,7 +261,7 @@ impl RegistrationChain {
261261
&self,
262262
role: RoleId,
263263
) -> Option<(VerifyingKey, KeyRotation)> {
264-
self.inner.get_latest_encryption_pk_for_role(role)
264+
self.inner.get_latest_encryption_public_key_for_role(role)
265265
}
266266

267267
/// Get signing public key for a role with given rotation.
@@ -274,7 +274,7 @@ impl RegistrationChain {
274274
) -> Option<VerifyingKey> {
275275
self.inner.role_data_record.get(role).and_then(|rdr| {
276276
rdr.signing_key_from_rotation(rotation)
277-
.and_then(CertOrPk::extract_pk)
277+
.and_then(CertOrPk::extract_public_key)
278278
})
279279
}
280280

@@ -288,7 +288,7 @@ impl RegistrationChain {
288288
) -> Option<VerifyingKey> {
289289
self.inner.role_data_record.get(role).and_then(|rdr| {
290290
rdr.encryption_key_from_rotation(rotation)
291-
.and_then(CertOrPk::extract_pk)
291+
.and_then(CertOrPk::extract_public_key)
292292
})
293293
}
294294

@@ -398,7 +398,7 @@ impl RegistrationChainInner {
398398
return None;
399399
};
400400

401-
let Some(registration) = cip509.metadata().cloned() else {
401+
let Some(registration) = cip509.metadata() else {
402402
cip509.report().missing_field("metadata", context);
403403
return None;
404404
};
@@ -408,7 +408,7 @@ impl RegistrationChainInner {
408408
let mut role_data_record = HashMap::new();
409409
let point_tx_idx = cip509.origin().clone();
410410
update_role_data(
411-
&registration,
411+
registration,
412412
&mut role_data_history,
413413
&mut role_data_record,
414414
&point_tx_idx,
@@ -423,7 +423,7 @@ impl RegistrationChainInner {
423423
let Some(signing_pk) = role0_data
424424
.signing_keys()
425425
.last()
426-
.and_then(|key| key.data().extract_pk())
426+
.and_then(|key| key.data().extract_public_key())
427427
else {
428428
cip509
429429
.report()
@@ -643,31 +643,31 @@ impl RegistrationChainInner {
643643
/// Get the latest signing public key for a role.
644644
/// Returns the public key and the rotation,`None` if not found.
645645
#[must_use]
646-
pub fn get_latest_signing_pk_for_role(
646+
pub fn get_latest_signing_public_key_for_role(
647647
&self,
648648
role: RoleId,
649649
) -> Option<(VerifyingKey, KeyRotation)> {
650650
self.role_data_record.get(&role).and_then(|rdr| {
651651
rdr.signing_keys().last().and_then(|key| {
652652
let rotation = KeyRotation::from_latest_rotation(rdr.signing_keys());
653653

654-
key.data().extract_pk().map(|pk| (pk, rotation))
654+
key.data().extract_public_key().map(|pk| (pk, rotation))
655655
})
656656
})
657657
}
658658

659659
/// Get the latest encryption public key for a role.
660660
/// Returns the public key and the rotation, `None` if not found.
661661
#[must_use]
662-
pub fn get_latest_encryption_pk_for_role(
662+
pub fn get_latest_encryption_public_key_for_role(
663663
&self,
664664
role: RoleId,
665665
) -> Option<(VerifyingKey, KeyRotation)> {
666666
self.role_data_record.get(&role).and_then(|rdr| {
667667
rdr.encryption_keys().last().and_then(|key| {
668668
let rotation = KeyRotation::from_latest_rotation(rdr.encryption_keys());
669669

670-
key.data().extract_pk().map(|pk| (pk, rotation))
670+
key.data().extract_public_key().map(|pk| (pk, rotation))
671671
})
672672
})
673673
}
@@ -731,7 +731,7 @@ fn check_validation_signature(
731731

732732
/// Checks that a new registration doesn't contain a signing key that was used by any
733733
/// other chain.
734-
async fn check_signing_pk<State>(
734+
async fn check_signing_public_key<State>(
735735
cat_id: &CatalystId,
736736
cip509: &Cip509,
737737
state: &State,
@@ -740,8 +740,10 @@ where
740740
State: RbacChainsState,
741741
{
742742
for role in cip509.all_roles() {
743-
if let Some(key) = cip509.signing_pk_for_role(role)
744-
&& let Some(previous) = state.chain_catalyst_id_from_signing_pk(&key).await?
743+
if let Some(key) = cip509.signing_public_key_for_role(role)
744+
&& let Some(previous) = state
745+
.chain_catalyst_id_from_signing_public_key(&key)
746+
.await?
745747
&& &previous != cat_id
746748
{
747749
cip509.report().functional_validation(
@@ -835,7 +837,7 @@ mod test {
835837
assert_eq!(role_0_data.extended_data().len(), 2);
836838

837839
let (_k, r) = update
838-
.get_latest_signing_pk_for_role(RoleId::Role0)
840+
.get_latest_signing_public_key_for_role(RoleId::Role0)
839841
.unwrap();
840842
assert_eq!(r, KeyRotation::from(1));
841843
assert!(

0 commit comments

Comments
 (0)