Skip to content

Commit 299c0ec

Browse files
Introduce Cip0134UriSet type
1 parent 433f3cb commit 299c0ec

File tree

10 files changed

+319
-213
lines changed

10 files changed

+319
-213
lines changed

rust/rbac-registration/src/cardano/cip509/mod.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@ use validation::{
2525
use x509_chunks::X509Chunks;
2626

2727
use super::transaction::witness::TxWitness;
28-
use crate::utils::{
29-
decode_helper::{decode_bytes, decode_helper, decode_map_len},
30-
general::{decode_utf8, decremented_index},
31-
hashing::{blake2b_128, blake2b_256},
28+
use crate::{
29+
cardano::cip509::rbac::Cip509RbacMetadata,
30+
utils::{
31+
decode_helper::{decode_bytes, decode_helper, decode_map_len},
32+
general::{decode_utf8, decremented_index},
33+
hashing::{blake2b_128, blake2b_256},
34+
},
3235
};
3336

3437
/// CIP509 label.
3538
pub const LABEL: u64 = 509;
3639

3740
/// CIP509.
41+
///
42+
/// See `x509-envelope.cddl` for the details how this structure is encoded.
3843
#[derive(Debug, PartialEq, Clone, Default)]
3944
pub struct Cip509 {
4045
/// `UUIDv4` Purpose .
@@ -43,9 +48,13 @@ pub struct Cip509 {
4348
pub txn_inputs_hash: TxInputHash, // bytes .size 16
4449
/// Optional previous transaction ID.
4550
pub prv_tx_id: Option<Hash<32>>, // bytes .size 32
46-
/// x509 chunks.
47-
pub x509_chunks: X509Chunks, // chunk_type => [ + x509_chunk ]
51+
/// Metadata.
52+
///
53+
/// This field encoded in chunks (`chunk_type => [ + x509_chunk ]`). See
54+
/// [`X509Chunks`] for more details.
55+
pub metadata: Cip509RbacMetadata,
4856
/// Validation signature.
57+
// TODO: FIXME: This probably should be a separate type and not just Vec.
4958
pub validation_signature: Vec<u8>, // bytes size (1..64)
5059
}
5160

@@ -134,7 +143,7 @@ impl Decode<'_, ()> for Cip509 {
134143
} else {
135144
// Handle the x509 chunks 10 11 12
136145
let x509_chunks = X509Chunks::decode(d, ctx)?;
137-
cip509_metadatum.x509_chunks = x509_chunks;
146+
cip509_metadatum.metadata = x509_chunks.into();
138147
}
139148
}
140149
Ok(cip509_metadatum)
@@ -179,7 +188,7 @@ impl Cip509 {
179188
let mut is_valid_stake_public_key = true;
180189
let mut is_valid_payment_key = true;
181190
let mut is_valid_signing_key = true;
182-
if let Some(role_set) = &self.x509_chunks.0.role_set {
191+
if let Some(role_set) = &self.metadata.role_set {
183192
// Validate only role 0
184193
for role in role_set {
185194
if role.role_number == 0 {

rust/rbac-registration/src/cardano/cip509/rbac/mod.rs

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@ use role_data::RoleData;
1616
use strum_macros::FromRepr;
1717

1818
use 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.
2427
#[derive(Debug, PartialEq, Clone, Default)]
2528
pub struct Cip509RbacMetadata {
29+
// TODO: FIXME: Discuss if we need `Option<Vec>`.
2630
/// Optional list of x509 certificates.
31+
// TODO: FIXME: Parse X509DerCert?..
2732
pub x509_certs: Option<Vec<X509DerCert>>,
2833
/// Optional list of c509 certificates.
2934
/// The value can be either the c509 certificate or c509 metadatum reference.
3035
pub c509_certs: Option<Vec<C509Cert>>,
36+
// TODO: FIXME:
37+
pub fixme: Cip0134UriSet,
3138
/// Optional list of Public keys.
3239
pub pub_keys: Option<Vec<SimplePublicKeyType>>,
3340
/// Optional list of revocation list.
@@ -60,74 +67,35 @@ pub enum Cip509RbacMetadataInt {
6067
RoleSet = 100,
6168
}
6269

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-
10270
impl Decode<'_, ()> for Cip509RbacMetadata {
10371
fn decode(d: &mut Decoder, ctx: &mut ()) -> Result<Self, decode::Error> {
10472
let map_len = decode_map_len(d, "Cip509RbacMetadata")?;
10573

106-
let mut x509_rbac_metadata = Cip509RbacMetadata::new();
74+
let mut x509_rbac_metadata = Cip509RbacMetadata::default();
10775

10876
for _ in 0..map_len {
10977
let key: u16 = decode_helper(d, "key in Cip509RbacMetadata", ctx)?;
11078
if let Some(key) = Cip509RbacMetadataInt::from_repr(key) {
11179
match key {
11280
Cip509RbacMetadataInt::X509Certs => {
11381
let x509_certs = decode_array_rbac(d, "x509 certificate")?;
114-
x509_rbac_metadata.set_x509_certs(x509_certs);
82+
x509_rbac_metadata.x509_certs = Some(x509_certs);
11583
},
11684
Cip509RbacMetadataInt::C509Certs => {
11785
let c509_certs = decode_array_rbac(d, "c509 certificate")?;
118-
x509_rbac_metadata.set_c509_certs(c509_certs);
86+
x509_rbac_metadata.c509_certs = Some(c509_certs);
11987
},
12088
Cip509RbacMetadataInt::PubKeys => {
12189
let pub_keys = decode_array_rbac(d, "public keys")?;
122-
x509_rbac_metadata.set_pub_keys(pub_keys);
90+
x509_rbac_metadata.pub_keys = Some(pub_keys);
12391
},
12492
Cip509RbacMetadataInt::RevocationList => {
12593
let revocation_list = decode_revocation_list(d)?;
126-
x509_rbac_metadata.set_revocation_list(revocation_list);
94+
x509_rbac_metadata.revocation_list = Some(revocation_list);
12795
},
12896
Cip509RbacMetadataInt::RoleSet => {
12997
let role_set = decode_array_rbac(d, "role set")?;
130-
x509_rbac_metadata.set_role_set(role_set);
98+
x509_rbac_metadata.role_set = Some(role_set);
13199
},
132100
}
133101
} else {
@@ -139,6 +107,9 @@ impl Decode<'_, ()> for Cip509RbacMetadata {
139107
.insert(key, decode_any(d, "purpose key")?);
140108
}
141109
}
110+
111+
// TODO: FIXME:
112+
x509_rbac_metadata.fixme = Cip0134UriSet::new();
142113
Ok(x509_rbac_metadata)
143114
}
144115
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Utilities for [CIP-134] (Cardano URIs - Address Representation).
2+
//!
3+
//! [CIP-134]: https://github.com/cardano-foundation/CIPs/tree/master/CIP-0134
4+
pub use self::{uri::Cip0134Uri, uri_set::Cip0134UriSet};
5+
6+
mod uri;
7+
mod uri_set;

rust/rbac-registration/src/cardano/cip509/utils/cip134.rs renamed to rust/rbac-registration/src/cardano/cip509/utils/cip134/uri.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Utility functions for CIP-0134 address.
1+
//! An URI in the CIP-0134 format.
22
33
// Ignore URIs that are used in tests and doc-examples.
44
// cSpell:ignoreRegExp web\+cardano:.+
@@ -13,7 +13,8 @@ use pallas::ledger::addresses::Address;
1313
/// See the [proposal] for more details.
1414
///
1515
/// [proposal]: https://github.com/cardano-foundation/CIPs/pull/888
16-
#[derive(Debug)]
16+
#[derive(Debug, Eq, PartialEq)]
17+
#[allow(clippy::module_name_repetitions)]
1718
pub struct Cip0134Uri {
1819
/// A URI string.
1920
uri: String,

0 commit comments

Comments
 (0)