Feature flags and no_std

Cargo features for the ocmf crate, the embedded build, the dependency budget, and the supported Rust version.

Defaults

default = ["std", "verify", "sign", "session", "curve-p256"]

The features

FeatureGives you
allocthe crate itself; a no_std build needs this and nothing more
stdstd integration; required by xml
digestRecord::payload_digest — its own feature, because identity is needed without verification
verifysignature checking
signRecordBuilder, the RFC 6979 signers, ExternalSigner
sessionthe check-component rules
curve-p256 (default)secp256r1, verify and sign
curve-p384 / curve-k256 / curve-bp256 / curve-bp384secp384r1 / secp256k1 / brainpoolP256r1 / brainpoolP384r1, verify and sign
curve-p192secp192r1, verify only. The one feature that pulls a pre-release crate (p192), so nothing else enables it
curves-pureall six pure-Rust curves above
backend-opensslall seven algorithms against the system OpenSSL — the only way to check secp192k1. The pure-Rust backend is still tried first
vendored-opensslthe same, built from source and linked statically. For distributable binaries; needs a C compiler and perl and takes minutes to build
ocppSignedMeterValueType and the oca: public-key composition
xmlthe S.A.F.E. transparency container, read and write
serdeSerialize on the derived report and the session report, and Serialize/Deserialize on the OCPP container
fulleverything except the OpenSSL backends

Curves are separate features so an embedded verifier that only sees secp256r1 carries one field implementation. CI runs the test suite under five feature combinations.

$ cargo add ocmf --features curve-bp256,curve-bp384   # add brainpool to the defaults
$ cargo add ocmf --features curves-pure               # all six pure-Rust curves

Embedded and WebAssembly

#![no_std] with alloc, #![forbid(unsafe_code)], no I/O, no clock and no randomness. Every instant is an argument, so verification is deterministic and an old dispute replays exactly.

$ cargo build -p ocmf --no-default-features \
    --features alloc,verify,curve-p256,sign,session,ocpp \
    --target thumbv7em-none-eabihf
$ cargo build -p ocmf --features full --target wasm32-unknown-unknown

Both builds run in CI. alloc is required: the resolved reading list and the deviation report need it.

std does not enable ecdsa/std or sha2/std, which would pull in getrandom. The crate never needs randomness (RFC 6979 signing is deterministic), and leaving it out is what lets wasm32-unknown-unknown build without configuring a getrandom backend.

The serde feature does not enable rust_decimal/serde, which writes a Decimal as a JSON number (and so through f64 in most consumers). Every quantity this crate serialises is the decimal’s exact text.

The dependency budget

The library’s non-optional dependencies are rust_decimal and thiserror. Hex, Base64, DER, SubjectPublicKeyInfo and JSON are implemented in-crate, because each has to be lenient in a way a general-purpose crate rightly refuses:

In-crateWhy not the obvious crate
JSONEvery value must keep its source span, duplicate keys must be visible, unknown keys must survive. A deserialise-into-a-struct reader loses all three
DERBouncyCastle accepts non-minimal lengths, trailing bytes and unpadded high-bit integers; a correct DER library is right to refuse them, and a record the legally recognised tool accepts must not be refused here
HexThe reference verifier strips whitespace, and real transparency files write keys as 3059 3013 0607 …
Base64Both alphabets, optional padding, embedded whitespace

Cryptography is not in-crate: sha2 and the RustCrypto curve crates do that.

Limits

Parsing is bounded, and every bound is a named error rather than a truncation. The defaults are sized well above the largest payload in the reference corpus (932 bytes, 6 readings) and small enough for a charge controller: 128 KiB per record, 64 KiB per payload, 4096 readings, nesting depth 8, 256 members per object, 4096 <value> elements in a transparency container.

use ocmf::{Limits, Profile, Record};

let record = Record::parse_with(&text, Profile::Interop, &Limits::DEFAULT)?;

// `Limits` is `#[non_exhaustive]`, so a new bound is not a breaking change —
// adjust one with a setter rather than a struct literal.
let tight = Limits::DEFAULT.payload(4 * 1024).readings(64);

Limits::UNLIMITED removes the size bounds for a server that has already bounded its input. Nesting stays capped at Limits::HARD_DEPTH (512), because the reader recurses and a stack overflow cannot be returned as a Result.

Supported Rust version

1.88, checked in CI. Raising it is a minor version bump of the crate.