#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Oid<'a> {
content_octets: &'a [u8],
}
impl<'a> Oid<'a> {
pub const fn new(content_octets: &'a [u8]) -> Self {
Self { content_octets }
}
pub fn as_bytes(&self) -> &[u8] {
self.content_octets
}
}
impl<'a> From<&'a [u8]> for Oid<'a> {
fn from(content_octets: &'a [u8]) -> Self {
Self::new(content_octets)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn new_and_as_bytes_round_trip() {
let octets: &[u8] = &[0x2a, 0x86, 0x48];
assert_eq!(Oid::new(octets).as_bytes(), octets);
}
#[test]
fn from_slice_matches_new() {
let octets: &[u8] = &[1, 2, 3];
let oid: Oid = octets.into();
assert_eq!(oid, Oid::new(octets));
assert_eq!(oid.as_bytes(), octets);
}
}