laminapdf-syntax 0.4.0

PDF syntax in Rust: the object model, lexer and parser, stream filters, decryption, and resource limits for untrusted input.
Documentation
//! The PDF syntax layer: the object model, its exact serialization, the lexer, the object
//! parser and the stream filters (ISO 32000-2 §7.2–7.4).
//!
//! ```
//! use laminapdf_syntax::{Object, parse_object};
//!
//! let obj = parse_object(b"<< /Kids [3 0 R] /Count 1 >>")?;
//! assert_eq!(obj.as_dict().and_then(|d| d.get_int("Count")), Some(1));
//! assert_eq!(obj.to_bytes(), b"<< /Kids [3 0 R] /Count 1 >>");
//! # Ok::<(), laminapdf_syntax::Error>(())
//! ```
//!
//! This crate is part of Lamina PDF's pure core: it takes bytes and returns values, and never
//! touches the file system, network, clocks or threads, so it builds for native, WebAssembly
//! and mobile targets alike. Every parse path returns [`Result`]; no input panics. Recursion
//! only happens in the object parser, which is depth-limited ([`Limits::max_nesting_depth`]).
//!
//! * [`Object`] and friends: the object model and its byte-exact serialization.
//! * [`parse_object`] / [`Parser`]: the tolerant object parser (indirect objects and
//!   streams, with an `endstream` scan when `/Length` is wrong).
//! * [`Lexer`] / [`Token`]: the tokenizer the parser and the cross-reference reader share.
//! * [`filters`]: Flate encode/decode within [`Limits`], and PNG predictors.
//! * [`crypt`]: standard security handler decryption (read only): password authentication
//!   for R2–R6 and RC4 / AES-128 / AES-256 string and stream decryption.
//! * [`ErrorKind`], [`Position`] and [`Location`]: the shared parts of the error contract
//!   (ADR 0026): kinds and tagged positions; [`ErrorCode`] and [`WarningCode`], every code's
//!   kind, hint and `docsUrl` (generated from `fixtures/codes.json`); and, with the `json`
//!   feature, `Diagnostic`, the §1 object every boundary serialises.
//! * [`Limits`]: the resource limits of ADR 0003, shared by every layer that reads input.
//! * [`Rotation`]: a rotation by a multiple of 90°, read from `/Rotate` values and shared by
//!   the page model and the renderers.
//! * [`text`]: text strings (`PDFDocEncoding`, UTF-16BE, UTF-8) and the `PDFDocEncoding` table.
//!
//! The file structure (cross-reference tables, object streams, repair, the page tree) and the
//! writer live one layer up, in `laminapdf-cos`.
#![forbid(unsafe_code)]

mod cancel;
pub mod crypt;
mod diagnostic;
mod error;
pub mod filters;
mod job;
/// Generated by `cargo xtask gen codes` from `fixtures/codes.json`; never edited by hand.
mod generated {
    #[rustfmt::skip]
    pub(crate) mod codes;
}
mod lexer;
mod limits;
mod object;
mod parser;
pub mod png;
#[cfg(feature = "json")]
mod record;
mod rotation;
mod suggest;
pub mod text;
// What `fixtures/codes.json` lists, for the kind tests.
#[cfg(test)]
use laminapdf_test_fixtures::codes as test_codes;

pub use cancel::CancelToken;
pub use diagnostic::{ErrorKind, Location, Position};
pub use error::{Error, Result};
pub use generated::codes::{DOCS_URL_BASE, DOCS_URL_SUFFIX, ErrorCode, WarningCode};
pub use job::{Budget, Phase, Step};
pub use lexer::{Lexer, Token, is_delimiter, is_regular, is_whitespace};
pub use limits::{DecodeBudget, Limit, Limits};
pub use object::{Dict, Name, ObjRef, Object, PdfString, Stream, StringFormat, format_real};
pub use parser::{
    IndirectHead, IndirectObject, Parser, StreamHead, endstream_at, find, parse_object, parse_object_with,
    stream_data_end,
};
#[cfg(feature = "json")]
pub use record::Diagnostic;
pub use rotation::Rotation;
pub use suggest::did_you_mean;