use crate::{ImageSbat, ParseError, RevocationSbat};
use ascii::AsciiString;
use core::ops::Deref;
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct ImageSbatOwned(AsciiString);
impl ImageSbatOwned {
pub fn parse(input: &[u8]) -> Result<Self, ParseError> {
let sbat = ImageSbat::parse(input)?;
Ok(Self(sbat.as_csv().to_ascii_string()))
}
}
impl Deref for ImageSbatOwned {
type Target = ImageSbat;
fn deref(&self) -> &Self::Target {
ImageSbat::from_ascii_str_unchecked(&self.0)
}
}
impl PartialEq<&ImageSbat> for ImageSbatOwned {
fn eq(&self, other: &&ImageSbat) -> bool {
&**self == *other
}
}
impl PartialEq<ImageSbatOwned> for &ImageSbat {
fn eq(&self, other: &ImageSbatOwned) -> bool {
*self == &**other
}
}
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct RevocationSbatOwned(AsciiString);
impl RevocationSbatOwned {
pub fn parse(input: &[u8]) -> Result<Self, ParseError> {
let sbat = RevocationSbat::parse(input)?;
Ok(Self(sbat.as_csv().to_ascii_string()))
}
}
impl Deref for RevocationSbatOwned {
type Target = RevocationSbat;
fn deref(&self) -> &Self::Target {
RevocationSbat::from_ascii_str_unchecked(&self.0)
}
}
impl PartialEq<&RevocationSbat> for RevocationSbatOwned {
fn eq(&self, other: &&RevocationSbat) -> bool {
&**self == *other
}
}
impl PartialEq<RevocationSbatOwned> for &RevocationSbat {
fn eq(&self, other: &RevocationSbatOwned) -> bool {
*self == &**other
}
}
#[cfg(test)]
mod tests {
use super::*;
const CSV: &[u8] = b"compA,1\ncompB,2\ncompC,3";
#[test]
fn test_image_sbat_owned() {
let r1 = ImageSbat::parse(CSV).unwrap();
let r2 = ImageSbatOwned::parse(CSV).unwrap();
assert_eq!(r1, r2);
assert_eq!(r2, r1);
}
#[test]
fn test_revocation_sbat_owned() {
let r1 = RevocationSbat::parse(CSV).unwrap();
let r2 = RevocationSbatOwned::parse(CSV).unwrap();
assert_eq!(r1, r2);
assert_eq!(r2, r1);
}
}