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
// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use thiserror::Error;
/// Error returned when decoding fails to conform to the DAG-CBOR profile.
///
/// Decoding fails closed: any malformed or non-canonical input yields one of
/// these variants rather than a partial or best-effort value.
#[derive(Debug, Clone, Copy, Error, PartialEq, Eq)]
#[non_exhaustive]
pub enum CborError {
/// Extra bytes remain after decoding the top-level value.
#[error("CBOR: trailing bytes after top-level value")]
TrailingBytes,
/// Input ended before the current value was fully decoded.
#[error("CBOR: unexpected end of input")]
UnexpectedEnd,
/// The encoded input exceeded the absolute DAG-CBOR boundary cap.
#[error("CBOR: input too large")]
InputTooLarge,
/// Encoding would exceed the absolute DAG-CBOR boundary cap.
#[error("CBOR: encoded output too large")]
OutputTooLarge,
/// Computing an offset into the input would overflow.
#[error("CBOR: offset arithmetic overflow")]
OffsetOverflow,
/// A declared length is too large to represent as a platform `usize`.
#[error("CBOR: length does not fit in platform usize")]
LengthTooLarge,
/// An encoded integer falls outside the supported `i64` range.
#[error("CBOR: integer is outside supported i64 range")]
IntegerOutOfRange,
/// An integer used a longer-than-minimal (non-canonical) encoding.
#[error("CBOR: non-canonical integer encoding")]
NonCanonicalInteger,
/// The numeric argument (length/value) bytes were truncated.
#[error("CBOR: truncated numeric argument")]
TruncatedArgument,
/// A byte string ended before its declared length was read.
#[error("CBOR: truncated byte string")]
TruncatedBytes,
/// A text string contained bytes that are not valid UTF-8.
#[error("CBOR: invalid UTF-8 string")]
InvalidUtf8,
/// A map key was not a text string, which DAG-CBOR requires.
#[error("CBOR: map key must be text string")]
MapKeyMustBeString,
/// A map contained the same text key more than once.
///
/// Duplicate keys make the data model ambiguous and would cause the
/// encoder to produce bytes that the canonical decoder must reject.
#[error("CBOR: duplicate map key")]
DuplicateMapKey,
/// Map keys were not in the canonical (sorted) order DAG-CBOR requires.
#[error("CBOR: map keys out of canonical order")]
MapKeysOutOfOrder,
/// A CBOR simple value not permitted by the DAG-CBOR profile was found.
#[error("CBOR: simple value not allowed in DAG-CBOR")]
DisallowedSimpleValue {
/// The rejected simple-value code, or the additional-info code
/// (25, 26, or 27) for a rejected float. Never contains float payload bits.
value: u64,
},
/// A CBOR major type not permitted by the DAG-CBOR profile was found.
#[error("CBOR: major type not allowed in DAG-CBOR")]
DisallowedMajorType {
/// The CBOR major-type number that was rejected.
major: u8,
},
/// An oversized or indefinite-length additional-info value was found.
#[error("CBOR: value too large or indefinite length not allowed")]
UnsupportedAdditionalInfo,
/// A declared array/map element count is larger than the remaining
/// input could possibly satisfy. Rejected before allocating so an
/// attacker-chosen length prefix cannot drive an out-of-memory abort.
#[error("CBOR: declared container length exceeds remaining input")]
ContainerLengthExceedsInput,
/// Nesting exceeded [`MAX_NESTING_DEPTH`](crate::MAX_NESTING_DEPTH).
/// Bounds recursion so a deeply nested input cannot overflow the stack.
#[error("CBOR: nesting depth limit exceeded")]
DepthExceeded,
/// A document contained more semantic nodes than the profile allows.
#[error("CBOR: node limit exceeded")]
NodeLimitExceeded,
/// One array or map contained more entries than the profile allows.
#[error("CBOR: container entry limit exceeded")]
ContainerEntriesExceeded,
}