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
//! The DSSE Pre-Authentication Encoding.
/// The fixed DSSE version prefix, ASCII `DSSEv1`.
const PREFIX: & = b"DSSEv1 ";
/// Returns the DSSE Pre-Authentication Encoding of `payload_type` and `payload`.
///
/// The encoding is specified in `protocol.md` of
/// <https://github.com/secure-systems-lab/dsse> as
///
/// ```text
/// PAE(type, body) = "DSSEv1" + SP + LEN(type) + SP + type + SP + LEN(body) + SP + body
/// SP = ASCII space [0x20]
/// LEN(s) = ASCII decimal encoding of the byte length of s, with no leading zeros
/// ```
///
/// `LEN` counts **bytes**, not characters. For a `payload_type` outside ASCII the
/// two differ, and a signature computed over a character count does not verify
/// against one computed over a byte count.
///
/// The encoding is injective: the length prefixes fix the boundary between type
/// and body, so no two distinct `(type, payload)` pairs share a pre-image and a
/// signature minted for one payload type never verifies as another.