Skip to content

Commit ae05abd

Browse files
committed
wip
1 parent 3a7ae9b commit ae05abd

File tree

4 files changed

+99
-133
lines changed

4 files changed

+99
-133
lines changed

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

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use catalyst_types::{
2222
uuid::UuidV4,
2323
};
2424
use cbork_utils::decode_helper::{decode_bytes, decode_helper, decode_map_len};
25-
use ed25519_dalek::VerifyingKey;
2625
use minicbor::{
2726
decode::{self},
2827
Decode, Decoder,
@@ -33,7 +32,6 @@ use uuid::Uuid;
3332

3433
use crate::cardano::cip509::{
3534
decode_context::DecodeContext,
36-
extract_key,
3735
rbac::Cip509RbacMetadata,
3836
types::{PaymentHistory, TxInputHash, ValidationSignature},
3937
utils::Cip0134UriSet,
@@ -42,7 +40,7 @@ use crate::cardano::cip509::{
4240
validate_txn_inputs_hash,
4341
},
4442
x509_chunks::X509Chunks,
45-
C509Cert, LocalRefInt, Payment, PointTxnIdx, RoleData, SimplePublicKeyType, X509DerCert,
43+
Payment, PointTxnIdx, RoleData,
4644
};
4745

4846
/// A x509 metadata envelope.
@@ -229,46 +227,6 @@ impl Cip509 {
229227
self.metadata.as_ref().and_then(|m| m.role_data.get(&role))
230228
}
231229

232-
/// Returns signing public key for a role.
233-
#[must_use]
234-
pub fn signing_pk_for_role(
235-
&self,
236-
role: RoleId,
237-
) -> Option<VerifyingKey> {
238-
self.metadata.as_ref().and_then(|m| {
239-
let key_ref = m.role_data.get(&role).and_then(|d| d.signing_key())?;
240-
match key_ref.local_ref {
241-
LocalRefInt::X509Certs => {
242-
m.x509_certs.get(key_ref.key_offset).and_then(|c| {
243-
if let X509DerCert::X509Cert(c) = c {
244-
extract_key::x509_key(&c).ok()
245-
} else {
246-
None
247-
}
248-
})
249-
},
250-
LocalRefInt::C509Certs => {
251-
m.c509_certs.get(key_ref.key_offset).and_then(|c| {
252-
if let C509Cert::C509Certificate(c) = c {
253-
extract_key::c509_key(&c).ok()
254-
} else {
255-
None
256-
}
257-
})
258-
},
259-
LocalRefInt::PubKeys => {
260-
m.pub_keys.get(key_ref.key_offset).and_then(|c| {
261-
if let SimplePublicKeyType::Ed25519(c) = c {
262-
Some(c.clone())
263-
} else {
264-
None
265-
}
266-
})
267-
},
268-
}
269-
})
270-
}
271-
272230
/// Returns a purpose of this registration.
273231
#[must_use]
274232
pub fn purpose(&self) -> Option<UuidV4> {
@@ -355,26 +313,10 @@ impl Cip509 {
355313
.unwrap_or_default()
356314
}
357315

358-
/// Returns `Cip509` fields consuming the structure if it was successfully decoded and
359-
/// validated otherwise return the problem report that contains all the encountered
360-
/// issues.
361-
///
362-
/// # Errors
363-
///
364-
/// - `Err(ProblemReport)`
365-
pub fn consume(self) -> Result<(UuidV4, Cip509RbacMetadata, PaymentHistory), ProblemReport> {
366-
match (
367-
self.purpose,
368-
self.txn_inputs_hash,
369-
self.metadata,
370-
self.validation_signature,
371-
) {
372-
(Some(purpose), Some(_), Some(metadata), Some(_)) if !self.report.is_problematic() => {
373-
Ok((purpose, metadata, self.payment_history))
374-
},
375-
376-
_ => Err(self.report),
377-
}
316+
/// Returns a payment history map.
317+
#[must_use]
318+
pub fn payment_history(&self) -> &PaymentHistory {
319+
&self.payment_history
378320
}
379321
}
380322

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ mod tests {
593593
assert_eq!(origin.txn_index(), data.txn_index);
594594
assert_eq!(origin.point().slot_or_default(), data.slot);
595595

596-
// The consume function must return the problem report contained within the registration.
597-
let report = registration.consume().unwrap_err();
596+
let report = registration.report();
598597
assert!(report.is_problematic());
599598
let report = format!("{report:?}");
600599
assert!(report.contains("is not present in the transaction witness set, and can not be verified as owned and spendable"));
@@ -616,7 +615,7 @@ mod tests {
616615
assert_eq!(origin.txn_index(), data.txn_index);
617616
assert_eq!(origin.point().slot_or_default(), data.slot);
618617

619-
let report = registration.consume().unwrap_err();
618+
let report = registration.report();
620619
assert!(report.is_problematic());
621620
let report = format!("{report:?}");
622621
assert!(report
@@ -637,8 +636,7 @@ mod tests {
637636
assert_eq!(origin.txn_index(), data.txn_index);
638637
assert_eq!(origin.point().slot_or_default(), data.slot);
639638

640-
// The consume function must return the problem report contained within the registration.
641-
let report = registration.consume().unwrap_err();
639+
let report = registration.report();
642640
assert!(report.is_problematic());
643641
let report = format!("{report:?}");
644642
assert!(report.contains("Unknown role found: 4"));

0 commit comments

Comments
 (0)