|
1 | 1 | use crate::DecoderError; |
2 | | -use bytemuck::{from_bytes, Pod, Zeroable}; |
| 2 | +use bytemuck::{pod_read_unaligned, Pod, Zeroable}; |
3 | 3 | use chacha20poly1305::{AeadInPlace, KeyInit, XChaCha20Poly1305}; |
4 | 4 | use ed25519_dalek::{Signature, Verifier, VerifyingKey, SIGNATURE_LENGTH}; |
5 | 5 | use rand_chacha::ChaCha20Rng; |
@@ -42,7 +42,7 @@ pub fn decrypt_decoder_payload<'a>( |
42 | 42 | return Err(DecoderError::InvalidEncoderPayload); |
43 | 43 | } |
44 | 44 |
|
45 | | - let header: DecoderPayloadHeader = *from_bytes(&payload[..size_of::<DecoderPayloadHeader>()]); |
| 45 | + let header: DecoderPayloadHeader = pod_read_unaligned(&payload[..size_of::<DecoderPayloadHeader>()]); |
46 | 46 |
|
47 | 47 | // first verify signature |
48 | 48 | // signature should include chacha nonce and tag, otherwise attacker can alter nonce and get invalid frame |
@@ -71,12 +71,12 @@ pub fn decrypt_decoder_payload<'a>( |
71 | 71 | } |
72 | 72 |
|
73 | 73 | /// Gets a reference to the associated data of the given decoder payload. |
74 | | -pub fn get_decoder_payload_associated_data<T: Pod>(payload: &[u8]) -> Result<&T, DecoderError> { |
| 74 | +pub fn get_decoder_payload_associated_data<T: Pod>(payload: &[u8]) -> Result<T, DecoderError> { |
75 | 75 | if payload.len() < size_of::<DecoderPayloadHeader>() + size_of::<T>() { |
76 | 76 | Err(DecoderError::InvalidEncoderPayload) |
77 | 77 | } else { |
78 | 78 | let associated_data = &payload[payload.len() - size_of::<T>()..]; |
79 | | - Ok(from_bytes(associated_data)) |
| 79 | + Ok(pod_read_unaligned(associated_data)) |
80 | 80 | } |
81 | 81 | } |
82 | 82 |
|
|
0 commit comments