Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust/rbac-registration): Fix deleted tag cbor decoding #249

Merged
merged 3 commits into from
Mar 24, 2025
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
5 changes: 4 additions & 1 deletion rust/rbac-registration/src/cardano/cip509/rbac/certs/c509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ impl Decode<'_, ProblemReport> for C509Cert {
minicbor::data::Type::Tag => {
let tag = decode_tag(d, "C509Cert")?;
match tag {
t if t == KeyTag::Deleted.tag() => Ok(Self::Deleted),
t if t == KeyTag::Deleted.tag() => {
d.undefined()?;
Ok(Self::Deleted)
},
_ => Err(decode::Error::message("Unknown tag for C509Cert")),
}
},
Expand Down
5 changes: 4 additions & 1 deletion rust/rbac-registration/src/cardano/cip509/rbac/certs/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ impl Decode<'_, ProblemReport> for X509DerCert {
minicbor::data::Type::Tag => {
let tag = decode_tag(d, "X509DerCert")?;
match tag {
t if t == KeyTag::Deleted.tag() => Ok(Self::Deleted),
t if t == KeyTag::Deleted.tag() => {
d.undefined()?;
Ok(Self::Deleted)
},
_ => Err(decode::Error::message("Unknown tag for X509DerCert")),
}
},
Expand Down
11 changes: 9 additions & 2 deletions rust/rbac-registration/src/cardano/cip509/rbac/pub_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ impl Decode<'_, ProblemReport> for SimplePublicKeyType {
minicbor::data::Type::Tag => {
let tag = decode_tag(d, "SimplePublicKeyType")?;
match tag {
t if t == KeyTag::Deleted.tag() => Ok(Self::Deleted),
t if t == KeyTag::Deleted.tag() => {
d.undefined()?;
Ok(Self::Deleted)
},
t if t == KeyTag::Ed25519.tag() => {
let bytes = decode_bytes(d, "Ed25519 SimplePublicKeyType")?;
let mut ed25519 = [0u8; 32];
Expand All @@ -42,7 +45,11 @@ impl Decode<'_, ProblemReport> for SimplePublicKeyType {
)))
}
},
_ => Err(decode::Error::message("Unknown tag for Self")),
_ => {
Err(decode::Error::message(
"Unknown tag for SimplePublicKeyType",
))
},
}
},
minicbor::data::Type::Undefined => {
Expand Down
5 changes: 3 additions & 2 deletions rust/rbac-registration/src/cardano/cip509/rbac/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ pub(crate) enum KeyTag {
/// Deleted Key tag 31.
Deleted,
/// Ed25519 Key tag 32773.
/// <https://cips.cardano.org/cip/CIP-0115>
Ed25519,
}

impl KeyTag {
/// Get the tag value.
pub(crate) fn tag(self) -> Tag {
match self {
KeyTag::Deleted => Tag::new(0x31),
KeyTag::Ed25519 => Tag::new(0x8005),
KeyTag::Deleted => Tag::new(31),
KeyTag::Ed25519 => Tag::new(32773),
}
}
}