pub enum Error {
Show 18 variants
TooShort {
expected: usize,
got: usize,
},
TooLong {
got: usize,
},
InvalidMType(u8),
InvalidMajor(u8),
InvalidRejoinType(u8),
ConflictingMacCommands,
FOptsTooLong(usize),
InvalidKeyLength {
expected: usize,
got: usize,
},
InvalidIdentifierLength {
expected: usize,
got: usize,
},
MicMismatch,
MissingKey(&'static str),
UnsupportedForVersion(&'static str),
MissingField(&'static str),
PayloadTooLarge(usize),
InvalidJoinAcceptLength(usize),
Other(String),
Hex(FromHexError),
Base64(DecodeError),
}Expand description
Every error this crate can produce.
Variants split into three rough buckets:
- Parsing (
Error::TooShort,Error::TooLong,Error::InvalidMType,Error::InvalidMajor,Error::InvalidRejoinType,Error::ConflictingMacCommands,Error::FOptsTooLong,Error::InvalidJoinAcceptLength). - Construction (
Error::InvalidKeyLength,Error::InvalidIdentifierLength,Error::MissingField,Error::PayloadTooLarge). - Crypto / MIC (
Error::MicMismatch,Error::MissingKey,Error::UnsupportedForVersion).
The Other, Hex, and Base64 variants exist for boundary conversions
and should not need to be matched in normal code paths.
Variants§
TooShort
Wire buffer ran out before the expected structure was complete.
Both expected and got are in bytes. Always inspect both fields; the
expected value differs by message type (5 for the minimum
PHYPayload, 18 for a Join Request body, etc.).
TooLong
Wire buffer exceeded the LoRaWAN PHY maximum of 256 bytes.
PHY payload size varies by region but never exceeds 256 bytes total in
any LoRaWAN regional plan. Beyond this limit, the 1-byte length field
in CMAC B0/B1 blocks would silently wrap and produce a deterministic
but wrong MIC. Reject the input early.
InvalidMType(u8)
MType field in the MHDR did not match any known value.
All 3-bit patterns are currently defined by the LoRaWAN spec, so this
variant is reserved for forward compatibility.
InvalidMajor(u8)
Major version field in the MHDR was not zero (the only defined value).
InvalidRejoinType(u8)
Rejoin Request type was not 0, 1, or 2.
ConflictingMacCommands
FRMPayload present with FPort = 0 alongside non-empty FOpts.
The LoRaWAN MAC spec forbids carrying MAC commands in both places at
once.
FOptsTooLong(usize)
FOpts exceeds the 15-byte maximum encoded in FCtrl.FOptsLen.
Returned by crate::LoraPacketBuilder::build_unsigned when the
builder’s f_opts vector is too long; not raised by wire parsing
because FCtrl only carries 4 bits of length.
InvalidKeyLength
A key slice supplied to from_slice had the wrong length.
All LoRaWAN keys are 16 bytes (AES-128).
InvalidIdentifierLength
An identifier slice supplied to from_slice had the wrong length.
Lengths per identifier: DevAddr = 4, NetId = 3, DevEui /
AppEui = 8, DevNonce = 2, AppNonce = 3.
MicMismatch
MIC verification failed.
The compare is constant-time (via subtle::ConstantTimeEq). Treat this
as a security event, not a parse error.
MissingKey(&'static str)
A MIC or crypto operation required a key that was not supplied.
The string argument names the missing role (e.g. "nwk_s_key required for Data MIC").
UnsupportedForVersion(&'static str)
An API call was made on a message type the chosen LoRaWAN version does
not support.
Example: calculate_mic_v1_0 called on a Rejoin Request or Proprietary
frame (both 1.1-only). The string names which API to call instead.
MissingField(&'static str)
Builder finalisation failed because a required field was not set.
The string argument names the field ("dev_addr", "join_eui", etc.).
Match on the field name to suggest a builder method to set it.
PayloadTooLarge(usize)
FRMPayload exceeded the AES-CTR block-index limit (255 blocks =
4080 bytes).
Beyond this size, the 1-byte block counter in the keystream block would
overflow and silently produce ciphertext no other LoRaWAN stack can
decrypt.
InvalidJoinAcceptLength(usize)
Join Accept ciphertext had a length outside the valid range.
A Join Accept is one AES block (17 bytes total: MHDR + 1 block + MIC)
or two blocks with a CFList (33 bytes total).
Other(String)
Catch-all carrying a free-form message. Used sparingly for situations no other variant fits; downstream code should not match on the string.
Hex(FromHexError)
Hex decoding failed (only with the hex_base64 feature).
Base64(DecodeError)
Base64 decoding failed (only with the hex_base64 feature).
Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<DecodeError> for Error
Available on crate feature hex_base64 only.
impl From<DecodeError> for Error
hex_base64 only.Source§fn from(e: DecodeError) -> Self
fn from(e: DecodeError) -> Self
Source§impl From<FromHexError> for Error
Available on crate feature hex_base64 only.
impl From<FromHexError> for Error
hex_base64 only.