Skip to content

Commit

Permalink
Move era validation outside of Cip0134UriList creation
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-tkach committed Dec 17, 2024
1 parent a13fa1b commit 3305775
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
18 changes: 5 additions & 13 deletions rust/rbac-registration/src/cardano/cip509/utils/cip134/uri_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<Self> {
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.
Expand Down Expand Up @@ -183,7 +175,7 @@ mod tests {
codec::utils::Nullable,
ledger::{
addresses::{Address, Network},
traverse::MultiEraBlock,
traverse::{MultiEraBlock, MultiEraTx},
},
};

Expand All @@ -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!(
Expand Down
14 changes: 5 additions & 9 deletions rust/rbac-registration/src/cardano/cip509/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,11 @@ pub(crate) fn validate_stake_public_key(
) -> Option<bool> {
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
Expand Down

0 comments on commit 3305775

Please sign in to comment.