1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 DeRec Alliance. All rights reserved.
//! Outer-envelope (`DeRecMessage`) parsing, building, and trace-id plumbing.
//!
//! # Security: no upper bound on inbound *byte size*
//!
//! This section is **only about how many bytes the parser will accept**.
//! Semantic validation of decoded content — transport-protocol scheme
//! consistency, contact-mode/field invariants, timestamp pairing,
//! `(nonce, secret_id, version)` binding for verification responses,
//! etc. — runs at the primitive `extract` layer and at the FFI/WASM
//! seams regardless of how big or small the envelope is. Don't read
//! this note as "the library skips validation"; it skips one specific
//! thing: a maximum-byte-length check.
//!
//! Every function in this module that ingests peer wire bytes —
//! [`extract_inner_message`], [`extract_inner_pairing_message`],
//! [`extract_inner_plaintext_message`], [`apply_trace_id`], [`read_trace_id`] —
//! parses whatever it's handed. No caller-side size cap is enforced anywhere
//! in the library, by design: legitimate envelopes span tens of bytes (acks)
//! through many MB (replica-secret sync), so any cap tight enough to be useful
//! against DoS would risk silently truncating a legitimate share or secret and
//! making the secret unrecoverable.
//!
//! The application's transport layer MUST bound inbound message size at a
//! ceiling consistent with its deployment's max secret size, helper count,
//! and replica fan-out before handing bytes to the library. See the security
//! note on [`crate::protocol::DeRecProtocol::process`] for the canonical
//! statement of this contract.
//!
//! Malformed bytes surface as [`crate::Error::ProtobufDecode`]; recursion
//! depth is bounded by `prost`'s decoder, and the DeRec schema is shallow
//! enough that no additional caller-side recursion limit is needed.
use crate::;
use PairingSecretKeyMaterial;
use ;
use Message;
pub use *;
pub use *;
/// Re-stamp the `trace_id` field on an already-produced DeRecMessage envelope.
///
/// The envelope's outer layer is plaintext, so this just decodes the
/// `DeRecMessage` protobuf, overwrites the `trace_id` field, and re-encodes.
/// The inner encrypted `message` payload is untouched — no crypto work.
///
/// Useful for consumers using primitives directly: the `*::request::produce`
/// functions emit envelopes with `trace_id = 0` (the protobuf default), so
/// callers who want correlation can produce + then [`apply_trace_id`] to set
/// their own. The orchestrator (`DeRecProtocol`) already does this
/// automatically on every outbound request.
/// Read the `trace_id` field off an inbound DeRecMessage envelope without
/// touching the encrypted inner payload.
///
/// Pair with [`apply_trace_id`] for request/response correlation when
/// driving the protocol through primitives directly.
/// Decodes the inner [`MessageBody`] from a plaintext envelope.
///
/// Used by the `HashedKeys` pre-pair leg, where the `message` field of the
/// outer [`DeRecMessage`] envelope carries a serialized `MessageBody`
/// directly — no encryption, because no shared or asymmetric key exists
/// yet at that point in the protocol.
///
/// Counterpart to the plaintext PrePair envelope builder path —
/// see [`crate::primitives::pairing::request::produce_pre_pair_request`]
/// and [`crate::primitives::pairing::response::produce_pre_pair`] for the
/// producers that emit the bytes this function decodes.