vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
//! Catalog entry for `detect_uuid`.

use crate::ops::security_detection::detector_support::{spans, ByteSpan, DetectionError};

/// Embedded operation spec formerly stored in metadata/spec.toml.
pub const SPEC_TOML: &str = r#"schema_version = 1
id = "security_detection.detect_uuid"
archetype = "match-bytes-pattern"
display_name = "Detect UUID"
summary = "Returns offset-length spans for canonical UUID byte sequences."
category = "C"

[intrinsic]
wgsl = "security_detection_detect_uuid"

[signature]
inputs = ["Bytes", "Bytes"]
output = "Bytes"

laws = []
equivalence_classes = ["canonical", "missing_dash", "bad_hex", "t47_cap"]
workgroup_size = [64, 1, 1]
tags = ["security-detection", "uuid", "secret-scan", "t47"]
fixtures_dir = "fixtures/"
"#;

/// Embedded reference vectors formerly stored in fixtures/reference-vectors.toml.
pub const REFERENCE_VECTORS_TOML: &str = r#"[[case]]
name = "positive_uuid"
input = "id 550e8400-e29b-41d4-a716-446655440000 ok"
expected_spans = [{ offset = 3, len = 36 }]

[[case]]
name = "negative_missing_dash"
input = "id 550e8400e29b41d4a716446655440000 ok"
expected_spans = []
"#;

/// WGSL lowering source for this detector.
pub mod lowering {
    /// Return the detector-specific WGSL source.
    #[must_use]
    pub const fn source() -> &'static str {
        r#"@compute @workgroup_size(64)
pub fn detect_uuid(@builtin(global_invocation_id) gid: vec3<u32>) {
    let i = gid.x;
    if (i + 36u > input_len) { return; }
    for (var n = 0u; n < 36u; n = n + 1u) {
        let dash = n == 8u || n == 13u || n == 18u || n == 23u;
        if ((dash && input[i + n] != 45u) || (!dash && !is_hex(input[i + n]))) { return; }
    }
    if (token_boundary(i, i + 36u)) { emit_span(i, 36u); }
}"#
    }
}

/// Return canonical UUID spans in 8-4-4-4-12 form.
///
/// # Errors
///
/// Returns `Fix: ...` when input exceeds 64 MiB.
pub fn detect_uuid(input: &[u8]) -> Result<Vec<ByteSpan>, DetectionError> {
    spans::uuid_spans(input)
}

/// Compatibility surface for the previous generated implementation module.
pub mod implementation {
    pub use super::detect_uuid;
    /// Compatibility module for callers that used the generated kernel path.
    pub mod kernel {
        pub use super::super::detect_uuid;
    }

    /// Compatibility module for callers that used the generated lowering path.
    pub mod lowering {
        /// Compatibility module for callers that used `implementation::lowering::wgsl`.
        pub mod wgsl {
            pub use super::super::super::lowering::source;
        }
    }
}