rasn/types/
any.rs

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