Skip to main content

Error

Enum Error 

Source
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:

  1. Parsing (Error::TooShort, Error::TooLong, Error::InvalidMType, Error::InvalidMajor, Error::InvalidRejoinType, Error::ConflictingMacCommands, Error::FOptsTooLong, Error::InvalidJoinAcceptLength).
  2. Construction (Error::InvalidKeyLength, Error::InvalidIdentifierLength, Error::MissingField, Error::PayloadTooLarge).
  3. 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.).

Fields

§expected: usize

Required minimum length.

§got: usize

Actual length provided.

§

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.

Fields

§got: usize

Actual length provided.

§

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).

Fields

§expected: usize

Required length.

§got: usize

Actual slice length.

§

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.

Fields

§expected: usize

Required length.

§got: usize

Actual slice length.

§

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 Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DecodeError> for Error

Available on crate feature hex_base64 only.
Source§

fn from(e: DecodeError) -> Self

Converts to this type from the input type.
Source§

impl From<FromHexError> for Error

Available on crate feature hex_base64 only.
Source§

fn from(e: FromHexError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.