use crate::ops::security_detection::detector_support::{magic, DetectionError, MagicFinding};
pub const SPEC_TOML: &str = r#"schema_version = 1
id = "security_detection.file_magic_detect"
archetype = "match-bytes-pattern"
display_name = "File Magic Detect"
summary = "Returns magic-id and confidence pairs for known file signatures."
category = "C"
[intrinsic]
wgsl = "security_detection_file_magic_detect"
[signature]
inputs = ["Bytes", "Bytes"]
output = "Bytes"
laws = []
equivalence_classes = ["elf", "pe", "archive", "unknown", "t47_cap"]
workgroup_size = [64, 1, 1]
tags = ["security-detection", "file-magic", "t47"]
fixtures_dir = "fixtures/"
"#;
pub const REFERENCE_VECTORS_TOML: &str = r#"[[case]]
name = "positive_elf"
input_hex = "7f454c4602010100"
expected = [{ magic_id = 2, confidence = 100 }]
[[case]]
name = "negative_unknown"
input = "plain text"
expected = []
"#;
pub mod lowering {
#[must_use]
pub const fn source() -> &'static str {
r#"@compute @workgroup_size(64)
pub fn file_magic_detect() {
if (starts_with("MZ")) { emit_magic(1u, 80u); }
if (starts_with("\x7fELF")) { emit_magic(2u, 100u); }
if (starts_with("\xfe\xed\xfa\xce")) { emit_magic(3u, 100u); }
if (starts_with("\xfe\xed\xfa\xcf")) { emit_magic(4u, 100u); }
if (starts_with("\xca\xfe\xba\xbe")) { emit_magic(5u, 100u); }
if (starts_with("PK\x03\x04")) { emit_magic(6u, 95u); }
if (starts_with("\x1f\x8b")) { emit_magic(7u, 95u); }
if (starts_with("\x89PNG\r\n\x1a\n")) { emit_magic(8u, 100u); }
if (starts_with("%PDF-")) { emit_magic(9u, 100u); }
}"#
}
}
pub fn file_magic_detect(input: &[u8]) -> Result<Vec<MagicFinding>, DetectionError> {
magic::file_magic_detect(input)
}
pub mod implementation {
pub use super::file_magic_detect;
pub mod kernel {
pub use super::super::file_magic_detect;
}
pub mod lowering {
pub mod wgsl {
pub use super::super::super::lowering::source;
}
}
}