use crate::ber;
use crate::Error;
pub const OID: &str = "1.2.840.113556.1.4.801";
pub const OWNER: u32 = 0x1;
pub const GROUP: u32 = 0x2;
pub const DACL: u32 = 0x4;
pub const SACL: u32 = 0x8;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SdFlags(pub u32);
impl SdFlags {
pub const fn new(bits: u32) -> Self {
Self(bits)
}
pub const fn owner_dacl() -> Self {
Self(OWNER | DACL)
}
pub const fn sacl() -> Self {
Self(SACL)
}
pub const fn all() -> Self {
Self(OWNER | GROUP | DACL | SACL)
}
pub fn encode(&self) -> Vec<u8> {
let mut body = Vec::with_capacity(6);
ber::write_u32(&mut body, self.0);
ber::wrap_sequence(&body)
}
pub fn decode(buf: &[u8]) -> Result<Self, Error> {
let (inner, _) = ber::read_sequence(buf)?;
let (v, _) = ber::read_u32(inner)?;
Ok(Self(v))
}
}