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
+1 -1
View File
@@ -20,7 +20,7 @@ use sha2::{Digest, Sha512};
const ML: usize = 3309; // the ML-DSA-65 half comes first
const ML_PK: usize = 1952;
fn ctx(label: &[u8]) -> AppContext {
fn ctx(label: &'static [u8]) -> AppContext {
AppContext::new(label).unwrap()
}