dvb_simulcrypt/error.rs
1//! Error type for DVB SimulCrypt (ETSI TS 103 197) message framing.
2
3/// Result alias for SimulCrypt parsing.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// A SimulCrypt parse / serialize error.
7#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10 /// Input shorter than required.
11 #[error("buffer too short: need {need}, have {have} ({what})")]
12 BufferTooShort {
13 /// Bytes required.
14 need: usize,
15 /// Bytes available.
16 have: usize,
17 /// What was being parsed.
18 what: &'static str,
19 },
20 /// The output buffer passed to `serialize_into` was too small.
21 #[error("output buffer too small: need {need}, have {have}")]
22 OutputBufferTooSmall {
23 /// Bytes required.
24 need: usize,
25 /// Bytes available.
26 have: usize,
27 },
28 /// The `message_length` header field is inconsistent with the bytes that
29 /// follow it (TS 103 197 Table 1b: it counts the bytes immediately after
30 /// the `message_length` field — i.e. the sum of all parameter TLVs).
31 #[error("invalid message_length {length}: {reason}")]
32 InvalidMessageLength {
33 /// The `message_length` field value.
34 length: u16,
35 /// Why it is invalid.
36 reason: &'static str,
37 },
38 /// A parameter TLV was truncated: its `parameter_length` ran past the end
39 /// of the message body.
40 #[error("truncated parameter (type {ptype:#06X}): need {need}, have {have}")]
41 TruncatedParameter {
42 /// The `parameter_type` of the offending TLV.
43 ptype: u16,
44 /// Bytes the `parameter_length` claimed.
45 need: usize,
46 /// Bytes actually remaining in the message body.
47 have: usize,
48 },
49 /// A value did not fit in its wire width when serializing (e.g. a TLV value
50 /// longer than the 16-bit `parameter_length`, or a body longer than the
51 /// 16-bit `message_length`).
52 #[error("field {what} value {value} does not fit in {bits} bits")]
53 FieldTooWide {
54 /// The over-wide field name.
55 what: &'static str,
56 /// The offending value.
57 value: usize,
58 /// The field width on the wire.
59 bits: u32,
60 },
61}