Struct lorawan::parser::DecryptedJoinAcceptPayload
source · 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>
impl<T: AsRef<[u8]>, F: CryptoFactory> DecryptedJoinAcceptPayload<T, F>
sourcepub fn validate_mic(&self, key: &AppKey) -> bool
pub fn validate_mic(&self, key: &AppKey) -> bool
Verifies that the JoinAccept has correct MIC.
pub fn calculate_mic(&self, key: &AppKey) -> MIC
sourcepub fn derive_newskey<TT: AsRef<[u8]>>(
&self,
dev_nonce: &DevNonce<TT>,
key: &AppKey,
) -> NewSKey
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,
);
sourcepub fn derive_appskey<TT: AsRef<[u8]>>(
&self,
dev_nonce: &DevNonce<TT>,
key: &AppKey,
) -> AppSKey
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>
impl<T: AsRef<[u8]>, F> DecryptedJoinAcceptPayload<T, F>
sourcepub fn dl_settings(&self) -> DLSettings
pub fn dl_settings(&self) -> DLSettings
Gives the downlink configuration of the JoinAccept.
source§impl<T: AsRef<[u8]> + AsMut<[u8]>, F: CryptoFactory> DecryptedJoinAcceptPayload<T, F>
impl<T: AsRef<[u8]> + AsMut<[u8]>, F: CryptoFactory> DecryptedJoinAcceptPayload<T, F>
sourcepub fn new_with_factory(
data: T,
key: &AppKey,
factory: F,
) -> Result<Self, Error>
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>
impl<T: AsRef<[u8]> + AsMut<[u8]>> DecryptedJoinAcceptPayload<T, DefaultFactory>
sourcepub fn new(data: T, key: &AppKey) -> Result<Self, Error>
Available on crate feature default-crypto
only.
pub fn new(data: T, key: &AppKey) -> Result<Self, Error>
default-crypto
only.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>
impl<T: AsRef<[u8]>, F> AsPhyPayloadBytes for DecryptedJoinAcceptPayload<T, F>
source§impl<T: PartialEq, F: PartialEq> PartialEq for DecryptedJoinAcceptPayload<T, F>
impl<T: PartialEq, F: PartialEq> PartialEq for DecryptedJoinAcceptPayload<T, F>
source§fn eq(&self, other: &DecryptedJoinAcceptPayload<T, F>) -> bool
fn eq(&self, other: &DecryptedJoinAcceptPayload<T, F>) -> bool
Tests for
self
and other
values to be equal, and is used by ==
.impl<T: Eq, F: Eq> Eq for DecryptedJoinAcceptPayload<T, F>
impl<T, F> StructuralPartialEq for DecryptedJoinAcceptPayload<T, F>
Auto Trait Implementations§
impl<T, F> Freeze for DecryptedJoinAcceptPayload<T, F>
impl<T, F> RefUnwindSafe for DecryptedJoinAcceptPayload<T, F>where
T: RefUnwindSafe,
F: RefUnwindSafe,
impl<T, F> Send for DecryptedJoinAcceptPayload<T, F>
impl<T, F> Sync for DecryptedJoinAcceptPayload<T, F>
impl<T, F> Unpin for DecryptedJoinAcceptPayload<T, F>
impl<T, F> UnwindSafe for DecryptedJoinAcceptPayload<T, F>where
T: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more