sddl 0.1.9

a library to parse and analyse SDDL Strings
Documentation
pub mod flags;
use binrw::binrw;
pub use flags::*;
use getset::Getters;
use serde::Serialize;

use crate::*;
pub const ACE_HEADER_SIZE: u16 = 8;

#[binrw]
#[derive(Eq, PartialEq, Getters, Clone, Copy, Debug, Serialize)]
#[getset(get = "pub")]
pub struct Header {
    /// An unsigned 8-bit integer that specifies a set of ACE type-specific
    /// control flags.
    ace_flags: ace::header::Flags,

    /// An unsigned 16-bit integer that specifies the size, in bytes, of the
    /// ACE. The AceSize field can be greater than the sum of the individual
    /// fields, but MUST be a multiple of 4 to ensure alignment on a DWORD
    /// boundary. In cases where the AceSize field encompasses additional data
    /// for the callback ACEs types, that data is implementation-specific.
    /// Otherwise, this additional data is not interpreted and MUST be ignored.
    #[brw(assert(ace_size%4 == 0))]
    #[serde(skip)]
    ace_size: u16,

    mask: AccessMask,

    #[br(calc=std::cmp::min(0, 4-(ace_size%4)))]
    #[bw(ignore)]
    #[serde(skip)]
    expected_padding: u16,
}

impl Header {
    pub fn new(
        ace_flags: ace::header::Flags,
        ace_size_without_header: u16,
        mask: AccessMask,
    ) -> Self {
        // make sure the size is a multiple of 4

        let expected_padding = std::cmp::min(0, 4 - (ace_size_without_header % 4));

        let ace_size = ACE_HEADER_SIZE + ace_size_without_header + expected_padding;
        Self {
            ace_flags,
            ace_size,
            mask,
            expected_padding,
        }
    }
}