@@ -22,6 +22,7 @@ use point_tx_idx::PointTxIdx;
2222use role_data:: RoleData ;
2323use tracing:: error;
2424use uuid:: Uuid ;
25+ use x509_cert:: certificate:: Certificate as X509Certificate ;
2526
2627use crate :: {
2728 cardano:: cip509:: {
@@ -102,7 +103,7 @@ impl RegistrationChain {
102103
103104 /// Get the map of index in array to point, transaction index, and x509 certificate.
104105 #[ must_use]
105- pub fn x509_certs ( & self ) -> & HashMap < usize , ( PointTxIdx , Vec < u8 > ) > {
106+ pub fn x509_certs ( & self ) -> & HashMap < usize , ( PointTxIdx , X509Certificate ) > {
106107 & self . inner . x509_certs
107108 }
108109
@@ -147,7 +148,7 @@ struct RegistrationChainInner {
147148
148149 // RBAC
149150 /// Map of index in array to point, transaction index, and x509 certificate.
150- x509_certs : HashMap < usize , ( PointTxIdx , Vec < u8 > ) > ,
151+ x509_certs : HashMap < usize , ( PointTxIdx , X509Certificate ) > ,
151152 /// Map of index in array to point, transaction index, and c509 certificate.
152153 c509_certs : HashMap < usize , ( PointTxIdx , C509 ) > ,
153154 /// Map of index in array to point, transaction index, and public key.
@@ -304,15 +305,18 @@ fn is_valid_cip509(validation_data: &Cip509Validation) -> bool {
304305/// Process x509 certificate for chain root.
305306fn chain_root_x509_certs (
306307 x509_certs : Vec < X509DerCert > , point_tx_idx : & PointTxIdx ,
307- ) -> HashMap < usize , ( PointTxIdx , Vec < u8 > ) > {
308- let mut map = HashMap :: new ( ) ;
309- for ( idx, cert) in x509_certs. into_iter ( ) . enumerate ( ) {
310- // Chain root, expect only the certificate not undefined or delete
311- if let X509DerCert :: X509Cert ( cert) = cert {
312- map. insert ( idx, ( point_tx_idx. clone ( ) , cert) ) ;
313- }
314- }
315- map
308+ ) -> HashMap < usize , ( PointTxIdx , X509Certificate ) > {
309+ x509_certs
310+ . into_iter ( )
311+ . enumerate ( )
312+ . filter_map ( |( index, cert) | {
313+ if let X509DerCert :: X509Cert ( cert) = cert {
314+ Some ( ( index, ( point_tx_idx. clone ( ) , * cert) ) )
315+ } else {
316+ None
317+ }
318+ } )
319+ . collect ( )
316320}
317321
318322/// Update x509 certificates in the registration chain.
@@ -331,7 +335,7 @@ fn update_x509_certs(
331335 X509DerCert :: X509Cert ( cert) => {
332336 new_inner
333337 . x509_certs
334- . insert ( idx, ( point_tx_idx. clone ( ) , cert) ) ;
338+ . insert ( idx, ( point_tx_idx. clone ( ) , * cert) ) ;
335339 } ,
336340 }
337341 }
0 commit comments