lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

commit c6e895a1060fbaa038f43b0f6cdef236c4289101
parent 01024cbf1a829e0a9b1278c66bfe76f73aa36689
Author: triesap <tyson@radroots.org>
Date:   Mon, 12 Oct 2026 23:44:54 +0000

event_codec: Reject blank optional file message metadata

- Reject present blank original hash blurhash and thumbnail values
- Preserve absent fields exact nonblank text and accepted wire order
- Retain actual authored decoder regressions and twenty passing cases
- Validate Rust 1.99 portability lint native caller and closed deviation

Diffstat:
Mcontracts/architecture/deviations.toml | 28++++++++++++++++++++++++++++
Mcrates/event_codec/README.md | 4++++
Mcrates/event_codec/src/message_file/encode.rs | 15+++++++++++----
Mcrates/event_codec/tests/message_file.rs | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 119 insertions(+), 4 deletions(-)

diff --git a/contracts/architecture/deviations.toml b/contracts/architecture/deviations.toml @@ -2,6 +2,34 @@ schema_version = 1 architecture_id = "radroots.crates.release.v1" [[deviation]] +id = "RCRV1-DEV-034" +date = "2026-10-12" +status = "closed" +approval = "The user approved the successor refactor, scoped execution/recovery amendments and all remaining local verified checkpoints; publication and supported consumer qualification remain separate." +affected_steps = ["010", "040", "070", "130"] +spec_anchors = ["contracts/crates/release_v1/radroots_crates_release_v1.toml#package.radroots_event_codec"] +source_evidence = [ + "The file-message authoring helper emits present original_hash, blurhash and thumb strings without validating that they are nonblank; the paired decoder rejects those same present blank values.", + "The full source and sixteen existing file-message cases were reviewed, and the freshly fetched published integration branch retains identical encoder and decoder bytes; no newer published correction was observed.", + "Retained unchanged-source regressions prove that all three first blank optional values are accepted by authoring and then rejected by its paired decoder; seventeen existing and valid-value controls pass. This is not a private crypto/media exposure claim.", +] +replacement_action = "Bring forward contained optional-string admission during source reevaluation. Reproduce the existing file-message authoring/decoder mismatch, then reject present blank optional original_hash, blurhash and thumb values with the existing typed required-field error. Preserve absent and exact nonblank values, accepted wire order/bytes, public API and feature ownership, algorithms, dependencies and frozen historical evidence." +verification = [ + "Validate this prospective standalone deviation before production edits, then retain actual unchanged-source regressions for all three optional fields plus absent and exact nonblank round-trip controls.", + "Run the complete file-message suite against the correction, exact Rust 1.99.0 all-feature/all-target package checking and warnings-as-errors Clippy, scoped formatting and no-default-feature library checking.", + "Check the unchanged owning native Wasm binding caller, run final standalone architecture validation with explicit closure evidence, and review exact owned source/test/deviation changes before the local owner commit.", +] +unresolved_risk = "The contained optional-string admission correction is locally verified. Strict recipient/key/hash/algorithm/URL contracts, private encryption/custody, delivery/media/resource proving, packed browser behavior, supported target/consumer adoption and full G1 remain separate." +normative_architecture_change = false +adr_required = false +closure_evidence = [ + "Prospective standalone architecture validation passed before production edits. The first three retained admission regressions fail against unchanged source; strengthened regressions then prove each actually authored invalid wire record is rejected by the paired decoder, with seventeen controls passing in both runs.", + "The existing optional-tag helper now rejects present empty or whitespace-only original_hash, blurhash and thumb values with the existing typed required-field error. All twenty file-message tests pass, including all sixteen original cases, absent/exact nonblank round trips and both blank forms for each optional field.", + "Rust 1.99.0 scoped formatting, event-codec all-feature/all-target check and warnings-as-errors Clippy, no-default-feature library check, active architecture validation and native all-feature/all-target compilation of the unchanged Wasm binding caller passed on local macOS arm64.", + "Only private helper admission, meaningful retained regressions, package guidance and this controlled deviation changed. Accepted nonblank text and wire ordering, public type/API shapes, dependencies, algorithms and feature ownership are preserved; final closed-deviation architecture validation is required before local commit. No packed browser, crypto/media/delivery, complete package-test or consumer/G1 qualification is claimed.", +] + +[[deviation]] id = "RCRV1-DEV-033" date = "2026-10-12" status = "closed" diff --git a/crates/event_codec/README.md b/crates/event_codec/README.md @@ -33,6 +33,10 @@ surface is recorded in the ## Verification pipeline +File-message authoring requires a supplied `original_hash`, `blurhash`, or +`thumb` value to contain non-whitespace text, matching the decoder's admission +rules. Nonblank values retain their exact text; use `None` to omit a field. + Wire parsing and cryptographic trust are separate operations. A successful decode returns a structurally valid `RawEvent`; it does not make the declared event ID, signature, contract, referenced events, relay hints, or remote media diff --git a/crates/event_codec/src/message_file/encode.rs b/crates/event_codec/src/message_file/encode.rs @@ -34,10 +34,17 @@ fn push_required_tag( Ok(()) } -fn push_optional_tag(tags: &mut Vec<Vec<String>>, key: &'static str, value: &Option<String>) { +fn push_optional_tag( + tags: &mut Vec<Vec<String>>, + key: &'static str, + value: &Option<String>, + field: &'static str, +) -> Result<(), EventEncodeError> { if let Some(value) = value { + validate_required(value, field)?; tags.push(vec![key.to_string(), value.clone()]); } + Ok(()) } fn push_dimensions_tag(tags: &mut Vec<Vec<String>>, dimensions: &Option<MessageFileDimensions>) { @@ -81,13 +88,13 @@ pub fn message_file_build_tags( )?; push_required_tag(&mut tags, "x", &message.encrypted_hash, "encrypted_hash")?; - push_optional_tag(&mut tags, "ox", &message.original_hash); + push_optional_tag(&mut tags, "ox", &message.original_hash, "original_hash")?; if let Some(size) = message.size { tags.push(vec!["size".to_string(), size.to_string()]); } push_dimensions_tag(&mut tags, &message.dimensions); - push_optional_tag(&mut tags, "blurhash", &message.blurhash); - push_optional_tag(&mut tags, "thumb", &message.thumb); + push_optional_tag(&mut tags, "blurhash", &message.blurhash, "blurhash")?; + push_optional_tag(&mut tags, "thumb", &message.thumb, "thumb")?; for fallback in &message.fallbacks { validate_required(fallback, "fallback")?; tags.push(vec!["fallback".to_string(), fallback.clone()]); diff --git a/crates/event_codec/tests/message_file.rs b/crates/event_codec/tests/message_file.rs @@ -543,3 +543,79 @@ fn message_file_from_tags_rejects_invalid_dimension_components() { message_file_from_tags(KIND_MESSAGE_FILE, &tags, &file_url("encrypted.bin")).unwrap_err(); assert!(matches!(err, EventParseError::InvalidTag("dim"))); } + +#[test] +fn message_file_optional_strings_roundtrip_absent_and_exact_nonblank_values() { + for value in [None, Some("metadata"), Some(" \tmetadata\n")] { + let mut message = sample_message_file(); + message.original_hash = value.map(str::to_string); + message.blurhash = value.map(str::to_string); + message.thumb = value.map(str::to_string); + let parts = to_wire_parts(&message).expect("valid optional metadata"); + let decoded = message_file_from_tags(parts.kind, &parts.tags, &parts.content) + .expect("authored optional metadata must decode"); + assert_eq!(decoded.original_hash, message.original_hash); + assert_eq!(decoded.blurhash, message.blurhash); + assert_eq!(decoded.thumb, message.thumb); + } +} + +#[test] +fn message_file_to_wire_parts_rejects_blank_optional_original_hash() { + for value in ["", " \t\n"] { + let mut message = sample_message_file(); + message.original_hash = Some(value.to_string()); + let authored = to_wire_parts(&message); + if let Ok(parts) = &authored { + assert!(matches!( + message_file_from_tags(parts.kind, &parts.tags, &parts.content), + Err(EventParseError::InvalidTag("ox")) + )); + panic!("authoring accepted optional metadata rejected by its own decoder"); + } + assert!(matches!( + authored, + Err(EventEncodeError::EmptyRequiredField("original_hash")) + )); + } +} + +#[test] +fn message_file_to_wire_parts_rejects_blank_optional_blurhash() { + for value in ["", " \t\n"] { + let mut message = sample_message_file(); + message.blurhash = Some(value.to_string()); + let authored = to_wire_parts(&message); + if let Ok(parts) = &authored { + assert!(matches!( + message_file_from_tags(parts.kind, &parts.tags, &parts.content), + Err(EventParseError::InvalidTag("blurhash")) + )); + panic!("authoring accepted optional metadata rejected by its own decoder"); + } + assert!(matches!( + authored, + Err(EventEncodeError::EmptyRequiredField("blurhash")) + )); + } +} + +#[test] +fn message_file_to_wire_parts_rejects_blank_optional_thumb() { + for value in ["", " \t\n"] { + let mut message = sample_message_file(); + message.thumb = Some(value.to_string()); + let authored = to_wire_parts(&message); + if let Ok(parts) = &authored { + assert!(matches!( + message_file_from_tags(parts.kind, &parts.tags, &parts.content), + Err(EventParseError::InvalidTag("thumb")) + )); + panic!("authoring accepted optional metadata rejected by its own decoder"); + } + assert!(matches!( + authored, + Err(EventEncodeError::EmptyRequiredField("thumb")) + )); + } +}