firehazard 0.0.0-2022-09-10

Unopinionated low level API bindings focused on soundness, safety, and stronger types over raw FFI.
Documentation
use crate::*;

use winapi::um::winnt::*;

use core::marker::PhantomData;
use core::mem::align_of;



#[derive(Clone)] pub struct Iter<'a> {
    next_ace:   *mut ace::Header,
    count:      u32,
    ph:         PhantomData<(&'a ACL, &'a [ace::Header])>,
}

impl<'a> Iter<'a> {
    pub fn new(ptr: acl::Ptr<'a>) -> Self {
        Self {
            next_ace:   unsafe { ptr.as_pacl().add(1).cast() },
            count:      ptr.get_acl_size_information().AceCount,
            ph:         PhantomData
        }
    }

    pub fn as_ptr(&self) -> *mut ace::Header { self.next_ace }
}

impl<'a> Iterator for Iter<'a> {
    type Item = ace::Ptr<'a>;
    fn next(&mut self) -> Option<Self::Item> {
        if self.count == 0 { return None }
        let r = self.next_ace;
        let size = unsafe { (*r).size };
        self.count -= 1;
        self.next_ace = unsafe { (self.next_ace as *mut u8).add(size.into()).cast() };
        debug_assert!(self.next_ace as usize % align_of::<ace::Header>() == 0);
        Some(unsafe { ace::Ptr::from_raw_unchecked(r) })
    }
}