Reads what meters emit
Every record in the S.A.F.E. reference corpus parses and reproduces itself byte for byte — padded quoted numbers, unpadded DER integers, bare public keys and all.
Rust · no_std · 7 signature algorithms
ocmf is the Rust implementation of the Open Charge Metering Format — the container a certified meter in an EV charging station signs a reading into, and the working answer to German calibration law (Mess- und Eichrecht) for e-mobility.
cargo add ocmf · brew install hupe1980/tap/ocmf
The signature is ECDSA over SHA-256 of the payload section exactly as it was written. Parse into a struct, serialise it back, and the hash has already changed.
Key order, whitespace, number formatting and Unicode escapes are all free to change on a round trip through a typed value — and every one of them changes the digest. So Record::signed_bytes() returns a slice of the input, and no API in this crate produces signable bytes from a typed value.
Nine records in the reference corpus are pretty-printed. Any implementation that re-serialises destroys them.
use ocmf::{PublicKey, Record, verify};
let record = Record::parse(&text)?;
// Reading a record and writing it back is the identity function.
assert_eq!(record.to_string(), text);
// The bytes the signature covers — a slice of `text`, never rebuilt.
let signed: &[u8] = record.signed_bytes();
let key = PublicKey::from_text(&key_text, record.signature().curve())?;
let verified = verify(&record, &key)?;One crate for the whole life of a record: read it, judge it, check it, produce it, move it.
Every record in the S.A.F.E. reference corpus parses and reproduces itself byte for byte — padded quoted numbers, unpadded DER integers, bare public keys and all.
Every departure from the specification is a typed value with the table it is measured against, and a flag saying whether it breaches the document or is merely worth knowing.
Six in pure Rust, brainpool included; secp192k1 through OpenSSL. An algorithm a build cannot check is reported as unsupported, never as “does not verify”.
RFC 6979 deterministic ECDSA — no nonce, no RNG — low-s output, an HSM seam, and every record re-read and re-verified before it is returned.
Continuous pagination, one begin and one end in their places, one source, error states fatal: every rule the specification assigns to a check component.
OCPP’s SignedMeterValueType with the oca: key composition, and a S.A.F.E. transparency file grouped into the transactions its verifier pairs on.
#![no_std] with alloc, #![forbid(unsafe_code)], no I/O, no clock and no randomness — so it builds for a charge controller and for wasm32 alike.
Every design decision is anchored in a measurement over 256 real records from eleven vendors, each carrying OpenSSL’s independent verdict.
89 % of real records omit a field the specification marks mandatory. A strict parser rejects nine records in ten; a lenient one never tells an operator their fleet emits records the official tool will reject. So parsing runs in a profile, and every departure is reported rather than swallowed.
Twenty-six of those records carry a value no closed table defines — a unit called sec, a charge-point identifier written as a JSON number, RFID UIDs of the wrong width. They parse clean everywhere else.
$ ocmf explain record.ocmf
record.ocmf
format version 1.0
gateway KEBA_KCP30 / 17619300 / 2.8.5
meter - - serial (absent) fw -
pagination T32
algorithm ECDSA-secp256r1-SHA256 (defaulted; SA absent)
payload bytes 391
readings 2
[0] 2019-08-13T10:03:15,000+0000 I 0.2596 kWh 1-b:1.8.0 billable
[1] 2019-08-13T10:03:36,000+0000 R 0.2597 kWh 1-b:1.8.0 billable
01-0B:01.08.00 Δ 0.0001 kWh
deviations 3 (3 breach the specification, 0 advisory)
! `MS` is absent although it is mandatory at byte 5 [OCMF Tab. 3]
! OBIS code is not in the canonical form: "1-b:1.8.0" at RD[0].RI [OCMF Tab. 25]
! OBIS code is not in the canonical form: "1-b:1.8.0" at RD[1].RI [OCMF Tab. 25]