[−][src]Struct lorawan::parser::EncryptedDataPayload
EncryptedDataPayload represents an encrypted data payload.
It can be built either directly through the new or using the parse function.
Implementations
impl<T: AsRef<[u8]>, F: CryptoFactory> EncryptedDataPayload<T, F>
[src]
pub fn new_with_factory<'a>(data: T, factory: F) -> Result<Self, &'a str>
[src]
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.
pub fn validate_mic(&self, key: &AES128, fcnt: u32) -> bool
[src]
Verifies that the DataPayload has correct MIC.
impl<T: AsRef<[u8]> + AsMut<[u8]>, F: CryptoFactory> EncryptedDataPayload<T, F>
[src]
pub fn decrypt<'a, 'b>(
self,
nwk_skey: Option<&'a AES128>,
app_skey: Option<&'a AES128>,
fcnt: u32
) -> Result<DecryptedDataPayload<T>, &'b str>
[src]
self,
nwk_skey: Option<&'a AES128>,
app_skey: Option<&'a AES128>,
fcnt: u32
) -> Result<DecryptedDataPayload<T>, &'b str>
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);
pub fn decrypt_if_mic_ok<'a>(
self,
nwk_skey: &'a AES128,
app_skey: &'a AES128,
fcnt: u32
) -> Result<DecryptedDataPayload<T>, Self>
[src]
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.
impl<T: AsRef<[u8]>> EncryptedDataPayload<T, DefaultFactory>
[src]
Trait Implementations
impl<T: AsRef<[u8]>, F> DataHeader for EncryptedDataPayload<T, F>
[src]
fn as_data_bytes(&self) -> &[u8]
[src]
fn fhdr(&self) -> FHDR
[src]
fn is_uplink(&self) -> bool
[src]
fn f_port(&self) -> Option<u8>
[src]
fn fhdr_length(&self) -> usize
[src]
impl<T: Debug, F: Debug> Debug for EncryptedDataPayload<T, F>
[src]
impl<T: PartialEq, F: PartialEq> PartialEq<EncryptedDataPayload<T, F>> for EncryptedDataPayload<T, F>
[src]
fn eq(&self, other: &EncryptedDataPayload<T, F>) -> bool
[src]
fn ne(&self, other: &EncryptedDataPayload<T, F>) -> bool
[src]
impl<T, F> StructuralPartialEq for EncryptedDataPayload<T, F>
[src]
Auto Trait Implementations
impl<T, F> RefUnwindSafe for EncryptedDataPayload<T, F> where
F: RefUnwindSafe,
T: RefUnwindSafe,
F: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, F> Send for EncryptedDataPayload<T, F> where
F: Send,
T: Send,
F: Send,
T: Send,
impl<T, F> Sync for EncryptedDataPayload<T, F> where
F: Sync,
T: Sync,
F: Sync,
T: Sync,
impl<T, F> Unpin for EncryptedDataPayload<T, F> where
F: Unpin,
T: Unpin,
F: Unpin,
T: Unpin,
impl<T, F> UnwindSafe for EncryptedDataPayload<T, F> where
F: UnwindSafe,
T: UnwindSafe,
F: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AsPhyPayloadBytes for T where
T: DataHeader,
[src]
T: DataHeader,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> MHDRAble for T where
T: AsPhyPayloadBytes,
[src]
T: AsPhyPayloadBytes,
impl<T> MICAble for T where
T: AsPhyPayloadBytes,
[src]
T: AsPhyPayloadBytes,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,