quelda
Version:
PDF & Illustrator security scanner (WebAssembly): files + policy in, verdict out
34 lines (33 loc) • 1.58 kB
TypeScript
import { type FromWorker } from './protocol.js';
/** What `scan_source` reads the file through (see quelda-wasm). */
export interface Reader {
size: number;
/** Fills `into` with the bytes at `offset`, synchronously, or throws. */
readInto(offset: number, into: Uint8Array): void;
}
/** The wasm-bindgen exports the host calls. */
export interface Engine {
scan(bytes: Uint8Array, policyJson: string): string;
scan_source(reader: Reader, policyJson: string): string;
list_rules(): string;
version(): string;
/** Current WASM memory size in bytes. */
memory(): number;
}
/** A synchronous reader over a Blob, if this scope can read one. */
export type BlobReader = (blob: Blob) => Reader | undefined;
/**
* `FileReaderSync` (dedicated workers in browsers): each `readInto` reads
* one slice of the Blob, so the file is never loaded whole. `undefined`
* where it does not exist (Node).
*/
export declare const fileReaderSync: BlobReader;
/** Loads the engine; `wasm` is the scanner's `wasm` option (or `undefined`). */
export type EngineLoader = (wasm: string | WebAssembly.Module | undefined) => Promise<Engine>;
/**
* Returns the worker's message handler. The engine is loaded once (`init`);
* after it throws or traps the host refuses further work (`fail`), since a
* trapped WASM instance may be left in a broken state. The scanner then
* replaces the worker.
*/
export declare function createHost(load: EngineLoader, post: (message: FromWorker) => void, now?: () => number, readerFor?: BlobReader): (data: unknown) => Promise<void>;