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:
@@ -96,10 +96,8 @@ fuzz_target!(|input: &[u8]| {
|
||||
}
|
||||
}
|
||||
5 => {
|
||||
// Any label, and any raw ctx (0..=255 bytes, or a typed error for longer).
|
||||
if let Ok(c) = AppContext::new(data) {
|
||||
assert!(vk.verify(MSG, &c, &f.sig).is_err() || c == f.ctx);
|
||||
}
|
||||
// Any raw ctx (0..=255 bytes, or a typed error for longer). `AppContext` labels are
|
||||
// `&'static` and fixed at compile time, so there is no runtime label to fuzz.
|
||||
let raw = xor_into(f.ctx.as_bytes(), data);
|
||||
match sign::verify_composite_raw(vk, MSG, &raw, &f.sig) {
|
||||
Ok(()) => assert_eq!(raw, f.ctx.as_bytes()),
|
||||
|
||||
Reference in New Issue
Block a user