pub struct EncryptedDataPayload<T, F>(/* private fields */);
Expand description

EncryptedDataPayload represents an encrypted data payload.

It can be built either directly through the new or using the parse function.

Implementations§

source§

impl<T: AsRef<[u8]>, F: CryptoFactory> EncryptedDataPayload<T, F>

source

pub fn new_with_factory(data: T, factory: F) -> Result<Self, Error>

Creates a new EncryptedDataPayload if the provided data is acceptable.

Argument
  • data - the bytes for the payload.
  • factory - the factory that shall be used to create object for crypto functions.
source

pub fn validate_mic(&self, key: &AES128, fcnt: u32) -> bool

Verifies that the DataPayload has correct MIC.

source§

impl<T: AsRef<[u8]> + AsMut<[u8]>, F: CryptoFactory> EncryptedDataPayload<T, F>

source

pub fn decrypt<'a>( self, nwk_skey: Option<&'a AES128>, app_skey: Option<&'a AES128>, fcnt: u32 ) -> Result<DecryptedDataPayload<T>, Error>

Decrypts the EncryptedDataPayload payload.

This method consumes the EncryptedDataPayload as it reuses the underlying memory. Please note that it does not verify the mic.

If used on the application server side for application payload decryption, the nwk_skey can be None. If used on the network server side and the app_skey is not available, app_skey can be None when fport is 0. Failure to meet those constraints will result in an Err being returned.

Argument
  • nwk_skey - the Network Session key used to decrypt the mac commands in case the payload is transporting those.
  • app_skey - the Application Session key used to decrypt the application payload in case the payload is transporting that.
  • fcnt - the counter used to encrypt the payload.
Examples
let mut data = vec![0x40, 0x04, 0x03, 0x02, 0x01, 0x80, 0x01, 0x00, 0x01,
    0xa6, 0x94, 0x64, 0x26, 0x15, 0xd6, 0xc3, 0xb5, 0x82];
let key = lorawan::keys::AES128([1; 16]);
let enc_phy = lorawan::parser::EncryptedDataPayload::new(data).unwrap();
let dec_phy = enc_phy.decrypt(None, Some(&key), 1);
source

pub fn decrypt_if_mic_ok<'a>( self, nwk_skey: &'a AES128, app_skey: &'a AES128, fcnt: u32 ) -> Result<DecryptedDataPayload<T>, Self>

Verifies the mic and decrypts the EncryptedDataPayload payload if mic matches.

This is helper method that combines validate_mic and decrypt. In case the mic is fine, it consumes the EncryptedDataPayload and reuses the underlying memory to produce DecryptedDataPayload. If the mic does not match, it returns the original EncryptedDataPayload so that it can be tried against the keys of another device that shares the same dev_addr. For an example please see decrypt.

source§

impl<T: AsRef<[u8]>> EncryptedDataPayload<T, DefaultFactory>

source

pub fn new(data: T) -> Result<Self, Error>

Creates a PhyPayload from bytes.

Argument
  • bytes - the data from which the PhyPayload is to be built.
Examples
let mut data = vec![0x40, 0x04, 0x03, 0x02, 0x01, 0x80, 0x01, 0x00, 0x01,
    0xa6, 0x94, 0x64, 0x26, 0x15, 0xd6, 0xc3, 0xb5, 0x82];
let phy = lorawan::parser::EncryptedDataPayload::new(data);

Trait Implementations§

source§

impl<T: AsRef<[u8]>, F> DataHeader for EncryptedDataPayload<T, F>

source§

fn as_data_bytes(&self) -> &[u8]

Equivalent to AsRef<u8>.
source§

fn fhdr(&self) -> FHDR<'_>

Gives the FHDR of the DataPayload.
source§

fn is_confirmed(&self) -> bool

Gives whether the frame is confirmed
Gives whether the payload is uplink or not.
source§

fn f_port(&self) -> Option<u8>

Gives the FPort of the DataPayload if there is one.
source§

fn fhdr_length(&self) -> usize

Gives the length of the FHDR field.
source§

impl<T: Debug, F: Debug> Debug for EncryptedDataPayload<T, F>

source§

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

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

impl<T: PartialEq, F: PartialEq> PartialEq for EncryptedDataPayload<T, F>

source§

fn eq(&self, other: &EncryptedDataPayload<T, F>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq, F: Eq> Eq for EncryptedDataPayload<T, F>

source§

impl<T, F> StructuralEq for EncryptedDataPayload<T, F>

source§

impl<T, F> StructuralPartialEq for EncryptedDataPayload<T, F>

Auto Trait Implementations§

§

impl<T, F> RefUnwindSafe for EncryptedDataPayload<T, F>

§

impl<T, F> Send for EncryptedDataPayload<T, F>
where F: Send, T: Send,

§

impl<T, F> Sync for EncryptedDataPayload<T, F>
where F: Sync, T: Sync,

§

impl<T, F> Unpin for EncryptedDataPayload<T, F>
where F: Unpin, T: Unpin,

§

impl<T, F> UnwindSafe for EncryptedDataPayload<T, F>
where F: UnwindSafe, T: UnwindSafe,

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> AsPhyPayloadBytes for T
where T: DataHeader,

source§

fn as_bytes(&self) -> &[u8]

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> MHDRAble for T

source§

fn mhdr(&self) -> MHDR

Gives the MIC of the PhyPayload.
source§

impl<T> MICAble for T

source§

fn mic(&self) -> MIC

Gives the MIC of the PhyPayload.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.