File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
mithril-common/src/crypto_helper/cardano Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ pub enum ParseError {
45
45
46
46
#[ error( "CBOR parse error: `{0}`" ) ]
47
47
CborFormat ( #[ from] serde_cbor:: Error ) ,
48
+
49
+ #[ error( "Invalid KES format" ) ]
50
+ KesFormat ,
48
51
}
49
52
50
53
/// Fields for a shelley formatted file (holds for vkeys, skeys or certs)
@@ -121,9 +124,11 @@ impl SerDeShelleyFileFormat for Sum6KesBytes {
121
124
}
122
125
}
123
126
124
- impl < ' a > From < & ' a mut Sum6KesBytes > for Sum6Kes < ' a > {
125
- fn from ( value : & ' a mut Sum6KesBytes ) -> Self {
126
- Self :: from_bytes ( & mut value. 0 ) . expect ( "Invalid data format" )
127
+ impl < ' a > TryFrom < & ' a mut Sum6KesBytes > for Sum6Kes < ' a > {
128
+ type Error = ParseError ;
129
+
130
+ fn try_from ( value : & ' a mut Sum6KesBytes ) -> Result < Self , Self :: Error > {
131
+ Self :: from_bytes ( & mut value. 0 ) . map_err ( |_| ParseError :: KesFormat )
127
132
}
128
133
}
129
134
@@ -154,6 +159,6 @@ mod test {
154
159
let mut kes_sk_bytes =
155
160
Sum6KesBytes :: from_file ( & sk_dir) . expect ( "Failure parsing Shelley file format." ) ;
156
161
157
- let _kes_sk = Sum6Kes :: from ( & mut kes_sk_bytes) ; // Panics if data is incorrect
162
+ assert ! ( Sum6Kes :: try_from ( & mut kes_sk_bytes) . is_ok ( ) ) ;
158
163
}
159
164
}
Original file line number Diff line number Diff line change @@ -125,7 +125,8 @@ impl StmInitializerWrapper {
125
125
let stm_initializer = StmInitializer :: setup ( params, stake, rng) ;
126
126
let kes_signature = if let Some ( kes_sk_path) = kes_sk_path {
127
127
let mut kes_sk_bytes = Sum6KesBytes :: from_file ( kes_sk_path) ?;
128
- let mut kes_sk = Sum6Kes :: from ( & mut kes_sk_bytes) ;
128
+ let mut kes_sk = Sum6Kes :: try_from ( & mut kes_sk_bytes)
129
+ . map_err ( ProtocolInitializerErrorWrapper :: Codec ) ?;
129
130
let kes_sk_period = kes_sk. get_period ( ) ;
130
131
let provided_period = kes_period. unwrap_or_default ( ) ;
131
132
if kes_sk_period > provided_period {
You can’t perform that action at this time.
0 commit comments