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
use alloc::vec::Vec;

/// Represents a complete encoded ASN.1 value of any type. Usually identified
/// 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.
    pub fn new(contents: Vec<u8>) -> Self {
        Self { contents }
    }

    /// Provides the raw representation of the value as bytes.
    pub fn as_bytes(&self) -> &[u8] {
        &self.contents
    }

    /// Converts `Self` into the raw representation of the value.
    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)
    }
}