dvb_ci/error.rs
1//! Error type for EN 50221 Common Interface parsing/serialization.
2
3/// Result alias for `dvb-ci`.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// A Common Interface parse or serialize error.
7#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10 /// Input shorter than required.
11 #[error(transparent)]
12 BufferTooShort(#[from] broadcast_common::error::BufferTooShort),
13 /// Output buffer smaller than `serialized_len()`.
14 #[error(transparent)]
15 OutputBufferTooSmall(#[from] broadcast_common::error::OutputBufferTooSmall),
16 /// An object's 3-byte `apdu_tag` did not match the expected value.
17 #[error("unexpected apdu_tag: got {got:#08X}, expected {expected:#08X} ({what})")]
18 UnexpectedApduTag {
19 /// The tag read from the wire (24-bit, in the low 3 bytes).
20 got: u32,
21 /// The tag the parser expected.
22 expected: u32,
23 /// The object being parsed.
24 what: &'static str,
25 },
26 /// A 1-byte `spdu_tag` did not match the expected value.
27 #[error("unexpected spdu_tag: got {got:#04X}, expected {expected:#04X} ({what})")]
28 UnexpectedSpduTag {
29 /// The tag read from the wire.
30 got: u8,
31 /// The tag the parser expected.
32 expected: u8,
33 /// The object being parsed.
34 what: &'static str,
35 },
36 /// A 1-byte `tpdu_tag` did not match the expected value.
37 #[error("unexpected tpdu_tag: got {got:#04X}, expected {expected:#04X} ({what})")]
38 UnexpectedTpduTag {
39 /// The tag read from the wire.
40 got: u8,
41 /// The tag the parser expected.
42 expected: u8,
43 /// The object being parsed.
44 what: &'static str,
45 },
46 /// The ASN.1-style `length_field` was malformed (truncated, or a
47 /// declared length running past the buffer).
48 #[error("invalid length_field: {0}")]
49 InvalidLength(&'static str),
50 /// A `length_field` encoded a value too large to represent (the spec caps
51 /// any length at 65535, i.e. at most 3 length bytes).
52 #[error("length_field value too large to encode: {0}")]
53 LengthTooLarge(usize),
54 /// A declared `length_field` did not match the actual body length, or the
55 /// body did not fit the fixed shape the object requires.
56 #[error(transparent)]
57 LengthMismatch(#[from] broadcast_common::error::LengthMismatch),
58 /// A fixed-shape object had a body length the spec does not allow.
59 #[error("invalid object body for {what}: {reason}")]
60 InvalidObject {
61 /// The object being parsed.
62 what: &'static str,
63 /// Why it is invalid.
64 reason: &'static str,
65 },
66 /// A `resource_identifier()` did not map to any CI-extension resource that
67 /// [`crate::ci_ext::CiExtApdu`] can dispatch.
68 #[error("unknown CI-extension resource: {resource_id:#010X}")]
69 UnknownResource {
70 /// The 32-bit `resource_identifier()`.
71 resource_id: u32,
72 },
73}