Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/gunnar

fuzz/src/storage.rs

//! `crate::storage`, named as in gunnar-server, so the scanner's own `pub(in crate::storage)`
//! test fixtures compile here unchanged.

#[path = "../../crates/gunnar-server/src/storage/pack_end.rs"]
#[allow(dead_code)]
pub(crate) mod pack_end;

/// Feed `pack` to the scanner in `step`-byte chunks, the way `fill_buf` hands a
/// pushed pack over. `true` when the scanner saw the whole pack, trailer included.
pub(crate) fn scan(pack: &[u8], hash_len: usize, step: usize) -> bool {
    let mut scanner = pack_end::PackScanner::new(hash_len);
    let mut at = 0;
    while !scanner.done() && at < pack.len() {
        let end = (at + step).min(pack.len());
        match scanner.feed(&pack[at..end]) {
            Ok(used) => {
                assert!(
                    used <= end - at,
                    "the scanner claimed more bytes than it was shown"
                );
                if used < end - at {
                    assert!(scanner.done(), "a short count before the trailer");
                }
                at += used;
            }
            Err(_) => return false,
        }
    }
    let _ = scanner.header();
    let _ = scanner.waiting_for();
    scanner.done()
}