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
/// Errors encountered when parsing a stego payload.
#[derive(Debug, thiserror::Error)]
pub enum PayloadV3ParseError {
/// Payload is shorter than the minimum required size.
#[error("Payload too short: need at least {min} bytes, got {actual}")]
TooShort {
/// Minimum required bytes.
min: usize,
/// Actual bytes provided.
actual: usize,
},
/// Magic bytes do not match the expected `SE` marker.
#[error("Invalid magic bytes: expected [0x53, 0x45], got {0:?}")]
InvalidMagic([u8; 2]),
/// Payload version is not supported.
#[error("Unsupported payload version: {0}")]
UnsupportedVersion(u8),
/// Header length exceeds total payload length.
#[error("Header length {header} exceeds total payload length {total}")]
HeaderExceedsTotal {
/// Declared header length.
header: usize,
/// Total payload length.
total: usize,
},
/// DMI policy byte is out of range.
#[error("Invalid DMI policy byte: {0}")]
InvalidDmiPolicy(u8),
/// Authentication algorithm byte is not recognized.
#[error("Invalid authentication algorithm: {0}")]
InvalidAuthAlgorithm(u8),
/// Key ID length exceeds the maximum allowed.
#[error("Key ID length {key_id_len} exceeds maximum {max}")]
KeyIdTooLong {
/// Declared key ID length.
key_id_len: usize,
/// Maximum allowed key ID length.
max: usize,
},
/// Extension section exceeds maximum size.
#[error("Extension section exceeds maximum size")]
ExtensionsTooLarge,
/// Unknown critical extension type encountered.
#[error("Unknown critical extension type: 0x{0:04X}")]
UnknownCriticalExtension(u16),
/// Duplicate singleton extension type encountered.
#[error("Duplicate singleton extension: 0x{0:04X}")]
DuplicateExtension(u16),
/// Payload exceeds maximum embedded size.
#[error("Payload exceeds maximum embedded size: {size} > {max}")]
Oversized {
/// Actual size.
size: usize,
/// Maximum allowed size.
max: usize,
},
/// Intensity value is out of range.
#[error("Invalid intensity value: {0}")]
InvalidIntensity(u16),
/// Authentication key was not provided but the payload requires one.
#[error("Authentication key required but not provided")]
MissingKey,
/// Authentication key was provided but HMAC verification failed.
///
/// This indicates the supplied key does not match the key used during
/// embedding. It is distinct from [`PayloadV3ParseError::CorruptTag`],
/// which indicates the tag itself is structurally malformed.
#[error("Authentication failed: wrong key")]
WrongKey,
/// Authentication tag is present but structurally invalid.
///
/// The tag length does not match the expected length for the declared
/// algorithm, or the tag is truncated. This is distinct from
/// [`PayloadV3ParseError::WrongKey`], where the tag structure is correct
/// but the HMAC does not match.
#[error("Authentication tag is corrupt or truncated")]
CorruptTag,
}