Skip to main content

Crate decision_cert

Crate decision_cert 

Source
Expand description

Load, verify and apply decision certificates: decision-certificate.v1 (spec/decision-certificate.v1.md), decision-certificate.v1.1 (spec/decision-certificate.v1.1.md) and decision-certificate.v1.2 (spec/decision-certificate.v1.2.md).

Verification canonicalises the JSON value exactly as received (RFC 8785, JCS), never a re-serialised struct, so number formatting can’t drift from the issuer’s. The typed Certificate is read from the same value afterwards, rejecting unknown fields.

A v1.2 certificate also stores the confidence histogram of its threshold split, so a consumer can monitor without labels: Histogram::of bins a window of use-time confidences and shift_score compares it with the stored one. The score is descriptive, a prompt to measure again; it never shows that the bound holds or has failed.

probabilities applies a certificate’s calibration map to a case’s raw scores, for the map kinds v1.2 defines (temperature and dr, MAP_KINDS).

Structs§

Audit
Band
CalibrationMap
Certificate
Every field is required; Option fields must be present (as null): a missing field is an error.
Histogram
A test’s threshold-split cases per bin of confidence_bins, and the cases the rule abstains on whatever the threshold (unscored, or above the cannot_tell cut). v1.2.
Issuer
Rule
Segment
ShiftScore
Pearson’s chi-square test of homogeneity between the stored histogram and a window’s.
Split
Verified
A certificate whose signature verified against a trusted key.
Window

Enums§

CertError

Constants§

ABSTAIN_ALL
abstain_below that abstains on every case (as dk calibrate writes it).
MAP_KINDS
The kinds of calibration map v1.2 defines. A certificate may name another kind; it still verifies, and a consumer that does not apply that kind refuses it (spec v1.2 §4).
MAX_BINS
Most bins a confidence_bins may define.
SPEC
The spec of a certificate produced by the v1 procedure.
SPECS
Every spec this verifier accepts. v1 and v1.1 have the same fields; v1.2 adds some.
SPEC_V1_1
The spec of a certificate produced by the v1.1 procedure (the per-test grid start).
SPEC_V1_2
The spec of a v1.2 certificate: v1.1’s procedure, plus the stored confidence histogram.

Functions§

bin_of
The bin of confidence: i with bins[i] <= confidence < bins[i + 1]; the last bin also holds
canonical
The JCS bytes of a JSON value.
certificate_id
chi2_sf
P(X >= x) for X ~ chi-square with df degrees of freedom: the regularised upper incomplete gamma Q(df/2, x/2), by its series below a + 1 and its continued fraction above. 1 for df 0.
confidence
A case’s confidence under map: the largest of its probabilities. None when those are.
key_id
ed25519: + the first 16 hex chars of SHA-256 of the raw public key.
probabilities
The probabilities map gives a case’s raw scores, one per option in score order (spec v1.2 §1):
shift_score
Compare a window’s histogram with the certificate’s (spec §4). The columns are the bins and the unscored count; columns empty in both are dropped. With an empty side or one column left there is nothing to compare: statistic 0, df 0, p-value 1. None when the bin counts differ.
timestamp
Parse the spec’s timestamp form, YYYY-MM-DDTHH:MM:SSZ, and nothing else.
verify
Verify v against keys (key id → base64url raw public key) and read it.