1
1
//! A local key reference.
2
2
3
+ use catalyst_types:: problem_report:: ProblemReport ;
3
4
use cbork_utils:: decode_helper:: decode_helper;
4
5
use minicbor:: { decode, Decode , Decoder } ;
5
6
use strum_macros:: FromRepr ;
6
7
7
8
use crate :: cardano:: cip509:: rbac:: Cip509RbacMetadataInt ;
8
9
9
10
/// Local key reference.
10
- #[ derive( Debug , PartialEq , Clone ) ]
11
+ #[ derive( Debug , PartialEq , Clone , Copy ) ]
11
12
pub struct KeyLocalRef {
12
13
/// Local reference.
13
14
pub local_ref : LocalRefInt ,
14
15
/// Key offset.
15
- pub key_offset : u64 ,
16
+ pub key_offset : usize ,
16
17
}
17
18
18
19
/// Enum of local reference with its associated unsigned integer value.
19
- #[ derive( FromRepr , Debug , PartialEq , Clone , Eq , Hash ) ]
20
+ #[ derive( FromRepr , Debug , PartialEq , Clone , Copy , Eq , Hash ) ]
20
21
#[ repr( u8 ) ]
21
22
pub enum LocalRefInt {
22
23
/// x509 certificates.
@@ -27,11 +28,23 @@ pub enum LocalRefInt {
27
28
PubKeys = Cip509RbacMetadataInt :: PubKeys as u8 , // 30
28
29
}
29
30
30
- impl Decode < ' _ , ( ) > for KeyLocalRef {
31
- fn decode ( d : & mut Decoder , ctx : & mut ( ) ) -> Result < Self , decode:: Error > {
32
- let local_ref = LocalRefInt :: from_repr ( decode_helper ( d, "LocalRef in KeyLocalRef" , ctx) ?)
33
- . ok_or ( decode:: Error :: message ( "Invalid local reference" ) ) ?;
34
- let key_offset: u64 = decode_helper ( d, "KeyOffset in KeyLocalRef" , ctx) ?;
31
+ impl Decode < ' _ , ProblemReport > for KeyLocalRef {
32
+ fn decode ( d : & mut Decoder , report : & mut ProblemReport ) -> Result < Self , decode:: Error > {
33
+ let local_ref =
34
+ LocalRefInt :: from_repr ( decode_helper ( d, "LocalRef in KeyLocalRef" , & mut ( ) ) ?)
35
+ . ok_or ( decode:: Error :: message ( "Invalid local reference" ) ) ?;
36
+ let key_offset: u64 = decode_helper ( d, "KeyOffset in KeyLocalRef" , & mut ( ) ) ?;
37
+ let key_offset = if let Ok ( v) = usize:: try_from ( key_offset) {
38
+ v
39
+ } else {
40
+ report. invalid_value (
41
+ "key_offset" ,
42
+ & format ! ( "{key_offset}" ) ,
43
+ & format ! ( "Value must be less than {}" , usize :: MAX ) ,
44
+ "KeyLocalRef decoding" ,
45
+ ) ;
46
+ 0
47
+ } ;
35
48
Ok ( Self {
36
49
local_ref,
37
50
key_offset,
0 commit comments