Skip to content

Commit

Permalink
der: add ErrorKind::TagNumberInvalid (#156)
Browse files Browse the repository at this point in the history
Handles the specific case that the lower 5-bits of a tag are all `1`.

This is a bit different from the `ErrorKind::TagUnknown` previously
used, in that it specifically related to an unsupported BER encoding.
  • Loading branch information
tarcieri authored Oct 30, 2021
1 parent f53d1d7 commit 5e6e69d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions der/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ pub enum ErrorKind {
/// Unknown tag mode.
TagModeUnknown,

/// Invalid tag number.
///
/// The "tag number" is the lower 5-bits of a tag's octet.
/// This error occurs in the case that all 5-bits are set to `1`,
/// which indicates a multi-byte tag which is unsupported by this library.
TagNumberInvalid,

/// Unexpected tag.
TagUnexpected {
/// Tag the decoder was expecting (if there is a single such tag).
Expand Down Expand Up @@ -328,6 +335,7 @@ impl fmt::Display for ErrorKind {
#[cfg(feature = "std")]
ErrorKind::PermissionDenied => f.write_str("permission denied"),
ErrorKind::TagModeUnknown => write!(f, "unknown tag mode"),
ErrorKind::TagNumberInvalid => write!(f, "invalid tag number"),
ErrorKind::TagUnexpected { expected, actual } => {
write!(f, "unexpected ASN.1 DER tag: ")?;

Expand Down
2 changes: 1 addition & 1 deletion der/src/tag/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl TryFrom<u8> for TagNumber {
fn try_from(byte: u8) -> Result<Self> {
match byte {
0..=Self::MAX => Ok(Self(byte)),
_ => Err(ErrorKind::TagUnknown { byte }.into()),
_ => Err(ErrorKind::TagNumberInvalid.into()),
}
}
}
Expand Down

0 comments on commit 5e6e69d

Please sign in to comment.