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

der: add Any::null() #226

Merged
merged 1 commit into from
Nov 15, 2021
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
12 changes: 10 additions & 2 deletions der/src/asn1/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ impl<'a> Any<'a> {
decoder.finish(result)
}

/// Is this value an ASN.1 NULL value?
/// Is this value an ASN.1 `NULL` value?
pub fn is_null(self) -> bool {
Null::try_from(self).is_ok()
self == Any::null()
}

/// Create an [`Any`] value representing ASN.1 `NULL`.
pub const fn null() -> Self {
Any {
tag: Tag::Null,
value: ByteSlice::empty(),
}
}

/// Attempt to decode an ASN.1 `BIT STRING`.
Expand Down
8 changes: 8 additions & 0 deletions der/src/byte_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ impl<'a> ByteSlice<'a> {
pub fn is_empty(self) -> bool {
self.len() == Length::ZERO
}

/// Create an empty [`ByteSlice`].
pub const fn empty() -> Self {
Self {
length: Length::ZERO,
inner: &[],
}
}
}

impl AsRef<[u8]> for ByteSlice<'_> {
Expand Down