Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rust/rbac-registration/src/cardano/cip509/rbac/role_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ impl Decode<'_, ProblemReport> for CborRoleData {

/// Decodes a signing key.
fn decode_signing_key(
d: &mut Decoder, context: &str, report: &ProblemReport,
d: &mut Decoder, context: &str, report: &mut ProblemReport,
) -> Result<Option<KeyLocalRef>, ()> {
if let Err(e) = decode_array_len(d, "RoleSigningKey") {
report.other(&format!("{e:?}"), context);
return Err(());
}

match KeyLocalRef::decode(d, &mut ()) {
match KeyLocalRef::decode(d, report) {
Ok(v) => Ok(Some(v)),
Err(e) => {
report.other(
Expand All @@ -158,14 +158,14 @@ fn decode_signing_key(

/// Decodes an encryption key.
fn decode_encryption_key(
d: &mut Decoder, context: &str, report: &ProblemReport,
d: &mut Decoder, context: &str, report: &mut ProblemReport,
) -> Result<Option<KeyLocalRef>, ()> {
if let Err(e) = decode_array_len(d, "RoleEncryptionKey") {
report.other(&format!("{e:?}"), context);
return Err(());
}

match KeyLocalRef::decode(d, &mut ()) {
match KeyLocalRef::decode(d, report) {
Ok(v) => Ok(Some(v)),
Err(e) => {
report.other(
Expand Down
25 changes: 19 additions & 6 deletions rust/rbac-registration/src/cardano/cip509/types/key_local_ref.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! A local key reference.

use catalyst_types::problem_report::ProblemReport;
use cbork_utils::decode_helper::decode_helper;
use minicbor::{decode, Decode, Decoder};
use strum_macros::FromRepr;
Expand All @@ -12,7 +13,7 @@ pub struct KeyLocalRef {
/// Local reference.
pub local_ref: LocalRefInt,
/// Key offset.
pub key_offset: u64,
pub key_offset: usize,
}

/// Enum of local reference with its associated unsigned integer value.
Expand All @@ -27,11 +28,23 @@ pub enum LocalRefInt {
PubKeys = Cip509RbacMetadataInt::PubKeys as u8, // 30
}

impl Decode<'_, ()> for KeyLocalRef {
fn decode(d: &mut Decoder, ctx: &mut ()) -> Result<Self, decode::Error> {
let local_ref = LocalRefInt::from_repr(decode_helper(d, "LocalRef in KeyLocalRef", ctx)?)
.ok_or(decode::Error::message("Invalid local reference"))?;
let key_offset: u64 = decode_helper(d, "KeyOffset in KeyLocalRef", ctx)?;
impl Decode<'_, ProblemReport> for KeyLocalRef {
fn decode(d: &mut Decoder, report: &mut ProblemReport) -> Result<Self, decode::Error> {
let local_ref =
LocalRefInt::from_repr(decode_helper(d, "LocalRef in KeyLocalRef", &mut ())?)
.ok_or(decode::Error::message("Invalid local reference"))?;
let key_offset: u64 = decode_helper(d, "KeyOffset in KeyLocalRef", &mut ())?;
let key_offset = if let Ok(v) = usize::try_from(key_offset) {
v
} else {
report.invalid_value(
"key_offset",
&format!("{key_offset}"),
&format!("Value must be less than {}", usize::MAX),
"KeyLocalRef decoding",
);
0
};
Ok(Self {
local_ref,
key_offset,
Expand Down