Skip to main content

SniffWindow

Struct SniffWindow 

Source
pub struct SniffWindow<'a> { /* private fields */ }
Expand description

A bounded window of bytes handed to a prober. Holds a prefix of the source (the head) plus the absolute base offset that prefix starts at, so a prober reads magic without an unbounded scan and without touching the source directly. It also carries the source’s total_len and a tail window (the last N bytes), so a prober can match a trailer signature — e.g. the DMG koly footer at total_len - 512 — that the head window never reaches.

Implementations§

Source§

impl<'a> SniffWindow<'a>

Source

pub fn new(base: u64, bytes: &'a [u8]) -> Self

A head-only window of bytes that begins at absolute base in the source. total_len is inferred as base + bytes.len() and the tail is empty — existing head-magic probers are unaffected.

Source

pub fn with_tail( base: u64, bytes: &'a [u8], total_len: u64, tail: &'a [u8], ) -> Self

A window carrying both a head (bytes at base) and a tail (the last bytes of the source), plus the source’s total_len. tail must end at total_len for the from-end probes to be correct.

Source

pub fn base(&self) -> u64

The absolute offset the window starts at.

Source

pub fn bytes(&self) -> &[u8]

The window (head) bytes.

Source

pub fn total_len(&self) -> u64

The total length of the source this window was sniffed from.

Source

pub fn at(&self, off: usize, n: usize) -> Option<&[u8]>

The n bytes at window-relative off, or None if out of range. Never panics — the panic-free way to test a magic.

Source

pub fn has_magic(&self, off: usize, magic: &[u8]) -> bool

True when the window has magic at window-relative off.

Source

pub fn tail_at(&self, from_end: usize, n: usize) -> Option<&[u8]>

The n bytes of the tail beginning from_end bytes before the source’s end, or None when the tail is too short. Never panics.

Source

pub fn has_magic_from_end(&self, from_end: usize, magic: &[u8]) -> bool

True when the tail carries magic starting from_end bytes before the source’s end (e.g. has_magic_from_end(512, b"koly") for a DMG footer). False if the tail is too short — the panic-free trailer probe.

Auto Trait Implementations§

§

impl<'a> Freeze for SniffWindow<'a>

§

impl<'a> RefUnwindSafe for SniffWindow<'a>

§

impl<'a> Send for SniffWindow<'a>

§

impl<'a> Sync for SniffWindow<'a>

§

impl<'a> Unpin for SniffWindow<'a>

§

impl<'a> UnsafeUnpin for SniffWindow<'a>

§

impl<'a> UnwindSafe for SniffWindow<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.