Skip to content

Commit a5af8a8

Browse files
Make Cip509 field private
1 parent 84137d9 commit a5af8a8

File tree

2 files changed

+31
-13
lines changed
  • rust/rbac-registration/src

2 files changed

+31
-13
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ pub struct Cip509 {
4949
/// A registration purpose (`UUIDv4`).
5050
///
5151
/// The purpose is defined by the consuming dApp.
52-
pub purpose: Uuid,
52+
purpose: Uuid,
5353
/// Transaction inputs hash.
54-
pub txn_inputs_hash: TxInputHash,
54+
txn_inputs_hash: TxInputHash,
5555
/// An optional hash of the previous transaction.
5656
///
5757
/// The hash must always be present except for the first registration transaction.
58-
pub prv_tx_id: Option<Blake2b256Hash>,
58+
prv_tx_id: Option<Blake2b256Hash>,
5959
/// Metadata.
6060
///
6161
/// This field encoded in chunks. See [`X509Chunks`] for more details.
62-
pub metadata: Cip509RbacMetadata,
62+
metadata: Cip509RbacMetadata,
6363
/// Validation signature.
64-
pub validation_signature: ValidationSignature,
64+
validation_signature: ValidationSignature,
6565
}
6666

6767
/// Validation value for CIP509 metadatum.
@@ -239,4 +239,22 @@ impl Cip509 {
239239
additional_data: AdditionalData { precomputed_aux },
240240
}
241241
}
242+
243+
/// Returns a registration purpose.
244+
#[must_use]
245+
pub fn purpose(&self) -> Uuid {
246+
self.purpose
247+
}
248+
249+
/// Returns an identifier of the previous transaction.
250+
#[must_use]
251+
pub fn previous_transaction(&self) -> Option<&Blake2b256Hash> {
252+
self.prv_tx_id.as_ref()
253+
}
254+
255+
/// Returns CIP509 metadata.
256+
#[must_use]
257+
pub fn metadata(&self) -> &Cip509RbacMetadata {
258+
&self.metadata
259+
}
242260
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl RegistrationChainInner {
185185
txn: &MultiEraTx,
186186
) -> anyhow::Result<Self> {
187187
// Should be chain root, return immediately if not
188-
if cip509.prv_tx_id.is_some() {
188+
if cip509.previous_transaction().is_some() {
189189
bail!("Invalid chain root, previous transaction ID should be None.");
190190
}
191191

@@ -200,9 +200,9 @@ impl RegistrationChainInner {
200200
}
201201

202202
// Add purpose to the list
203-
let purpose = vec![cip509.purpose];
203+
let purpose = vec![cip509.purpose()];
204204

205-
let registration = cip509.metadata;
205+
let registration = cip509.metadata().clone();
206206
let point_tx_idx = PointTxIdx::new(point, tx_idx);
207207

208208
let certificate_uris = registration.certificate_uris;
@@ -259,23 +259,23 @@ impl RegistrationChainInner {
259259
}
260260

261261
// Check and update the current transaction ID hash
262-
if let Some(prv_tx_id) = cip509.prv_tx_id {
262+
if let Some(prv_tx_id) = cip509.previous_transaction() {
263263
// Previous transaction ID in the CIP509 should equal to the current transaction ID
264264
// or else it is not a part of the chain
265-
if prv_tx_id == self.current_tx_id_hash {
266-
new_inner.current_tx_id_hash = prv_tx_id;
265+
if prv_tx_id == &self.current_tx_id_hash {
266+
new_inner.current_tx_id_hash = *prv_tx_id;
267267
} else {
268268
bail!("Invalid previous transaction ID, not a part of this registration chain");
269269
}
270270
}
271271

272272
// Add purpose to the chain, if not already exist
273-
let purpose = cip509.purpose;
273+
let purpose = cip509.purpose();
274274
if !self.purpose.contains(&purpose) {
275275
new_inner.purpose.push(purpose);
276276
}
277277

278-
let registration = cip509.metadata;
278+
let registration = cip509.metadata().clone();
279279
let point_tx_idx = PointTxIdx::new(point, tx_idx);
280280
new_inner.certificate_uris = new_inner.certificate_uris.update(&registration);
281281
update_x509_certs(&mut new_inner, registration.x509_certs, &point_tx_idx);

0 commit comments

Comments
 (0)