Skip to content

Commit 06536b8

Browse files
More error handling
1 parent 4bce78c commit 06536b8

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ impl Decode<'_, ProblemReport> for CborRoleData {
7777
data.encryption_key = decode_encryption_key(d, context, report);
7878
},
7979
RoleDataInt::PaymentKey => {
80-
data.payment_key =
81-
Some(decode_helper(d, "PaymentKey in RoleData", &mut ())?);
80+
data.payment_key = decode_payment_key(d, context, report);
8281
},
8382
}
8483
} else {
@@ -166,3 +165,17 @@ fn decode_encryption_key(
166165
},
167166
}
168167
}
168+
169+
/// Decodes a payment key.
170+
fn decode_payment_key(d: &mut Decoder, context: &str, report: &ProblemReport) -> Option<u16> {
171+
match decode_helper(d, "PaymentKey in RoleData", &mut ()) {
172+
Ok(v) => Some(v),
173+
Err(e) => {
174+
report.other(
175+
&format!("Unable to decode role payment key: {e:?}"),
176+
context,
177+
);
178+
None
179+
},
180+
}
181+
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,16 @@ impl Decode<'_, DecodeContext<'_, '_>> for X509Chunks {
6868

6969
// Decode the decompressed data.
7070
let mut decoder = Decoder::new(&decompressed);
71-
let chunk_data = Cip509RbacMetadata::decode(&mut decoder, decode_context).map_err(|e| {
72-
decode::Error::message(format!("Failed to decode Cip509 metadata: {e:?}"))
73-
})?;
71+
let chunk_data = match Cip509RbacMetadata::decode(&mut decoder, decode_context) {
72+
Ok(d) => d,
73+
Err(e) => {
74+
decode_context.report.other(
75+
&format!("Failed to decode: {e:?}"),
76+
"Cip509 chunked metadata",
77+
);
78+
return Ok(Self(None));
79+
},
80+
};
7481

7582
Ok(X509Chunks(Some(chunk_data)))
7683
}

0 commit comments

Comments
 (0)