oxipkx 1.0.0

Zero-dependency parser for id Tech 3/4 PK3/PK4 files (Quake III, Doom 3).
Documentation
//! Quake III (id Tech 3) PK3 extras: the two pak block checksums the engine
//! derives for content identification and pure-server validation.

use crate::md4::block_checksum;
use crate::Archive;

/// flatten a CRC feed (optionally seeded) into the little-endian byte buffer
/// the block checksum runs over.
fn feed_bytes(seed: Option<i32>, crcs: &[u32]) -> Vec<u8> {
    let mut buffer = Vec::with_capacity((crcs.len() + 1) * 4);
    if let Some(seed_value) = seed {
        buffer.extend_from_slice(&seed_value.to_le_bytes());
    }
    for &crc in crcs {
        buffer.extend_from_slice(&crc.to_le_bytes());
    }
    buffer
}

impl Archive {
    /// content **checksum**: block checksum over the CRC-32 of every nonzero
    /// entry (in central-directory order), excluding any seed. identifies the
    /// archive's content.
    pub fn checksum(&self) -> u32 {
        block_checksum(&feed_bytes(None, &self.content_crc_feed()))
    }

    /// **pure checksum**: block checksum over `seed` followed by the same CRC
    /// list. used for pure-server validation, where clients may only load
    /// archives whose checksums appear on the server's allowed list. `seed` is
    /// the server-provided checksum feed value.
    pub fn pure_checksum(&self, seed: i32) -> u32 {
        block_checksum(&feed_bytes(Some(seed), &self.content_crc_feed()))
    }
}