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(transparent)]
12 BufferTooShort(#[from] broadcast_common::error::BufferTooShort),
13 /// The output buffer passed to `serialize_into` was too small.
14 #[error(transparent)]
15 OutputBufferTooSmall(#[from] broadcast_common::error::OutputBufferTooSmall),
16 /// The `message_length` header field is inconsistent with the bytes that
17 /// follow it (TS 103 197 Table 1b: it counts the bytes immediately after
18 /// the `message_length` field — i.e. the sum of all parameter TLVs).
19 #[error("invalid message_length {length}: {reason}")]
20 InvalidMessageLength {
21 /// The `message_length` field value.
22 length: u16,
23 /// Why it is invalid.
24 reason: &'static str,
25 },
26 /// A parameter TLV was truncated: its `parameter_length` ran past the end
27 /// of the message body.
28 #[error("truncated parameter (type {ptype:#06X}): need {need}, have {have}")]
29 TruncatedParameter {
30 /// The `parameter_type` of the offending TLV.
31 ptype: u16,
32 /// Bytes the `parameter_length` claimed.
33 need: usize,
34 /// Bytes actually remaining in the message body.
35 have: usize,
36 },
37 /// A value did not fit the wire field it is written to.
38 #[error(transparent)]
39 FieldOverflow(#[from] broadcast_common::error::FieldOverflow),
40}