1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use alloc::vec::Vec;
/// Represents a complete encoded ASN.1 value of any type (an open type in modern ASN.1).
/// Commonly associated with an [`ObjectIdentifier`][crate::types::ObjectIdentifier].
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Any {
pub(crate) contents: Vec<u8>,
}
impl Any {
/// Creates a new wrapper around the opaque value.
#[must_use]
pub fn new(contents: Vec<u8>) -> Self {
Self { contents }
}
/// Provides the raw representation of the value as bytes.
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
&self.contents
}
/// Converts `Self` into the raw representation of the value.
#[must_use]
pub fn into_bytes(self) -> Vec<u8> {
self.contents
}
}
impl AsRef<[u8]> for Any {
fn as_ref(&self) -> &[u8] {
self.contents.as_ref()
}
}
impl From<Vec<u8>> for Any {
fn from(value: Vec<u8>) -> Self {
Any::new(value)
}
}