Driver: Update the head and tail offsets returned from decrypt_*_in_place(). (#281)
* Correct the head and tail offsets returned from decrypt_*_in_place(). * Incorporate formatting changes from `cargo make ready`
This commit is contained in:
@@ -407,19 +407,19 @@ impl Cipher {
|
|||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
let (mut start_estimate, end) = self.decrypt_pkt_in_place(packet, plain_bytes)?;
|
let (_, end) = self.decrypt_pkt_in_place(packet, plain_bytes)?;
|
||||||
|
|
||||||
// Update the start estimate to account for bytes occupied by extension headers.
|
// Update the start estimate to account for bytes occupied by extension headers.
|
||||||
if has_extension {
|
let payload_offset = if has_extension {
|
||||||
let packet = packet.packet();
|
let payload = packet.payload();
|
||||||
if let Some((_, exts_and_opus)) = split_at_checked(packet, start_estimate) {
|
let extension =
|
||||||
let extension = RtpExtensionPacket::new(exts_and_opus)
|
RtpExtensionPacket::new(payload).ok_or(InternalError::IllegalVoicePacket)?;
|
||||||
.ok_or(InternalError::IllegalVoicePacket)?;
|
extension.packet().len() - extension.payload().len()
|
||||||
start_estimate += extension.packet().len() - extension.payload().len();
|
} else {
|
||||||
}
|
0
|
||||||
}
|
};
|
||||||
|
|
||||||
Ok((start_estimate, end))
|
Ok((payload_offset, end))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "receive")]
|
#[cfg(feature = "receive")]
|
||||||
@@ -484,23 +484,15 @@ impl Cipher {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((plaintext_end + pre_payload.len(), post_payload.len()))
|
Ok((
|
||||||
|
plaintext_end + pre_payload.len(),
|
||||||
|
post_payload.len() + slice_to_use.len(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary functions -- MSRV is ostensibly 1.74, slice::split_at(_mut)_checked is 1.80+.
|
// Temporary functions -- MSRV is ostensibly 1.74, slice::split_at(_mut)_checked is 1.80+.
|
||||||
// TODO: Remove in v0.5+ with MSRV bump to 1.81+.
|
// TODO: Remove in v0.5+ with MSRV bump to 1.81+.
|
||||||
#[cfg(any(feature = "receive", test))]
|
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
|
||||||
const fn split_at_checked(els: &[u8], mid: usize) -> Option<(&[u8], &[u8])> {
|
|
||||||
if mid <= els.len() {
|
|
||||||
Some(els.split_at(mid))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "receive", test))]
|
#[cfg(any(feature = "receive", test))]
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|||||||
Reference in New Issue
Block a user