SPB Git

Repository Public License

TestSupport.swift 20.4 KB 342 lines swift

1// ORIX Secure2// File: Packages/ORIXFileInspection/Tests/ORIXFileInspectionTests/TestSupport.swift3// Description: Test fixtures built in code: temporary folders, a hand-written ZIP and TAR writer, minimal samples of4//              every recognised format, a deterministic random generator and the wording check applied to findings.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import Foundation9import ORIXSecureModel10import Testing11@testable import ORIXFileInspection1213final class TempDir: Sendable {14    let url: URL1516    init() throws {17        url = FileManager.default.temporaryDirectory.appendingPathComponent("orix-fi-" + UUID().uuidString, isDirectory: true)18        try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)19    }2021    deinit {22        _ = chmod(url.path, 0o755)23        try? FileManager.default.removeItem(at: url)24    }2526    @discardableResult27    func write(_ name: String, _ bytes: [UInt8]) throws -> URL {28        let file = url.appendingPathComponent(name)29        try FileManager.default.createDirectory(at: file.deletingLastPathComponent(), withIntermediateDirectories: true)30        try Data(bytes).write(to: file)31        return file32    }33}3435struct SplitMix64: RandomNumberGenerator {36    var state: UInt6437    init(seed: UInt64) { state = seed }38    mutating func next() -> UInt64 {39        state &+= 0x9E37_79B9_7F4A_7C1540        var z = state41        z = (z ^ (z >> 30)) &* 0xBF58_476D_1CE4_E5B942        z = (z ^ (z >> 27)) &* 0x94D0_49BB_1331_11EB43        return z ^ (z >> 31)44    }45}4647func bytes(_ text: String) -> [UInt8] { Array(text.utf8) }48func le16(_ value: UInt16) -> [UInt8] { [UInt8(value & 0xFF), UInt8(value >> 8)] }49func le32(_ value: UInt32) -> [UInt8] { (0..<4).map { UInt8((value >> (8 * UInt32($0))) & 0xFF) } }50func le64(_ value: UInt64) -> [UInt8] { (0..<8).map { UInt8((value >> (8 * UInt64($0))) & 0xFF) } }51func be16(_ value: UInt16) -> [UInt8] { [UInt8(value >> 8), UInt8(value & 0xFF)] }52func be32(_ value: UInt32) -> [UInt8] { Array(le32(value).reversed()) }53func zeros(_ count: Int) -> [UInt8] { [UInt8](repeating: 0, count: count) }5455// MARK: ZIP writer5657struct ZipEntrySpec {58    var name: String59    var data: [UInt8] = []60    var method: UInt16 = 061    var flags: UInt16 = 0x080062    var declaredCompressed: UInt64?63    var declaredUncompressed: UInt64?64    var externalAttributes: UInt32 = 065    var madeBy: UInt16 = 0x031E66    /// Reuse the local header of an earlier entry (overlapping data).67    var sharesDataWith: Int?68    /// Write sizes through a ZIP64 extra field.69    var zip64: Bool = false7071    init(_ name: String, _ data: [UInt8] = [], method: UInt16 = 0, flags: UInt16 = 0x0800, declaredCompressed: UInt64? = nil,72         declaredUncompressed: UInt64? = nil, externalAttributes: UInt32 = 0, madeBy: UInt16 = 0x031E, sharesDataWith: Int? = nil, zip64: Bool = false) {73        self.name = name74        self.data = data75        self.method = method76        self.flags = flags77        self.declaredCompressed = declaredCompressed78        self.declaredUncompressed = declaredUncompressed79        self.externalAttributes = externalAttributes80        self.madeBy = madeBy81        self.sharesDataWith = sharesDataWith82        self.zip64 = zip6483    }84}8586/// A ZIP archive written by hand. Entries are stored; the central directory can declare anything.87func buildZip(_ entries: [ZipEntrySpec], declaredCount: UInt64? = nil, zip64Record: Bool = false, comment: [UInt8] = []) -> [UInt8] {88    var out: [UInt8] = []89    var offsets: [UInt64] = []90    for entry in entries {91        if let shared = entry.sharesDataWith {92            offsets.append(offsets[shared])93            continue94        }95        offsets.append(UInt64(out.count))96        let name = bytes(entry.name)97        out += [0x50, 0x4B, 0x03, 0x04] + le16(20) + le16(entry.flags) + le16(entry.method) + le16(0) + le16(0)98        out += le32(0) + le32(UInt32(entry.data.count)) + le32(UInt32(entry.data.count)) + le16(UInt16(name.count)) + le16(0)99        out += name + entry.data100    }101    let directoryOffset = UInt64(out.count)102    for (index, entry) in entries.enumerated() {103        let name = bytes(entry.name)104        let compressed = entry.declaredCompressed ?? UInt64(entry.data.count)105        let uncompressed = entry.declaredUncompressed ?? UInt64(entry.data.count)106        var extra: [UInt8] = []107        if entry.zip64 { extra = le16(0x0001) + le16(16) + le64(uncompressed) + le64(compressed) }108        out += [0x50, 0x4B, 0x01, 0x02] + le16(entry.madeBy) + le16(20) + le16(entry.flags) + le16(entry.method) + le16(0) + le16(0)109        out += le32(0)110        out += entry.zip64 ? le32(0xFFFF_FFFF) + le32(0xFFFF_FFFF) : le32(UInt32(truncatingIfNeeded: compressed)) + le32(UInt32(truncatingIfNeeded: uncompressed))111        out += le16(UInt16(name.count)) + le16(UInt16(extra.count)) + le16(0) + le16(0) + le16(0)112        out += le32(entry.externalAttributes) + le32(UInt32(offsets[index]))113        out += name + extra114    }115    let directorySize = UInt64(out.count) - directoryOffset116    let count = declaredCount ?? UInt64(entries.count)117    if zip64Record {118        let recordOffset = UInt64(out.count)119        out += [0x50, 0x4B, 0x06, 0x06] + le64(44) + le16(45) + le16(45) + le32(0) + le32(0)120        out += le64(count) + le64(count) + le64(directorySize) + le64(directoryOffset)121        out += [0x50, 0x4B, 0x06, 0x07] + le32(0) + le64(recordOffset) + le32(1)122        out += [0x50, 0x4B, 0x05, 0x06] + le16(0) + le16(0) + le16(0xFFFF) + le16(0xFFFF) + le32(0xFFFF_FFFF) + le32(0xFFFF_FFFF)123    } else {124        out += [0x50, 0x4B, 0x05, 0x06] + le16(0) + le16(0) + le16(UInt16(truncatingIfNeeded: count)) + le16(UInt16(truncatingIfNeeded: count))125        out += le32(UInt32(directorySize)) + le32(UInt32(directoryOffset))126    }127    out += le16(UInt16(comment.count)) + comment128    return out129}130131func inspectZip(_ data: [UInt8], options: InspectionOptions = .init()) throws -> ZipInspection {132    try ZipInspector.inspect(source: DataByteSource(data), options: options)133}134135// MARK: TAR writer136137func tarHeader(name: String, size: Int, type: Character = "0", ustar: Bool = true) -> [UInt8] {138    var block = zeros(512)139    let nameBytes = Array(bytes(name).prefix(100))140    block.replaceSubrange(0..<nameBytes.count, with: nameBytes)141    block.replaceSubrange(100..<108, with: bytes("0000644\u{0}"))142    block.replaceSubrange(108..<116, with: bytes("0000000\u{0}"))143    block.replaceSubrange(116..<124, with: bytes("0000000\u{0}"))144    let octal = String(size, radix: 8)145    let sizeField = String(repeating: "0", count: 11 - octal.count) + octal + "\u{0}"146    block.replaceSubrange(124..<136, with: bytes(sizeField))147    block.replaceSubrange(136..<148, with: bytes("00000000000\u{0}"))148    block[156] = type.asciiValue ?? 0x30149    if ustar { block.replaceSubrange(257..<265, with: bytes("ustar\u{0}00")) }150    block.replaceSubrange(148..<156, with: [UInt8](repeating: 0x20, count: 8))151    let sum = block.reduce(0) { $0 + Int($1) }152    let sumText = String(sum, radix: 8)153    block.replaceSubrange(148..<156, with: bytes(String(repeating: "0", count: 6 - sumText.count) + sumText + "\u{0} "))154    return block155}156157func buildTar(_ entries: [(name: String, data: [UInt8], type: Character)]) -> [UInt8] {158    var out: [UInt8] = []159    for entry in entries {160        out += tarHeader(name: entry.name, size: entry.data.count, type: entry.type)161        out += entry.data162        out += zeros((512 - entry.data.count % 512) % 512)163    }164    return out + zeros(1024)165}166167// MARK: Samples168169struct Sample: Sendable, CustomTestStringConvertible {170    let name: String171    let bytes: [UInt8]172    let type: DetectedFileType173    var testDescription: String { name }174}175176enum Samples {177    static func ftyp(_ major: String, _ compatible: [String] = []) -> [UInt8] {178        let body = bytes("ftyp") + bytes(major) + be32(0) + compatible.flatMap { bytes($0) }179        return be32(UInt32(body.count + 4)) + body + be32(8) + bytes("free")180    }181182    static let png: [UInt8] = pngImage(width: 2, height: 2)183184    static func pngImage(width: UInt32, height: UInt32, trailing: [UInt8] = []) -> [UInt8] {185        var out: [UInt8] = [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]186        out += be32(13) + bytes("IHDR") + be32(width) + be32(height) + [8, 2, 0, 0, 0] + be32(0)187        out += be32(4) + bytes("IDAT") + [1, 2, 3, 4] + be32(0)188        out += be32(0) + bytes("IEND") + be32(0xAE42_6082)189        return out + trailing190    }191192    static func jpegImage(width: UInt16, height: UInt16, trailing: [UInt8] = []) -> [UInt8] {193        var out: [UInt8] = [0xFF, 0xD8, 0xFF, 0xE0] + be16(16) + bytes("JFIF\u{0}") + [1, 1, 0, 0, 1, 0, 1, 0, 0]194        out += [0xFF, 0xC0] + be16(17) + [8] + be16(height) + be16(width) + [3, 1, 0x11, 0, 2, 0x11, 1, 3, 0x11, 1]195        out += [0xFF, 0xDA] + be16(12) + [3, 1, 0, 2, 0x11, 3, 0x11, 0, 0x3F, 0] + [0x12, 0x34, 0x56, 0x78]196        out += [0xFF, 0xD9]197        return out + trailing198    }199200    static let pe: [UInt8] = {201        var out = bytes("MZ") + zeros(58) + le32(0x80) + zeros(64)202        out += bytes("PE\u{0}\u{0}") + le16(0x8664) + zeros(64)203        return out204    }()205206    static let ole2: [UInt8] = {207        var header: [UInt8] = [0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1] + zeros(16)208        header += le16(0x3E) + le16(3) + le16(0xFFFE) + le16(9) + le16(6) + zeros(6)209        header += le32(0) + le32(1) + le32(1) + le32(0) + le32(4096) + le32(0xFFFF_FFFE) + le32(0) + le32(0xFFFF_FFFE) + le32(0)210        header += [UInt8](repeating: 0xFF, count: 512 - header.count)211        return header + zeros(1024)212    }()213214    static let pdf: [UInt8] = bytes("%PDF-1.4\n1 0 obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n2 0 obj\n<< /Type /Pages /Kids [] /Count 0 >>\nendobj\ntrailer\n<< /Root 1 0 R >>\n%%EOF\n")215216    static let docx = buildZip([ZipEntrySpec("[Content_Types].xml", bytes("<Types/>")), ZipEntrySpec("word/document.xml", bytes("<w:document/>"))])217    static let plainZip = buildZip([ZipEntrySpec("readme.txt", bytes("hello")), ZipEntrySpec("folder/", []), ZipEntrySpec("folder/data.csv", bytes("a,b\n1,2\n"))])218219    static let mobileconfig = bytes("""220    <?xml version="1.0" encoding="UTF-8"?>221    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">222    <plist version="1.0"><dict><key>PayloadContent</key><array/><key>PayloadType</key><string>Configuration</string></dict></plist>223    """)224225    static let koly: [UInt8] = bytes("koly") + be32(4) + be32(512) + zeros(500)226227    static let all: [Sample] = [228        Sample(name: "document.pdf", bytes: pdf, type: .pdf),229        Sample(name: "image.png", bytes: png, type: .png),230        Sample(name: "photo.jpg", bytes: jpegImage(width: 4, height: 4), type: .jpeg),231        Sample(name: "anim87.gif", bytes: bytes("GIF87a") + le16(1) + le16(1) + zeros(8), type: .gif),232        Sample(name: "anim.gif", bytes: bytes("GIF89a") + le16(1) + le16(1) + zeros(8), type: .gif),233        Sample(name: "image.webp", bytes: bytes("RIFF") + le32(20) + bytes("WEBPVP8 ") + zeros(12), type: .webp),234        Sample(name: "photo.heic", bytes: ftyp("heic", ["mif1", "heic"]), type: .heic),235        Sample(name: "photo2.heic", bytes: ftyp("mif1", ["mif1", "heic"]), type: .heic),236        Sample(name: "photo.heif", bytes: ftyp("mif1", ["mif1"]), type: .heif),237        Sample(name: "photo.avif", bytes: ftyp("avif", ["mif1", "miaf"]), type: .avif),238        Sample(name: "scan.tif", bytes: [0x49, 0x49, 0x2A, 0x00] + le32(8) + zeros(8), type: .tiff),239        Sample(name: "scan-be.tiff", bytes: [0x4D, 0x4D, 0x00, 0x2A] + be32(8) + zeros(8), type: .tiff),240        Sample(name: "image.bmp", bytes: bytes("BM") + le32(70) + le32(0) + le32(54) + le32(40) + zeros(52), type: .bmp),241        Sample(name: "icon.ico", bytes: [0, 0, 1, 0, 1, 0, 16, 16, 0, 0, 1, 0, 32, 0] + le32(16) + le32(22) + zeros(16), type: .ico),242        Sample(name: "art.psd", bytes: bytes("8BPS") + be16(1) + zeros(20), type: .psd),243        Sample(name: "archive.zip", bytes: plainZip, type: .zip),244        Sample(name: "empty.zip", bytes: buildZip([]), type: .zip),245        Sample(name: "letter.docx", bytes: docx, type: .docx),246        Sample(name: "sheet.xlsx", bytes: buildZip([ZipEntrySpec("[Content_Types].xml", bytes("<Types/>")), ZipEntrySpec("xl/workbook.xml", bytes("<x/>"))]), type: .xlsx),247        Sample(name: "deck.pptx", bytes: buildZip([ZipEntrySpec("[Content_Types].xml", bytes("<Types/>")), ZipEntrySpec("ppt/presentation.xml", bytes("<p/>"))]), type: .pptx),248        Sample(name: "book.epub", bytes: buildZip([ZipEntrySpec("mimetype", bytes("application/epub+zip")), ZipEntrySpec("META-INF/container.xml", bytes("<c/>"))]), type: .epub),249        Sample(name: "text.odt", bytes: buildZip([ZipEntrySpec("mimetype", bytes("application/vnd.oasis.opendocument.text")), ZipEntrySpec("META-INF/manifest.xml", bytes("<m/>")), ZipEntrySpec("content.xml", bytes("<c/>"))]), type: .openDocument),250        Sample(name: "lib.jar", bytes: buildZip([ZipEntrySpec("META-INF/MANIFEST.MF", bytes("Manifest-Version: 1.0\n")), ZipEntrySpec("a/B.class", [0xCA, 0xFE, 0xBA, 0xBE])]), type: .jar),251        Sample(name: "app.apk", bytes: buildZip([ZipEntrySpec("AndroidManifest.xml", [3, 0, 8, 0]), ZipEntrySpec("classes.dex", bytes("dex\n035\u{0}")), ZipEntrySpec("META-INF/MANIFEST.MF", bytes("x"))]), type: .apk),252        Sample(name: "app.ipa", bytes: buildZip([ZipEntrySpec("Payload/"), ZipEntrySpec("Payload/Demo.app/Info.plist", bytes("bplist00")), ZipEntrySpec("Payload/Demo.app/Demo", [0xCF, 0xFA, 0xED, 0xFE])]), type: .ipa),253        Sample(name: "legacy.doc", bytes: ole2, type: .ole2),254        Sample(name: "note.rtf", bytes: bytes("{\\rtf1\\ansi Hello}"), type: .rtf),255        Sample(name: "data.gz", bytes: [0x1F, 0x8B, 0x08, 0x08, 0, 0, 0, 0, 0, 3] + bytes("data.txt\u{0}") + [3, 0] + le32(0) + le32(0), type: .gzip),256        Sample(name: "data.bz2", bytes: bytes("BZh9") + [0x31, 0x41, 0x59, 0x26, 0x53, 0x59] + zeros(8), type: .bzip2),257        Sample(name: "data.xz", bytes: [0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00, 0, 4] + zeros(8), type: .xz),258        Sample(name: "data.7z", bytes: [0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C, 0, 4] + zeros(24), type: .sevenZip),259        Sample(name: "old.rar", bytes: bytes("Rar!") + [0x1A, 0x07, 0x00] + zeros(13), type: .rar4),260        Sample(name: "new.rar", bytes: bytes("Rar!") + [0x1A, 0x07, 0x01, 0x00] + zeros(12), type: .rar5),261        Sample(name: "bundle.tar", bytes: buildTar([("a.txt", bytes("hello"), "0"), ("dir/", [], "5")]), type: .tar),262        Sample(name: "tool32", bytes: [0xFE, 0xED, 0xFA, 0xCE] + zeros(28), type: .machO),263        Sample(name: "tool64be", bytes: [0xFE, 0xED, 0xFA, 0xCF] + zeros(28), type: .machO),264        Sample(name: "tool32le", bytes: [0xCE, 0xFA, 0xED, 0xFE] + zeros(28), type: .machO),265        Sample(name: "tool64", bytes: [0xCF, 0xFA, 0xED, 0xFE] + zeros(28), type: .machO),266        Sample(name: "universal", bytes: [0xCA, 0xFE, 0xBA, 0xBE] + be32(2) + zeros(40) + zeros(64), type: .machOFat),267        Sample(name: "Main.class", bytes: [0xCA, 0xFE, 0xBA, 0xBE] + be16(0) + be16(52) + zeros(40), type: .javaClass),268        Sample(name: "program.elf", bytes: [0x7F, 0x45, 0x4C, 0x46, 2, 1, 1, 0] + zeros(56), type: .elf),269        Sample(name: "setup.exe", bytes: pe, type: .pe),270        Sample(name: "old.com", bytes: bytes("MZ") + zeros(58) + le32(0x4000) + zeros(64), type: .dosExecutable),271        Sample(name: "disk.dmg", bytes: [0x78, 0x9C] + zeros(600) + koly, type: .dmg),272        Sample(name: "store.sqlite", bytes: bytes("SQLite format 3\u{0}") + be16(4096) + zeros(82), type: .sqlite),273        Sample(name: "song.mp3", bytes: bytes("ID3") + [3, 0, 0, 0, 0, 0, 10] + zeros(16), type: .mp3),274        Sample(name: "raw.mp3", bytes: [0xFF, 0xFB, 0x90, 0x00] + zeros(64), type: .mp3),275        Sample(name: "clip.mp4", bytes: ftyp("isom", ["isom", "mp41"]), type: .mp4),276        Sample(name: "clip.mov", bytes: ftyp("qt  ", ["qt  "]), type: .quickTime),277        Sample(name: "old.mov", bytes: be32(16) + bytes("moov") + zeros(8), type: .quickTime),278        Sample(name: "song.m4a", bytes: ftyp("M4A ", ["M4A ", "mp42"]), type: .m4a),279        Sample(name: "sound.wav", bytes: bytes("RIFF") + le32(36) + bytes("WAVEfmt ") + zeros(24), type: .wav),280        Sample(name: "movie.avi", bytes: bytes("RIFF") + le32(36) + bytes("AVI LIST") + zeros(24), type: .avi),281        Sample(name: "song.flac", bytes: bytes("fLaC") + zeros(38), type: .flac),282        Sample(name: "song.ogg", bytes: bytes("OggS") + zeros(26), type: .ogg),283        Sample(name: "film.mkv", bytes: [0x1A, 0x45, 0xDF, 0xA3, 0x93, 0x42, 0x82, 0x88] + bytes("matroska") + zeros(8), type: .matroska),284        Sample(name: "film.webm", bytes: [0x1A, 0x45, 0xDF, 0xA3, 0x8F, 0x42, 0x82, 0x84] + bytes("webm") + zeros(8), type: .webm),285        Sample(name: "prefs.plist", bytes: bytes("bplist00") + zeros(32), type: .binaryPlist),286        Sample(name: "feed.xml", bytes: bytes("<?xml version=\"1.0\"?>\n<root><item/></root>\n"), type: .xml),287        Sample(name: "page.html", bytes: bytes("<!DOCTYPE html>\n<html><head><title>x</title></head><body>été</body></html>"), type: .html),288        Sample(name: "drawing.svg", bytes: bytes("<?xml version=\"1.0\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1\" height=\"1\"/>"), type: .svg),289        Sample(name: "data.json", bytes: bytes("  {\n \"key\": [1, 2, 3]\n}\n"), type: .json),290        Sample(name: "list.json", bytes: bytes("[{\"a\": 1}]"), type: .json),291        Sample(name: "run.sh", bytes: bytes("#!/bin/sh\necho hello\n"), type: .script),292        Sample(name: "tool.py", bytes: bytes("#!/usr/bin/env python3\nprint('x')\n"), type: .script),293        Sample(name: "Document.lnk", bytes: [0x4C, 0, 0, 0, 0x01, 0x14, 0x02, 0, 0, 0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46] + zeros(56), type: .windowsShortcut),294        Sample(name: "wifi.mobileconfig", bytes: mobileconfig, type: .mobileconfig),295        Sample(name: "signed.mobileconfig", bytes: [0x30, 0x82, 0x10, 0x00, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02, 0xA0, 0x82] + zeros(20) + mobileconfig + zeros(64), type: .mobileconfig),296        Sample(name: "chain.p7b", bytes: [0x30, 0x82, 0x10, 0x00, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02, 0xA0, 0x82] + zeros(64), type: .cmsSignedData),297        Sample(name: "notes.txt", bytes: bytes("Bonjour, ceci est un texte simple.\nDeuxième ligne — avec des accents.\n"), type: .text),298        Sample(name: "bom.txt", bytes: [0xEF, 0xBB, 0xBF] + bytes("With a byte order mark\n"), type: .text),299        Sample(name: "wide.txt", bytes: [0xFF, 0xFE] + bytes("h\u{0}i\u{0}"), type: .utf16Text),300        Sample(name: "wide-be.txt", bytes: [0xFE, 0xFF] + bytes("\u{0}h\u{0}i"), type: .utf16Text),301        Sample(name: "blob.dat", bytes: [0x9A, 0x00, 0x13, 0x7F, 0xC1, 0x02, 0xFE, 0x00, 0x88, 0x01, 0x00, 0x05, 0xD3, 0x11, 0x00, 0x9E], type: .unknown),302        Sample(name: "nothing", bytes: [], type: .empty),303    ]304}305306// MARK: Wording307308let forbiddenWords = ["safe", "malicious", "infected", "virus", "malware detected", "clean"]309310func findingTexts(_ finding: Finding) -> [String] {311    var texts = [finding.title, finding.explanation] + finding.notInspected312    if let recommendation = finding.recommendation { texts.append(recommendation) }313    for evidence in finding.evidence { texts += [evidence.label, evidence.value] }314    return texts315}316317/// Every finding carries evidence and an explanation, and never uses verdict words.318func expectHonest(_ findings: [Finding], sourceLocation: SourceLocation = #_sourceLocation) {319    for finding in findings {320        #expect(!finding.evidence.isEmpty, "\(finding.id) has no evidence", sourceLocation: sourceLocation)321        #expect(finding.explanation.count > 20, "\(finding.id) has no explanation", sourceLocation: sourceLocation)322        #expect(!finding.title.isEmpty, sourceLocation: sourceLocation)323        #expect(finding.category == .file, sourceLocation: sourceLocation)324        #expect((finding.confidence == .heuristic) == (finding.verification == .heuristic), sourceLocation: sourceLocation)325        for text in findingTexts(finding) {326            let lower = text.lowercased()327            for word in forbiddenWords {328                #expect(!lower.contains(word), "\(finding.id): “\(text)” contains “\(word)”", sourceLocation: sourceLocation)329            }330        }331    }332}333334func inspectBytes(_ data: [UInt8], name: String, options: InspectionOptions = .init()) throws -> FileInspector.CoreInspection {335    try FileInspector.inspectContent(source: DataByteSource(data), name: name, options: options)336}337338extension Array where Element == Finding {339    func with(_ id: String) -> Finding? { first { $0.id == id } }340    func has(_ id: String) -> Bool { contains { $0.id == id } }341}342
Files main
Menu

Theme