connector-contract-v3: the payload bound a frame allows is the largest payload that fits

The carriage grows in base64 groups of three bytes, so the frame is not
injective in the payload: payload_bytes_for_frame returns the largest payload
whose frame fits, and the tests say so. The slack of the not-wildly-above check
covers the real nonce being shorter than the worst one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-28 11:22:45 +01:00
commit face15ec16

View file

@ -693,22 +693,26 @@ mod tests {
// within the base64 expansion of the real one.
if id.len() == MAX_IDENTITY_BYTES {
let real = encode_result_frame(&sealed).unwrap().len();
assert!(worst <= real + 8, "{worst} {real}");
assert!(worst <= real + 32, "{worst} {real}");
}
}
}
}
#[test]
fn the_payload_bound_a_frame_allows_inverts_the_frame_a_payload_needs() {
fn the_payload_bound_a_frame_allows_is_the_largest_payload_that_fits() {
// The frame grows in base64 groups of three bytes, so several payloads
// share a frame: the inverse is the largest of them.
assert_eq!(
payload_bytes_for_frame(frame_bytes_for_payload(0) - 1),
None
);
assert_eq!(payload_bytes_for_frame(frame_bytes_for_payload(0)), Some(0));
for bytes in boundary_sizes().into_iter().chain([2_000_000]) {
let frame = frame_bytes_for_payload(bytes);
assert_eq!(payload_bytes_for_frame(frame), Some(bytes), "{bytes}");
let allowed = payload_bytes_for_frame(frame).unwrap();
assert!(allowed >= bytes && allowed - bytes < 3, "{bytes} {allowed}");
assert_eq!(frame_bytes_for_payload(allowed), frame, "{bytes}");
assert!(frame_bytes_for_payload(allowed + 1) > frame, "{bytes}");
assert!(
payload_bytes_for_frame(frame - 1).unwrap() < bytes,
"{bytes}"