Skip to content

Commit d5a3e79

Browse files
committed
fix(rbac-registration): add structured error
Signed-off-by: bkioshn <[email protected]>
1 parent 1b69576 commit d5a3e79

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

rust/rbac-registration/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tracing = "0.1.40"
3030
ed25519-dalek = "2.1.1"
3131
uuid = "1.11.0"
3232
oid-registry = "0.7.1"
33+
thiserror = "2.0.11"
3334

3435
c509-certificate = { version = "0.0.3", path = "../c509-certificate" }
3536
pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ use anyhow::{anyhow, Context};
55
use c509_certificate::c509::C509;
66
use ed25519_dalek::{VerifyingKey, PUBLIC_KEY_LENGTH};
77
use oid_registry::{Oid, OID_SIG_ED25519};
8+
use thiserror::Error;
89
use x509_cert::Certificate as X509Certificate;
910

11+
/// Error type for unsupported signature algorithms.
12+
#[derive(Error, Debug)]
13+
#[error("Unsupported signature algorithm: {oid}")]
14+
pub struct SignatureAlgoError {
15+
/// An OID of unsupported signature algorithm.
16+
oid: String,
17+
}
18+
1019
/// Returns `VerifyingKey` from the given X509 certificate.
1120
///
1221
/// # Errors
@@ -51,10 +60,12 @@ pub fn c509_key(cert: &C509) -> anyhow::Result<VerifyingKey> {
5160
}
5261

5362
/// Checks that the signature algorithm is supported.
54-
fn check_signature_algorithm(oid: &Oid) -> anyhow::Result<()> {
63+
fn check_signature_algorithm(oid: &Oid) -> Result<(), SignatureAlgoError> {
5564
// Currently the only supported signature algorithm is ED25519.
5665
if *oid != OID_SIG_ED25519 {
57-
return Err(anyhow!("Unsupported signature algorithm: {oid}"));
66+
return Err(SignatureAlgoError {
67+
oid: oid.to_id_string(),
68+
});
5869
}
5970
Ok(())
6071
}

0 commit comments

Comments
 (0)