Skip to content

Commit 29773a7

Browse files
Move era validation outside of Cip0134UriList creation
1 parent 28e9709 commit 29773a7

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

rust/rbac-registration/src/cardano/cip509/utils/cip134/uri_list.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
33
use std::sync::Arc;
44

5-
use anyhow::{anyhow, Result};
65
use c509_certificate::{
76
extensions::{alt_name::GeneralNamesOrText, extension::ExtensionValue},
87
general_names::general_name::{GeneralNameTypeRegistry, GeneralNameValue},
98
C509ExtensionType,
109
};
1110
use der_parser::der::parse_der_sequence;
12-
use pallas::ledger::traverse::MultiEraTx;
1311
use tracing::debug;
1412
use x509_cert::der::{oid::db::rfc5912::ID_CE_SUBJECT_ALT_NAME, Decode};
1513

@@ -38,19 +36,13 @@ pub struct Cip0134UriList {
3836

3937
impl Cip0134UriList {
4038
/// Creates a new `Cip0134UriList` instance from the given `Cip509`.
41-
///
42-
/// # Errors
43-
/// - Unsupported transaction era.
44-
pub fn new(cip509: &Cip509, tx: &MultiEraTx) -> Result<Self> {
45-
if !matches!(tx, MultiEraTx::Conway(_)) {
46-
return Err(anyhow!("Unsupported transaction era ({})", tx.era()));
47-
}
48-
39+
#[must_use]
40+
pub fn new(cip509: &Cip509) -> Self {
4941
let metadata = &cip509.x509_chunks.0;
5042
let mut uris = process_x509_certificates(metadata);
5143
uris.extend(process_c509_certificates(metadata));
5244

53-
Ok(Self { uris: uris.into() })
45+
Self { uris: uris.into() }
5446
}
5547

5648
/// Returns an iterator over the contained Cip0134 URIs.
@@ -183,7 +175,7 @@ mod tests {
183175
codec::utils::Nullable,
184176
ledger::{
185177
addresses::{Address, Network},
186-
traverse::MultiEraBlock,
178+
traverse::{MultiEraBlock, MultiEraTx},
187179
},
188180
};
189181

@@ -202,7 +194,7 @@ mod tests {
202194
let tx = &block.txs()[3];
203195
let cip509 = cip509(tx);
204196

205-
let list = Cip0134UriList::new(&cip509, tx).unwrap();
197+
let list = Cip0134UriList::new(&cip509);
206198
assert_eq!(list.as_slice().len(), 1);
207199
// cSpell:disable
208200
assert_eq!(

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,11 @@ pub(crate) fn validate_stake_public_key(
104104
) -> Option<bool> {
105105
let function_name = "Validate Stake Public Key";
106106

107-
let addresses = match Cip0134UriList::new(cip509, txn) {
108-
Ok(a) => a,
109-
Err(e) => {
110-
validation_report.push(format!(
111-
"{function_name}, Failed to extract CIP-0134 URIs: {e:?}"
112-
));
113-
return None;
114-
},
115-
};
107+
if !matches!(txn, MultiEraTx::Conway(_)) {
108+
validation_report.push(format!("{function_name}, Unsupported transaction era"));
109+
return None;
110+
}
111+
let addresses = Cip0134UriList::new(cip509);
116112

117113
// Create TxWitness
118114
// Note that TxWitness designs to work with multiple transactions

0 commit comments

Comments
 (0)