Local Tesseract OCR engine for infrastructure-ocr-engine: a subprocess adapter that pipes the image via stdin->stdout (NO temp file, no C linking), with an allowlisted binary, timeout, and input cap. Implements LocalOcrEngine (on-host, no egress) — usable on the DLP path.
| Tier | infrastructure |
| Role | unclassified (baselined) |
| Path | crates/infrastructure/ocr-tesseract |
| Edition | 2021 |
| Targets | ocr_file, infrastructure_ocr_tesseract |
| Public items | 13 across 0 modules |
| Tests | 4 |
What it is for
infrastructure-ocr-tesseract — a local Tesseract OCR engine for infrastructure_ocr_engine.
It shells out to the system tesseract binary as a subprocess, piping the image in via stdin and reading text back from stdout (tesseract stdin stdout). Consequences that matter for DLP:
- No temp file — the image never touches disk (stdin pipe only).
- No C linking — pure-Rust build; only the runtime needs the binary (like
curl). - Crash isolation — a Tesseract crash cannot take down the host process.
The binary is invoked as a strict argument vector (never a shell), from an allowlisted/configurable path, under a timeout and an input-size cap (PROCESS §17). It implements LocalOcrEngine — it runs entirely on-host and never transmits the image off the machine — so it is usable on the DLP screen path.
Capabilities
crate root
infrastructure-ocr-tesseract — a local Tesseract
| Item |
|---|
pub const DEFAULT_MAX_INPUT_BYTES: usize |
pub const DEFAULT_TIMEOUT: Duration |
TesseractEngine
infrastructure-ocr-tesseract — a local Tesseract
| Item |
|---|
pub struct TesseractEngine |
TesseractEngine :: fn default() -> Self |
TesseractEngine :: fn new() -> Self |
TesseractEngine :: fn with_bin(mut self, bin : impl Into <String>) -> Self |
TesseractEngine :: fn with_lang(mut self, lang : impl Into <String>) -> Self |
TesseractEngine :: fn with_psm(mut self, psm : u8) -> Self |
TesseractEngine :: fn with_timeout(mut self, timeout : Duration) -> Self |
TesseractEngine :: fn with_max_input_bytes(mut self, max : usize) -> Self |
TesseractEngine :: fn provider_id(& self) -> & 'static str |
TesseractEngine :: fn is_available(& self) -> bool |
TesseractEngine :: async fn recognize(& self, input : & OcrInput <'_>) -> Result <OcrText, OcrError> |
How to use it
From `examples/ocr_file.rs`:
use infrastructure_ocr_engine::{MediaType, OcrEngine, OcrInput};
use infrastructure_ocr_tesseract::TesseractEngine;
#[tokio::main]
async fn main() {
let path = std::env::args()
.nth(1)
.expect("usage: ocr_file <image-path>");
let bytes = std::fs::read(&path).expect("read image");
let media = std::path::Path::new(&path)
.extension()
.and_then(|e| e.to_str())
.and_then(MediaType::from_extension)
.unwrap_or(MediaType::Png);
let engine = TesseractEngine::new();
assert!(engine.is_available(), "tesseract binary not found");
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub const DEFAULT_MAX_INPUT_BYTES: usize | Default cap on the encoded image handed to Tesseract (16 MiB). |
pub const DEFAULT_TIMEOUT: Duration | Default recognition timeout. |
pub struct TesseractEngine | A local Tesseract OCR engine (subprocess adapter). |
TesseractEngine :: fn default() -> Self | — |
TesseractEngine :: fn new() -> Self | A Tesseract engine with defaults (bin="tesseract", lang="eng", psm=6). |
TesseractEngine :: fn with_bin(mut self, bin : impl Into <String>) -> Self | Override the binary path (allowlisted/configurable; still invoked as an arg vector, never a shell). |
TesseractEngine :: fn with_lang(mut self, lang : impl Into <String>) -> Self | Override the language(s) passed to -l (e.g |
TesseractEngine :: fn with_psm(mut self, psm : u8) -> Self | Override the page-segmentation mode (--psm). |
TesseractEngine :: fn with_timeout(mut self, timeout : Duration) -> Self | Override the recognition timeout. |
TesseractEngine :: fn with_max_input_bytes(mut self, max : usize) -> Self | Override the maximum accepted encoded-image size (bytes). |
TesseractEngine :: fn provider_id(& self) -> & 'static str | — |
TesseractEngine :: fn is_available(& self) -> bool | True iff the configured binary runs (tesseract --version exits 0). |
TesseractEngine :: async fn recognize(& self, input : & OcrInput <'_>) -> Result <OcrText, OcrError> | — |
No pub use re-exports: every item above is declared in this crate.
Boundary
Depends on no other workspace tier.
Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | infrastructure |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/infrastructure/ocr-tesseract |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `infrastructure-ocr-engine` | infrastructure | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
async-trait | ^0.1 | — | no | always |
tokio | ^1 | full, process, io-util, time, rt | no | always |
Development, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `infrastructure-dlp-detect` | infrastructure | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio | ^1 | full, macros, rt-multi-thread | no | always |
Build. None.
Depended on by. 6 workspace crates.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_infrastructure_acquire["infrastructure-acquire"] -->|uses| SELF n_infrastructure_ocr_provider["infrastructure-ocr-provider"] -->|uses| SELF n_operations_dlp_agent["operations-dlp-agent"] -->|uses| SELF n_operations_dlp_sensor["operations-dlp-sensor"] -->|uses| SELF n_tools_gui_harness["tools-gui-harness"] -->|uses| SELF n_tools_imp["tools-imp"] -->|uses| SELF SELF["infrastructure-ocr-tesseract"] SELF -->|development| n_infrastructure_dlp_detect["infrastructure-dlp-detect"] SELF -->|runtime| n_infrastructure_ocr_engine["infrastructure-ocr-engine"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| example | ocr_file | `examples/ocr_file.rs` |
| lib | infrastructure_ocr_tesseract | `src/lib.rs` |
Error model
No public error type was detected: no public item declares a type named *Error, and no public signature returns one.
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | yes |
| async runtime | yes |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
6 workspace crates depend on this one: infrastructure-acquire, infrastructure-ocr-provider, operations-dlp-agent, operations-dlp-sensor, tools-gui-harness, tools-imp.
Verification
| Kind | Count |
|---|---|
| Unit tests | 4 |
| Integration tests | 0 |
| Examples | 1 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 3 | 1 | 5 |
What the tests establish, by name:
input_too_large_is_rejected_without_spawning—src/lib.rsis_local_engine_and_has_provider_id—src/lib.rsrecognizes_fixture_and_detector_masks_it—src/lib.rsunknown_binary_is_unavailable—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 10 | 13 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 10
"No rustdoc detected" : 3
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 242 |
| Code lines | 176 |
| Public API items | 13 |
| Public modules | 0 |
| Tests | 4 |
| Examples | 1 |
| Cargo features | 0 |
| Direct runtime dependencies | 3 |
| Workspace reverse dependencies | 6 |
pie showData
title Public API by kind
"constant" : 2
"method" : 10
"struct" : 1
pie showData
title Rust source composition
"Code" : 176
"Blank or comment" : 66
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.