Skip to content

Commit 0a5071d

Browse files
committed
der: introduce an AnyLike trait to mark parameters
1 parent 6c42217 commit 0a5071d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

der/src/asn1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod utf8_string;
3131
mod videotex_string;
3232

3333
pub use self::{
34-
any::AnyRef,
34+
any::{AnyLike, AnyRef},
3535
bit_string::{BitStringIter, BitStringRef},
3636
choice::Choice,
3737
context_specific::{ContextSpecific, ContextSpecificRef},

der/src/asn1/any.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ use core::cmp::Ordering;
1111
#[cfg(feature = "alloc")]
1212
use crate::SliceWriter;
1313

14+
/// Trait representing value that will be serialized as Any
15+
pub trait AnyLike {
16+
/// Is this value an ASN.1 `NULL` value?
17+
fn is_null(&self) -> bool;
18+
}
19+
1420
/// ASN.1 `ANY`: represents any explicitly tagged ASN.1 value.
1521
///
1622
/// This is a zero-copy reference type which borrows from the input data.
@@ -74,11 +80,6 @@ impl<'a> AnyRef<'a> {
7480
Ok(decoder.finish(result)?)
7581
}
7682

77-
/// Is this value an ASN.1 `NULL` value?
78-
pub fn is_null(self) -> bool {
79-
self == Self::NULL
80-
}
81-
8283
/// Attempt to decode this value an ASN.1 `SEQUENCE`, creating a new
8384
/// nested reader and calling the provided argument with it.
8485
pub fn sequence<F, T, E>(self, f: F) -> Result<T, E>
@@ -93,6 +94,12 @@ impl<'a> AnyRef<'a> {
9394
}
9495
}
9596

97+
impl<'a> AnyLike for AnyRef<'a> {
98+
fn is_null(&self) -> bool {
99+
*self == Self::NULL
100+
}
101+
}
102+
96103
impl<'a> Choice<'a> for AnyRef<'a> {
97104
fn can_decode(_: Tag) -> bool {
98105
true
@@ -316,9 +323,8 @@ mod allocating {
316323
}
317324
}
318325

319-
impl Any {
320-
/// Is this value an ASN.1 `NULL` value?
321-
pub fn is_null(&self) -> bool {
326+
impl AnyLike for Any {
327+
fn is_null(&self) -> bool {
322328
self.owned_to_ref() == AnyRef::NULL
323329
}
324330
}

0 commit comments

Comments
 (0)