@@ -16,19 +16,40 @@ use role_data::RoleData;
1616use strum_macros:: FromRepr ;
1717
1818use super :: types:: cert_key_hash:: CertKeyHash ;
19- use crate :: utils:: decode_helper:: {
20- decode_any, decode_array_len, decode_bytes, decode_helper, decode_map_len,
19+ use crate :: {
20+ cardano:: cip509:: utils:: Cip0134UriSet ,
21+ utils:: decode_helper:: {
22+ decode_any, decode_array_len, decode_bytes, decode_helper, decode_map_len,
23+ } ,
2124} ;
2225
2326/// Cip509 RBAC metadata.
27+ ///
28+ /// See [this document] for more details.
29+ ///
30+ /// [this document]: https://github.com/input-output-hk/catalyst-CIPs/tree/x509-role-registration-metadata/CIP-XXXX
2431#[ derive( Debug , PartialEq , Clone , Default ) ]
32+ // TODO: FIXME: Discuss if we need options everywhere (`Option<Vec> -> Vec`).
2533pub struct Cip509RbacMetadata {
34+ // TODO: FIXME: Parse X509DerCert?..
35+ // TODO: FIXME: Store only C509Cert (transcode X509DerCert to C509Cert?).
36+ // TODO: FIXME: Check if we allow both lists to be present.
37+ // TODO: FIXME: Better documentation for the certificate field (or fields!).
2638 /// Optional list of x509 certificates.
2739 pub x509_certs : Option < Vec < X509DerCert > > ,
2840 /// Optional list of c509 certificates.
2941 /// The value can be either the c509 certificate or c509 metadatum reference.
3042 pub c509_certs : Option < Vec < C509Cert > > ,
31- /// Optional list of Public keys.
43+ // TODO: FIXME: Better documentation for the URI set/list field.
44+ /// This field isn't present in the encoded format and is populated by processing both
45+ /// `x509_certs` and `c509_certs`.
46+ pub fixme : Cip0134UriSet ,
47+ /// A list of public keys that can be used instead of storing full certificates.
48+ ///
49+ /// Check [this section] to understand the how certificates and the public keys list
50+ /// are related.
51+ ///
52+ /// [this section]: https://github.com/input-output-hk/catalyst-CIPs/tree/x509-role-registration-metadata/CIP-XXXX#storing-certificates-and-public-key
3253 pub pub_keys : Option < Vec < SimplePublicKeyType > > ,
3354 /// Optional list of revocation list.
3455 pub revocation_list : Option < Vec < CertKeyHash > > ,
@@ -60,74 +81,35 @@ pub enum Cip509RbacMetadataInt {
6081 RoleSet = 100 ,
6182}
6283
63- impl Cip509RbacMetadata {
64- /// Create a new instance of `Cip509RbacMetadata`.
65- pub ( crate ) fn new ( ) -> Self {
66- Self {
67- x509_certs : None ,
68- c509_certs : None ,
69- pub_keys : None ,
70- revocation_list : None ,
71- role_set : None ,
72- purpose_key_data : HashMap :: new ( ) ,
73- }
74- }
75-
76- /// Set the x509 certificates.
77- fn set_x509_certs ( & mut self , x509_certs : Vec < X509DerCert > ) {
78- self . x509_certs = Some ( x509_certs) ;
79- }
80-
81- /// Set the c509 certificates.
82- fn set_c509_certs ( & mut self , c509_certs : Vec < C509Cert > ) {
83- self . c509_certs = Some ( c509_certs) ;
84- }
85-
86- /// Set the public keys.
87- fn set_pub_keys ( & mut self , pub_keys : Vec < SimplePublicKeyType > ) {
88- self . pub_keys = Some ( pub_keys) ;
89- }
90-
91- /// Set the revocation list.
92- fn set_revocation_list ( & mut self , revocation_list : Vec < CertKeyHash > ) {
93- self . revocation_list = Some ( revocation_list) ;
94- }
95-
96- /// Set the role data set.
97- fn set_role_set ( & mut self , role_set : Vec < RoleData > ) {
98- self . role_set = Some ( role_set) ;
99- }
100- }
101-
10284impl Decode < ' _ , ( ) > for Cip509RbacMetadata {
10385 fn decode ( d : & mut Decoder , ctx : & mut ( ) ) -> Result < Self , decode:: Error > {
10486 let map_len = decode_map_len ( d, "Cip509RbacMetadata" ) ?;
10587
106- let mut x509_rbac_metadata = Cip509RbacMetadata :: new ( ) ;
88+ let mut x509_rbac_metadata = Cip509RbacMetadata :: default ( ) ;
10789
10890 for _ in 0 ..map_len {
10991 let key: u16 = decode_helper ( d, "key in Cip509RbacMetadata" , ctx) ?;
11092 if let Some ( key) = Cip509RbacMetadataInt :: from_repr ( key) {
11193 match key {
11294 Cip509RbacMetadataInt :: X509Certs => {
11395 let x509_certs = decode_array_rbac ( d, "x509 certificate" ) ?;
114- x509_rbac_metadata. set_x509_certs ( x509_certs) ;
96+ x509_rbac_metadata. x509_certs = Some ( x509_certs) ;
11597 } ,
11698 Cip509RbacMetadataInt :: C509Certs => {
11799 let c509_certs = decode_array_rbac ( d, "c509 certificate" ) ?;
118- x509_rbac_metadata. set_c509_certs ( c509_certs) ;
100+ x509_rbac_metadata. c509_certs = Some ( c509_certs) ;
119101 } ,
120102 Cip509RbacMetadataInt :: PubKeys => {
121103 let pub_keys = decode_array_rbac ( d, "public keys" ) ?;
122- x509_rbac_metadata. set_pub_keys ( pub_keys) ;
104+ x509_rbac_metadata. pub_keys = Some ( pub_keys) ;
123105 } ,
124106 Cip509RbacMetadataInt :: RevocationList => {
125107 let revocation_list = decode_revocation_list ( d) ?;
126- x509_rbac_metadata. set_revocation_list ( revocation_list) ;
108+ x509_rbac_metadata. revocation_list = Some ( revocation_list) ;
127109 } ,
128110 Cip509RbacMetadataInt :: RoleSet => {
129111 let role_set = decode_array_rbac ( d, "role set" ) ?;
130- x509_rbac_metadata. set_role_set ( role_set) ;
112+ x509_rbac_metadata. role_set = Some ( role_set) ;
131113 } ,
132114 }
133115 } else {
@@ -139,6 +121,9 @@ impl Decode<'_, ()> for Cip509RbacMetadata {
139121 . insert ( key, decode_any ( d, "purpose key" ) ?) ;
140122 }
141123 }
124+
125+ // TODO: FIXME:
126+ x509_rbac_metadata. fixme = Cip0134UriSet :: new ( ) ;
142127 Ok ( x509_rbac_metadata)
143128 }
144129}
0 commit comments