From 3305775598bd930ede3d2583a57f27af86160945 Mon Sep 17 00:00:00 2001 From: Stanislav Tkach Date: Tue, 17 Dec 2024 12:00:00 +0100 Subject: [PATCH] Move era validation outside of Cip0134UriList creation --- .../cardano/cip509/utils/cip134/uri_list.rs | 18 +++++------------- .../src/cardano/cip509/validation.rs | 14 +++++--------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/rust/rbac-registration/src/cardano/cip509/utils/cip134/uri_list.rs b/rust/rbac-registration/src/cardano/cip509/utils/cip134/uri_list.rs index f10711ff2..62219eabd 100644 --- a/rust/rbac-registration/src/cardano/cip509/utils/cip134/uri_list.rs +++ b/rust/rbac-registration/src/cardano/cip509/utils/cip134/uri_list.rs @@ -2,14 +2,12 @@ use std::sync::Arc; -use anyhow::{anyhow, Result}; use c509_certificate::{ extensions::{alt_name::GeneralNamesOrText, extension::ExtensionValue}, general_names::general_name::{GeneralNameTypeRegistry, GeneralNameValue}, C509ExtensionType, }; use der_parser::der::parse_der_sequence; -use pallas::ledger::traverse::MultiEraTx; use tracing::debug; use x509_cert::der::{oid::db::rfc5912::ID_CE_SUBJECT_ALT_NAME, Decode}; @@ -38,19 +36,13 @@ pub struct Cip0134UriList { impl Cip0134UriList { /// Creates a new `Cip0134UriList` instance from the given `Cip509`. - /// - /// # Errors - /// - Unsupported transaction era. - pub fn new(cip509: &Cip509, tx: &MultiEraTx) -> Result { - if !matches!(tx, MultiEraTx::Conway(_)) { - return Err(anyhow!("Unsupported transaction era ({})", tx.era())); - } - + #[must_use] + pub fn new(cip509: &Cip509) -> Self { let metadata = &cip509.x509_chunks.0; let mut uris = process_x509_certificates(metadata); uris.extend(process_c509_certificates(metadata)); - Ok(Self { uris: uris.into() }) + Self { uris: uris.into() } } /// Returns an iterator over the contained Cip0134 URIs. @@ -183,7 +175,7 @@ mod tests { codec::utils::Nullable, ledger::{ addresses::{Address, Network}, - traverse::MultiEraBlock, + traverse::{MultiEraBlock, MultiEraTx}, }, }; @@ -202,7 +194,7 @@ mod tests { let tx = &block.txs()[3]; let cip509 = cip509(tx); - let list = Cip0134UriList::new(&cip509, tx).unwrap(); + let list = Cip0134UriList::new(&cip509); assert_eq!(list.as_slice().len(), 1); // cSpell:disable assert_eq!( diff --git a/rust/rbac-registration/src/cardano/cip509/validation.rs b/rust/rbac-registration/src/cardano/cip509/validation.rs index abab03575..e782b7326 100644 --- a/rust/rbac-registration/src/cardano/cip509/validation.rs +++ b/rust/rbac-registration/src/cardano/cip509/validation.rs @@ -104,15 +104,11 @@ pub(crate) fn validate_stake_public_key( ) -> Option { let function_name = "Validate Stake Public Key"; - let addresses = match Cip0134UriList::new(cip509, txn) { - Ok(a) => a, - Err(e) => { - validation_report.push(format!( - "{function_name}, Failed to extract CIP-0134 URIs: {e:?}" - )); - return None; - }, - }; + if !matches!(txn, MultiEraTx::Conway(_)) { + validation_report.push(format!("{function_name}, Unsupported transaction era")); + return None; + } + let addresses = Cip0134UriList::new(cip509); // Create TxWitness // Note that TxWitness designs to work with multiple transactions