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
+6 -1
View File
@@ -157,7 +157,7 @@ fn the_raw_interface_is_not_reachable_without_hazmat() {
/// `Deref`/`AsRef` to the component keys, and an `AppContext` only from the Arcanum prefix.
#[test]
fn ml_dsa_internals_are_not_reachable() {
let calls: [(&str, &str, &[&str]); 8] = [
let calls: [(&str, &str, &[&str]); 9] = [
("re-export of ml_dsa", "use arcanum::ml_dsa;", &["E0432"]),
("re-export in sign", "use arcanum::sign::ml_dsa;", &["E0432"]),
("sign_internal through the key", "let _ = key().sign_internal(&[b\"m\"], &Default::default());", &["E0599"]),
@@ -170,6 +170,11 @@ fn ml_dsa_internals_are_not_reachable() {
("a component key field", "let k = key(); let _ = &k.ml;", &["E0609", "E0616"]),
("a foreign or empty context", "let _ = arcanum::sign::AppContext::from_raw(b\"\");", &["E0599"]),
("cloning a signing key", "let k = key(); let _ = k.clone();", &["E0599"]),
(
"a label built at run time (QA S-09)",
"let l = std::env::args().next().unwrap().into_bytes(); let _ = arcanum::sign::AppContext::new(&l);",
&["E0597", "E0716"],
),
];
for (what, body, needles) in calls {
assert_refused(what, body, needles);