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

DecryptedJoinAcceptPayload represents a decrypted JoinAccept.

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

Implementations§

source§

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

source

pub fn validate_mic(&self, key: &AppKey) -> bool

Verifies that the JoinAccept has correct MIC.

source

pub fn calculate_mic(&self, key: &AppKey) -> MIC

source

pub fn derive_newskey<TT: AsRef<[u8]>>( &self, dev_nonce: &DevNonce<TT>, key: &AppKey ) -> NewSKey

Computes the network session key for a given device.

Argument
  • app_nonce - the network server nonce.
  • nwk_addr - the address of the network.
  • dev_nonce - the nonce from the device.
  • key - the app key.
Examples
let dev_nonce = vec![0xcc, 0xdd];
let data = vec![0x20, 0x49, 0x3e, 0xeb, 0x51, 0xfb, 0xa2, 0x11, 0x6f, 0x81, 0x0e, 0xdb, 0x37,
    0x42, 0x97, 0x51, 0x42];
let app_key = lorawan::keys::AppKey::from([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
    0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff]);
let join_accept = lorawan::parser::DecryptedJoinAcceptPayload::new(data, &app_key).unwrap();

let nwk_skey = join_accept.derive_newskey(
    &lorawan::parser::DevNonce::new(&dev_nonce[..]).unwrap(),
    &app_key,
);
source

pub fn derive_appskey<TT: AsRef<[u8]>>( &self, dev_nonce: &DevNonce<TT>, key: &AppKey ) -> AppSKey

Computes the application session key for a given device.

Argument
  • app_nonce - the network server nonce.
  • nwk_addr - the address of the network.
  • dev_nonce - the nonce from the device.
  • key - the app key.
Examples
let dev_nonce = vec![0xcc, 0xdd];
let data = vec![0x20, 0x49, 0x3e, 0xeb, 0x51, 0xfb, 0xa2, 0x11, 0x6f, 0x81, 0x0e, 0xdb, 0x37,
    0x42, 0x97, 0x51, 0x42];
let app_key = lorawan::keys::AppKey::from([0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
    0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff]);
let join_accept = lorawan::parser::DecryptedJoinAcceptPayload::new(data, &app_key).unwrap();

let app_skey = join_accept.derive_appskey(
    &lorawan::parser::DevNonce::new(&dev_nonce[..]).unwrap(),
    &app_key,
);
source§

impl<T: AsRef<[u8]>, F> DecryptedJoinAcceptPayload<T, F>

source

pub fn app_nonce(&self) -> AppNonce<&[u8]>

Gives the app nonce of the JoinAccept.

source

pub fn net_id(&self) -> NwkAddr<&[u8]>

Gives the net ID of the JoinAccept.

source

pub fn dev_addr(&self) -> DevAddr<&[u8]>

Gives the dev address of the JoinAccept.

source

pub fn dl_settings(&self) -> DLSettings

Gives the downlink configuration of the JoinAccept.

source

pub fn rx_delay(&self) -> u8

Gives the RX delay of the JoinAccept.

source

pub fn c_f_list(&self) -> Option<CfList<'_>>

Gives the channel frequency list of the JoinAccept.

source§

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

source

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

Creates a DecryptedJoinAcceptPayload from the bytes of a JoinAccept.

The JoinAccept payload is automatically decrypted and the mic is verified using the suplied crypto factory implementation.

Argument
  • bytes - the data from which the PhyPayload is to be built.
  • key - the key that is to be used to decrypt the payload.
  • factory - the factory that shall be used to create object for crypto functions.
source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> DecryptedJoinAcceptPayload<T, DefaultFactory>

source

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

Creates a DecryptedJoinAcceptPayload from the bytes of a JoinAccept.

The JoinAccept payload is automatically decrypted and the mic is verified.

Argument
  • bytes - the data from which the PhyPayload is to be built.
  • key - the key that is to be used to decrypt the payload.
Examples
let mut data = vec![0x20u8, 0x49u8, 0x3eu8, 0xebu8, 0x51u8, 0xfbu8,
    0xa2u8, 0x11u8, 0x6fu8, 0x81u8, 0x0eu8, 0xdbu8, 0x37u8, 0x42u8,
    0x97u8, 0x51u8, 0x42u8];
let key = lorawan::keys::AppKey::from([2; 16]);
let phy = lorawan::parser::DecryptedJoinAcceptPayload::new(&mut data[..], &key);

Trait Implementations§

source§

impl<T: AsRef<[u8]>, F> AsPhyPayloadBytes for DecryptedJoinAcceptPayload<T, F>

source§

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

source§

impl<T: Debug, F: Debug> Debug for DecryptedJoinAcceptPayload<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 DecryptedJoinAcceptPayload<T, F>

source§

fn eq(&self, other: &DecryptedJoinAcceptPayload<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 DecryptedJoinAcceptPayload<T, F>

source§

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

source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T, F> UnwindSafe for DecryptedJoinAcceptPayload<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> 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.