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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use thiserror::Error;
/// Fixed, payload-free reasons for general CBOR rejection.
#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
#[non_exhaustive]
pub enum ErrorReason {
/// No top-level item was available.
#[error("empty input")]
EmptyInput,
/// A header or payload ended prematurely.
#[error("truncated item")]
Truncated,
/// Additional-information values 28 through 30 are reserved.
#[error("reserved additional information")]
ReservedAdditionalInformation,
/// Integers and tags cannot have indefinite arguments.
#[error("invalid indefinite argument")]
InvalidIndefiniteArgument,
/// A break occurred outside its permitted container position.
#[error("unexpected break")]
UnexpectedBreak,
/// A simple value used a forbidden two-byte representation.
#[error("invalid simple value encoding")]
InvalidSimpleValue,
/// A chunk was indefinite or had the wrong string type.
#[error("invalid string chunk")]
InvalidChunk,
/// The selected profile permits definite lengths only.
#[error("indefinite length is not allowed")]
IndefiniteNotAllowed,
/// An argument used more octets than necessary.
#[error("non-preferred argument encoding")]
NonPreferredArgument,
/// A float could be represented exactly at a shorter width.
#[error("non-preferred floating-point encoding")]
NonPreferredFloat,
/// The selected profile rejects floating-point values.
#[error("floating-point values are not allowed")]
FloatNotAllowed,
/// The selected profile rejects infinity and NaN.
#[error("non-finite floating-point value")]
NonFiniteFloat,
/// A text string or an individual text chunk was not UTF-8.
#[error("invalid UTF-8")]
InvalidUtf8,
/// Two map keys are equivalent in the basic generic data model.
#[error("duplicate map key")]
DuplicateMapKey,
/// Received keys violate the explicitly selected ordering rule.
#[error("map key ordering violation")]
MapKeyOrder,
/// More bytes followed the requested complete item.
#[error("trailing data")]
TrailingData,
/// An operation was applied to a different CBOR type.
#[error("unexpected item type")]
WrongType,
/// Embedded-item validation requires the standard encoded-CBOR tag.
#[error("unexpected tag")]
WrongTag,
/// A tag-24 byte string is empty, so it holds no embedded data item.
#[error("empty embedded CBOR")]
EmptyEmbeddedItem,
/// Chunked contents do not form one contiguous borrowed payload.
#[error("non-contiguous string contents")]
NonContiguousString,
/// A limit exceeded its supported hard ceiling.
#[error("invalid resource limit")]
InvalidLimit,
/// The profile combination cannot provide the requested guarantee.
#[error("unsupported profile combination")]
UnsupportedPolicy,
/// Input exceeded the configured transport cap.
#[error("input limit exceeded")]
InputLimit,
/// Output would exceed the configured cap.
#[error("output limit exceeded")]
OutputLimit,
/// Too many nested containers or tags were opened.
#[error("nesting limit exceeded")]
DepthLimit,
/// Too many structural nodes were encountered.
#[error("node limit exceeded")]
NodeLimit,
/// A container has too many entries or chunks.
#[error("container entry limit exceeded")]
EntryLimit,
/// Aggregate byte-string contents exceeded the configured cap.
#[error("byte-string content limit exceeded")]
ByteStringLimit,
/// Aggregate text contents exceeded the configured cap.
#[error("text content limit exceeded")]
TextLimit,
/// Parsing or semantic comparison exhausted its explicit work budget.
#[error("validation work limit exceeded")]
WorkLimit,
/// A declared container cannot fit in the remaining received input.
#[error("container declaration exceeds remaining input")]
ContainerExceedsInput,
/// A size or offset calculation could not be represented.
#[error("length arithmetic overflow")]
ArithmeticOverflow,
/// A bounded output allocation could not be reserved.
#[error("bounded allocation failed")]
AllocationFailure,
}
/// General CBOR error with no input, offsets, strings, or dependency diagnostics.
#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
#[error("general CBOR: {reason}")]
pub struct CborError {
reason: ErrorReason,
}
impl CborError {
/// Construct a fixed typed error.
#[must_use]
pub const fn new(reason: ErrorReason) -> Self {
Self { reason }
}
/// Return the stable rejection reason.
#[must_use]
pub const fn reason(self) -> ErrorReason {
self.reason
}
}
pub(super) const fn error(reason: ErrorReason) -> CborError {
CborError::new(reason)
}