fix: AppContext::new is a const fn over a &'static label (QA S-09)

A label is one fixed string per purpose; taking any runtime bytes let a
consumer derive it from a peer name, a file name or a message field, and
two purposes could then collide. AppContext::new now takes
&'static [u8] and is a const fn, so contexts are built as consts and a bad
label fails the consumer's build; there is no runtime constructor (the
simplest API: one constructor, no escape hatch until a need appears).

Tests: a const OK and a const EMPTY context; sig_hygiene refuses a
consumer that passes a runtime Vec (E0597/E0716); the one test that needs
runtime labels (flipping label bytes) leaks them on purpose. The random
labels in sig_malformed and fuzz mode 5's AppContext part are dropped (the
raw-ctx part of mode 5 stays). A doctest shows the const pattern, and
docs/02_signatures.md says so.
This commit is contained in:
2026-11-26 03:45:39 +01:00
parent 2329eb0719
commit abcc375741
7 changed files with 50 additions and 16 deletions
+5 -1
View File
@@ -147,7 +147,11 @@ Where the code differs from, or adds to, the design above (the code wins):
canonical one, as well as small-order points (`Error::InvalidVerifyingKey`). Invisible to honest
keys and to the RFC's vectors.
- **App labels are 1 to 231 bytes** (`MAX_APP_LABEL_LEN` = 255 minus the 24-byte prefix); an empty
label is `TooShort`, a longer one `TooLong`.
label is `TooShort`, a longer one `TooLong`. **And `&'static`** (QA S-09): `AppContext::new` is a
`const fn` taking `&'static [u8]`, so a label is written in the source, not derived from a peer
name, file name or message field at run time (a consumer would have to leak memory on purpose to
get around it). A consumer builds its contexts as `const`s, which also moves the length check to
its compile time. There is no runtime constructor.
- **Key bindings** are hashed field by field (no allocation); the window is inclusive at both ends;
`verify_binding` checks, in this order, the window's shape and the id length
(`InvalidValidity`, `TooLong`), the signature (`InvalidSignature`), then `now`