vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use vyre::ops::compression::{
    deflate_decompress::DeflateDecompress, gzip_decompress::GzipDecompress, lz4::Lz4Decompress,
    zlib_decompress::ZlibDecompress, zstd::ZstdDecompress,
};

use super::assert_structural_spec;

#[test]
fn compression_ops_validate_lower_and_compose_non_empty_programs() {
    for spec in [
        &Lz4Decompress::SPEC,
        &ZstdDecompress::SPEC,
        &DeflateDecompress::SPEC,
        &GzipDecompress::SPEC,
        &ZlibDecompress::SPEC,
    ] {
        assert_structural_spec(spec);
    }
}

#[test]
fn wave_a_decompress_wrappers_match_known_vectors_and_reject_bombs() {
    let deflate = hex("cb48cdc9c90700");
    assert_eq!(
        vyre::ops::compression::deflate_decompress::kernel::decompress_bytes(&deflate).unwrap(),
        b"hello"
    );

    let zlib = hex("789ccb48cdc9c90700062c0215");
    assert_eq!(
        vyre::ops::compression::zlib_decompress::kernel::decompress_bytes(&zlib).unwrap(),
        b"hello"
    );

    let gzip = hex("1f8b0800000000000003cb48cdc9c9070086a6103605000000");
    assert_eq!(
        vyre::ops::compression::gzip_decompress::kernel::decompress_bytes(&gzip).unwrap(),
        b"hello"
    );

    let gzip_bomb = hex("1f8b0800000000000003010000ffff0000000000000100");
    let error =
        vyre::ops::compression::gzip_decompress::kernel::decompress_bytes(&gzip_bomb).unwrap_err();
    assert!(error.contains("Fix:"));
    assert!(error.contains("bomb"));
}

fn hex(input: &str) -> Vec<u8> {
    input
        .as_bytes()
        .chunks_exact(2)
        .map(|pair| {
            let hi = from_hex(pair[0]);
            let lo = from_hex(pair[1]);
            (hi << 4) | lo
        })
        .collect()
}

fn from_hex(byte: u8) -> u8 {
    match byte {
        b'0'..=b'9' => byte - b'0',
        b'a'..=b'f' => byte - b'a' + 10,
        b'A'..=b'F' => byte - b'A' + 10,
        _ => panic!("test vector must be hex"),
    }
}