capsule-lib
Rust library for reading and writing Capsule container files (see the repository’s SPEC.md).
Capsule is a framing/container format:
- It provides a fixed-width ASCII prelude + header block + payload block.
- The payload is always treated as an opaque byte blob at the Capsule layer.
- Encoding selection (A/B/C) defines how header/payload bytes are represented in the container.
This library is intentionally strict/deterministic:
- Header length is measured in encoded bytes as stored.
- CRC-32 verification is supported (enabled by default when parsing).
- ASCII header
key=value\nparsing is provided when Encoding = A.
Add As A Dependency
If you vendor this repo into a larger workspace:
[]
= { = "path/to/capsule/crates/capsule-lib" }
If you depend on a git checkout (fill in the URL + revision you want):
[]
= { = "<REPO_URL>", = "<GIT_SHA>", = "capsule-lib" }
Core Types
Capsule::parse(...)/Capsule::parse_with_options(...)parse a full Capsule file from bytes.Capsule::to_bytes()serializes aCapsuleback to bytes (recomputes CRC).Capsule::from_decoded(...)builds a Capsule from decoded header/payload inputs.CapsuleDecodedis the parse result (prelude + encoded + decoded bytes).ParseOptionscontrols CRC verification and encoding validation.
Parsing Example
use fs;
use ;
Writing Example (Encoding A)
use HeaderField;
use ;
Validation Guidance
verify_crc=trueis recommended forcapsule verify-style behavior.validate_encoding=trueperforms lexical validation only:- A: rejects non-ASCII bytes in header/payload
- B: strict RFC 4648 Base64 decode
- C: validates CBOR well-formedness and accepts a CBOR sequence (0..N items)
Notes
- The Capsule container format version emitted by tooling is currently
0001. capsule-libtreats payload bytes as opaque; higher-level parsers can interpret payload content as needed.