#![no_std]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png",
html_root_url = "https://docs.rs/const-oid/0.1.0"
)]
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms)]
#[cfg(test)]
extern crate std;
use core::fmt;
pub struct ObjectIdentifier {
nodes: &'static [u32],
}
impl ObjectIdentifier {
pub const fn new(nodes: &'static [u32]) -> Self {
Self { nodes }
}
}
impl AsRef<[u32]> for ObjectIdentifier {
fn as_ref(&self) -> &[u32] {
self.nodes
}
}
impl fmt::Display for ObjectIdentifier {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for (i, node) in self.as_ref().iter().enumerate() {
write!(f, "{}", node)?;
if i < self.as_ref().len() - 1 {
write!(f, ".")?;
}
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::ObjectIdentifier;
use std::string::ToString;
const EXAMPLE_OID: ObjectIdentifier = ObjectIdentifier::new(&[1, 2, 840, 10045, 3, 1, 7]);
#[test]
fn display_test() {
let oid = EXAMPLE_OID.to_string();
assert_eq!(oid, "1.2.840.10045.3.1.7");
}
}