Struct lorawan::parser::EncryptedDataPayload
source · pub struct EncryptedDataPayload<T, F>(/* private fields */);
Expand description
Implementations§
source§impl<T: AsRef<[u8]>, F: CryptoFactory> EncryptedDataPayload<T, F>
impl<T: AsRef<[u8]>, F: CryptoFactory> EncryptedDataPayload<T, F>
sourcepub fn new_with_factory(data: T, factory: F) -> Result<Self, Error>
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.
sourcepub fn validate_mic(&self, key: &AES128, fcnt: u32) -> bool
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>
impl<T: AsRef<[u8]> + AsMut<[u8]>, F: CryptoFactory> EncryptedDataPayload<T, F>
sourcepub fn decrypt<'a>(
self,
nwk_skey: Option<&'a AES128>,
app_skey: Option<&'a AES128>,
fcnt: u32
) -> Result<DecryptedDataPayload<T>, Error>
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);
sourcepub fn decrypt_if_mic_ok<'a>(
self,
nwk_skey: &'a AES128,
app_skey: &'a AES128,
fcnt: u32
) -> Result<DecryptedDataPayload<T>, Self>
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>
impl<T: AsRef<[u8]>> EncryptedDataPayload<T, DefaultFactory>
Trait Implementations§
source§impl<T: AsRef<[u8]>, F> DataHeader for EncryptedDataPayload<T, F>
impl<T: AsRef<[u8]>, F> DataHeader for EncryptedDataPayload<T, F>
source§fn is_confirmed(&self) -> bool
fn is_confirmed(&self) -> bool
source§fn fhdr_length(&self) -> usize
fn fhdr_length(&self) -> usize
source§impl<T: PartialEq, F: PartialEq> PartialEq for EncryptedDataPayload<T, F>
impl<T: PartialEq, F: PartialEq> PartialEq for EncryptedDataPayload<T, F>
source§fn eq(&self, other: &EncryptedDataPayload<T, F>) -> bool
fn eq(&self, other: &EncryptedDataPayload<T, F>) -> bool
self
and other
values to be equal, and is used
by ==
.