55// cspell: words pkix
66
77pub mod rbac;
8- pub ( crate ) mod utils;
8+ pub mod types;
9+ pub mod utils;
910pub ( crate ) mod validation;
1011pub mod x509_chunks;
1112
@@ -15,6 +16,8 @@ use minicbor::{
1516} ;
1617use pallas:: { crypto:: hash:: Hash , ledger:: traverse:: MultiEraTx } ;
1718use strum_macros:: FromRepr ;
19+ use types:: tx_input_hash:: TxInputHash ;
20+ use uuid:: Uuid ;
1821use validation:: {
1922 validate_aux, validate_payment_key, validate_role_singing_key, validate_stake_public_key,
2023 validate_txn_inputs_hash,
@@ -35,7 +38,7 @@ pub const LABEL: u64 = 509;
3538#[ derive( Debug , PartialEq , Clone , Default ) ]
3639pub struct Cip509 {
3740 /// `UUIDv4` Purpose .
38- pub purpose : UuidV4 , // (bytes .size 16)
41+ pub purpose : Uuid , // (bytes .size 16)
3942 /// Transaction inputs hash.
4043 pub txn_inputs_hash : TxInputHash , // bytes .size 16
4144 /// Optional previous transaction ID.
@@ -51,15 +54,15 @@ pub struct Cip509 {
5154#[ derive( Debug , PartialEq , Clone , Default ) ]
5255pub struct Cip509Validation {
5356 /// Boolean value for the validity of the transaction inputs hash.
54- pub valid_txn_inputs_hash : bool ,
57+ pub is_valid_txn_inputs_hash : bool ,
5558 /// Boolean value for the validity of the auxiliary data.
56- pub valid_aux : bool ,
57- /// Boolean value for the validity of the public key.
58- pub valid_public_key : bool ,
59+ pub is_valid_aux : bool ,
60+ /// Boolean value for the validity of the stake public key.
61+ pub is_valid_stake_public_key : bool ,
5962 /// Boolean value for the validity of the payment key.
60- pub valid_payment_key : bool ,
63+ pub is_valid_payment_key : bool ,
6164 /// Boolean value for the validity of the signing key.
62- pub signing_key : bool ,
65+ pub is_valid_signing_key : bool ,
6366 /// Additional data from the CIP509 validation..
6467 pub additional_data : AdditionalData ,
6568}
@@ -71,54 +74,6 @@ pub struct AdditionalData {
7174 pub precomputed_aux : Vec < u8 > ,
7275}
7376
74- /// `UUIDv4` representing in 16 bytes.
75- #[ derive( Debug , PartialEq , Clone , Default ) ]
76- pub struct UuidV4 ( [ u8 ; 16 ] ) ;
77-
78- impl From < [ u8 ; 16 ] > for UuidV4 {
79- fn from ( bytes : [ u8 ; 16 ] ) -> Self {
80- UuidV4 ( bytes)
81- }
82- }
83-
84- impl TryFrom < Vec < u8 > > for UuidV4 {
85- type Error = & ' static str ;
86-
87- fn try_from ( vec : Vec < u8 > ) -> Result < Self , Self :: Error > {
88- if vec. len ( ) == 16 {
89- let mut array = [ 0u8 ; 16 ] ;
90- array. copy_from_slice ( & vec) ;
91- Ok ( UuidV4 ( array) )
92- } else {
93- Err ( "Input Vec must be exactly 16 bytes" )
94- }
95- }
96- }
97-
98- /// Transaction input hash representing in 16 bytes.
99- #[ derive( Debug , PartialEq , Clone , Default ) ]
100- pub struct TxInputHash ( [ u8 ; 16 ] ) ;
101-
102- impl From < [ u8 ; 16 ] > for TxInputHash {
103- fn from ( bytes : [ u8 ; 16 ] ) -> Self {
104- TxInputHash ( bytes)
105- }
106- }
107-
108- impl TryFrom < Vec < u8 > > for TxInputHash {
109- type Error = & ' static str ;
110-
111- fn try_from ( vec : Vec < u8 > ) -> Result < Self , Self :: Error > {
112- if vec. len ( ) == 16 {
113- let mut array = [ 0u8 ; 16 ] ;
114- array. copy_from_slice ( & vec) ;
115- Ok ( TxInputHash ( array) )
116- } else {
117- Err ( "Input Vec must be exactly 16 bytes" )
118- }
119- }
120- }
121-
12277/// Enum of CIP509 metadatum with its associated unsigned integer value.
12378#[ allow( clippy:: module_name_repetitions) ]
12479#[ derive( FromRepr , Debug , PartialEq ) ]
@@ -147,7 +102,7 @@ impl Decode<'_, ()> for Cip509 {
147102 match key {
148103 Cip509IntIdentifier :: Purpose => {
149104 cip509_metadatum. purpose =
150- UuidV4 :: try_from ( decode_bytes ( d, "CIP509 purpose" ) ?) . map_err ( |_| {
105+ Uuid :: try_from ( decode_bytes ( d, "CIP509 purpose" ) ?) . map_err ( |_| {
151106 decode:: Error :: message ( "Invalid data size of Purpose" )
152107 } ) ?;
153108 } ,
@@ -217,32 +172,31 @@ impl Cip509 {
217172 pub fn validate (
218173 & self , txn : & MultiEraTx , validation_report : & mut Vec < String > ,
219174 ) -> Cip509Validation {
220- let tx_input_validate =
175+ let is_valid_txn_inputs_hash =
221176 validate_txn_inputs_hash ( self , txn, validation_report) . unwrap_or ( false ) ;
222- let ( aux_validate , precomputed_aux) =
177+ let ( is_valid_aux , precomputed_aux) =
223178 validate_aux ( txn, validation_report) . unwrap_or_default ( ) ;
224- let mut stake_key_validate = true ;
225- let mut payment_key_validate = true ;
226- let mut signing_key = true ;
227- // Validate the role 0
179+ let mut is_valid_stake_public_key = true ;
180+ let mut is_valid_payment_key = true ;
181+ let mut is_valid_signing_key = true ;
228182 if let Some ( role_set) = & self . x509_chunks . 0 . role_set {
229183 // Validate only role 0
230184 for role in role_set {
231185 if role. role_number == 0 {
232- stake_key_validate =
186+ is_valid_stake_public_key =
233187 validate_stake_public_key ( self , txn, validation_report) . unwrap_or ( false ) ;
234- payment_key_validate =
188+ is_valid_payment_key =
235189 validate_payment_key ( txn, role, validation_report) . unwrap_or ( false ) ;
236- signing_key = validate_role_singing_key ( role, validation_report) ;
190+ is_valid_signing_key = validate_role_singing_key ( role, validation_report) ;
237191 }
238192 }
239193 }
240194 Cip509Validation {
241- valid_txn_inputs_hash : tx_input_validate ,
242- valid_aux : aux_validate ,
243- valid_public_key : stake_key_validate ,
244- valid_payment_key : payment_key_validate ,
245- signing_key ,
195+ is_valid_txn_inputs_hash ,
196+ is_valid_aux ,
197+ is_valid_stake_public_key ,
198+ is_valid_payment_key ,
199+ is_valid_signing_key ,
246200 additional_data : AdditionalData { precomputed_aux } ,
247201 }
248202 }
0 commit comments