Skip to content

Commit ad6828b

Browse files
Pass the (sub)net parameter to IdUri constructor (#259)
1 parent 31b258a commit ad6828b

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl Cip509 {
161161
validate_stake_public_key(txn, cip509.certificate_uris(), &cip509.report);
162162
}
163163
if let Some(metadata) = &cip509.metadata {
164-
cip509.catalyst_id = validate_role_data(metadata, &cip509.report);
164+
cip509.catalyst_id = validate_role_data(metadata, block.network(), &cip509.report);
165165
}
166166

167167
Ok(Some(cip509))

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use std::borrow::Cow;
88

99
use c509_certificate::c509::C509;
10-
use cardano_blockchain_types::{TxnWitness, VKeyHash};
10+
use cardano_blockchain_types::{Network, TxnWitness, VKeyHash};
1111
use catalyst_types::{
1212
hashes::{Blake2b128Hash, Blake2b256Hash},
1313
id_uri::IdUri,
@@ -164,7 +164,9 @@ fn extract_stake_addresses(uris: Option<&Cip0134UriSet>) -> Vec<VKeyHash> {
164164

165165
/// Checks the role data.
166166
#[allow(clippy::similar_names)]
167-
pub fn validate_role_data(metadata: &Cip509RbacMetadata, report: &ProblemReport) -> Option<IdUri> {
167+
pub fn validate_role_data(
168+
metadata: &Cip509RbacMetadata, subnet: Network, report: &ProblemReport,
169+
) -> Option<IdUri> {
168170
let context = "Role data validation";
169171

170172
// There should be some role data
@@ -235,7 +237,7 @@ pub fn validate_role_data(metadata: &Cip509RbacMetadata, report: &ProblemReport)
235237
let mut catalyst_id = None;
236238
for (number, data) in &metadata.role_data {
237239
if number == &RoleNumber::ROLE_0 {
238-
catalyst_id = validate_role_0(data, metadata, context, report);
240+
catalyst_id = validate_role_0(data, metadata, subnet, context, report);
239241
} else {
240242
if let Some(signing_key) = data.signing_key() {
241243
if signing_key.key_offset == 0 {
@@ -264,7 +266,8 @@ pub fn validate_role_data(metadata: &Cip509RbacMetadata, report: &ProblemReport)
264266

265267
/// Checks that the role 0 data is correct.
266268
fn validate_role_0(
267-
role: &RoleData, metadata: &Cip509RbacMetadata, context: &str, report: &ProblemReport,
269+
role: &RoleData, metadata: &Cip509RbacMetadata, subnet: Network, context: &str,
270+
report: &ProblemReport,
268271
) -> Option<IdUri> {
269272
if let Some(key) = role.encryption_key() {
270273
report.invalid_value(
@@ -296,7 +299,7 @@ fn validate_role_0(
296299
match metadata.x509_certs.first() {
297300
Some(X509DerCert::X509Cert(cert)) => {
298301
// All good: role 0 references a valid X509 certificate.
299-
catalyst_id = x509_cert_key(cert, context, report).map(|k| IdUri::new(network, None, k));
302+
catalyst_id = x509_cert_key(cert, context, report).map(|k| IdUri::new(network, Some(&subnet.to_string()), k));
300303
}
301304
Some(c) => report.other(&format!("Invalid X509 certificate value ({c:?}) for role 0 ({role:?})"), context),
302305
None => report.other("Role 0 reference X509 certificate at index 0, but there is no such certificate", context),
@@ -306,7 +309,7 @@ fn validate_role_0(
306309
match metadata.c509_certs.first() {
307310
Some(C509Cert::C509Certificate(cert)) => {
308311
// All good: role 0 references a valid C509 certificate.
309-
catalyst_id = c509_cert_key(cert, context, report).map(|k| IdUri::new(network, None, k));
312+
catalyst_id = c509_cert_key(cert, context, report).map(|k| IdUri::new(network, Some(&subnet.to_string()), k));
310313
}
311314
Some(c) => report.other(&format!("Invalid C509 certificate value ({c:?}) for role 0 ({role:?})"), context),
312315
None => report.other("Role 0 reference C509 certificate at index 0, but there is no such certificate", context),

0 commit comments

Comments
 (0)