use crate::ber;
use crate::Error;
pub const OID_REQUEST: &str = "1.2.840.113556.1.4.841";
pub const OID_RESPONSE: &str = "1.2.840.113556.1.4.842";
pub const OBJECT_SECURITY: u32 = 0x1;
pub const ANCESTORS_FIRST_ORDER: u32 = 0x800;
pub const PUBLIC_DATA_ONLY: u32 = 0x2000;
pub const INCREMENTAL_VALUES: u32 = 0x80000000;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DirSyncControl {
pub flags: u32,
pub max_attribute_count: u32,
pub cookie: Vec<u8>,
}
impl DirSyncControl {
pub fn initial(flags: u32, max_attribute_count: u32) -> Self {
Self {
flags,
max_attribute_count,
cookie: Vec::new(),
}
}
pub fn encode(&self) -> Vec<u8> {
let mut body = Vec::with_capacity(16);
ber::write_u32(&mut body, self.flags);
ber::write_u32(&mut body, self.max_attribute_count);
ber::write_octet_string(&mut body, &self.cookie);
ber::wrap_sequence(&body)
}
pub fn decode(buf: &[u8]) -> Result<Self, Error> {
let (inner, _) = ber::read_sequence(buf)?;
let (flags, c1) = ber::read_u32(inner)?;
let (max_attribute_count, c2) = ber::read_u32(&inner[c1..])?;
let (cookie, _) = ber::read_octet_string(&inner[c1 + c2..])?;
Ok(Self {
flags,
max_attribute_count,
cookie: cookie.to_vec(),
})
}
}