5
5
// cspell: words pkix
6
6
7
7
pub mod rbac;
8
- pub ( crate ) mod utils;
8
+ pub mod types;
9
+ pub mod utils;
9
10
pub ( crate ) mod validation;
10
11
pub mod x509_chunks;
11
12
@@ -15,6 +16,8 @@ use minicbor::{
15
16
} ;
16
17
use pallas:: { crypto:: hash:: Hash , ledger:: traverse:: MultiEraTx } ;
17
18
use strum_macros:: FromRepr ;
19
+ use types:: tx_input_hash:: TxInputHash ;
20
+ use uuid:: Uuid ;
18
21
use validation:: {
19
22
validate_aux, validate_payment_key, validate_role_singing_key, validate_stake_public_key,
20
23
validate_txn_inputs_hash,
@@ -35,7 +38,7 @@ pub const LABEL: u64 = 509;
35
38
#[ derive( Debug , PartialEq , Clone , Default ) ]
36
39
pub struct Cip509 {
37
40
/// `UUIDv4` Purpose .
38
- pub purpose : UuidV4 , // (bytes .size 16)
41
+ pub purpose : Uuid , // (bytes .size 16)
39
42
/// Transaction inputs hash.
40
43
pub txn_inputs_hash : TxInputHash , // bytes .size 16
41
44
/// Optional previous transaction ID.
@@ -51,15 +54,15 @@ pub struct Cip509 {
51
54
#[ derive( Debug , PartialEq , Clone , Default ) ]
52
55
pub struct Cip509Validation {
53
56
/// 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 ,
55
58
/// 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 ,
59
62
/// Boolean value for the validity of the payment key.
60
- pub valid_payment_key : bool ,
63
+ pub is_valid_payment_key : bool ,
61
64
/// Boolean value for the validity of the signing key.
62
- pub signing_key : bool ,
65
+ pub is_valid_signing_key : bool ,
63
66
/// Additional data from the CIP509 validation..
64
67
pub additional_data : AdditionalData ,
65
68
}
@@ -71,54 +74,6 @@ pub struct AdditionalData {
71
74
pub precomputed_aux : Vec < u8 > ,
72
75
}
73
76
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
-
122
77
/// Enum of CIP509 metadatum with its associated unsigned integer value.
123
78
#[ allow( clippy:: module_name_repetitions) ]
124
79
#[ derive( FromRepr , Debug , PartialEq ) ]
@@ -147,7 +102,7 @@ impl Decode<'_, ()> for Cip509 {
147
102
match key {
148
103
Cip509IntIdentifier :: Purpose => {
149
104
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 ( |_| {
151
106
decode:: Error :: message ( "Invalid data size of Purpose" )
152
107
} ) ?;
153
108
} ,
@@ -217,32 +172,31 @@ impl Cip509 {
217
172
pub fn validate (
218
173
& self , txn : & MultiEraTx , validation_report : & mut Vec < String > ,
219
174
) -> Cip509Validation {
220
- let tx_input_validate =
175
+ let is_valid_txn_inputs_hash =
221
176
validate_txn_inputs_hash ( self , txn, validation_report) . unwrap_or ( false ) ;
222
- let ( aux_validate , precomputed_aux) =
177
+ let ( is_valid_aux , precomputed_aux) =
223
178
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 ;
228
182
if let Some ( role_set) = & self . x509_chunks . 0 . role_set {
229
183
// Validate only role 0
230
184
for role in role_set {
231
185
if role. role_number == 0 {
232
- stake_key_validate =
186
+ is_valid_stake_public_key =
233
187
validate_stake_public_key ( self , txn, validation_report) . unwrap_or ( false ) ;
234
- payment_key_validate =
188
+ is_valid_payment_key =
235
189
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) ;
237
191
}
238
192
}
239
193
}
240
194
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 ,
246
200
additional_data : AdditionalData { precomputed_aux } ,
247
201
}
248
202
}
0 commit comments