Avoid a slice copy in send_relay_cell().
Convert slice to array in the parent function instead of copying.
This commit is contained in:
parent
541883f3df
commit
97f7bc7232
|
@ -731,16 +731,12 @@ impl ClientCircImpl {
|
|||
// If the cell counted towards our sendme window, decrement
|
||||
// that window, and maybe remember the authentication tag.
|
||||
if c_t_w {
|
||||
// XXXX I wish I didn't have to copy the tag.
|
||||
// TODO: I'd like to use get_hops_mut here, but the borrow checker
|
||||
// won't let me.
|
||||
assert!(tag.len() == 20); // XXXX risky
|
||||
let mut tag_copy = [0u8; 20];
|
||||
(&mut tag_copy[..]).copy_from_slice(&tag[..]);
|
||||
// This blocks if the send window is empty.
|
||||
self.hops[Into::<usize>::into(hop)]
|
||||
.sendwindow
|
||||
.take(&tag_copy)
|
||||
.take(&tag)
|
||||
.await?;
|
||||
}
|
||||
self.send_msg(msg).await
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
//!
|
||||
|
||||
use crate::{Error, Result};
|
||||
use std::convert::TryInto;
|
||||
use tor_cell::chancell::RawCellBody;
|
||||
|
||||
use generic_array::GenericArray;
|
||||
|
@ -159,7 +160,7 @@ impl OutboundClientCrypt {
|
|||
///
|
||||
/// On success, returns a reference to tag that should be expected
|
||||
/// for an authenticated SENDME sent in response to this cell.
|
||||
pub fn encrypt(&mut self, cell: &mut RelayCellBody, hop: HopNum) -> Result<&[u8]> {
|
||||
pub fn encrypt(&mut self, cell: &mut RelayCellBody, hop: HopNum) -> Result<&[u8; 20]> {
|
||||
let hop: usize = hop.into();
|
||||
if hop >= self.layers.len() {
|
||||
return Err(Error::NoSuchHop);
|
||||
|
@ -171,7 +172,7 @@ impl OutboundClientCrypt {
|
|||
for layer in layers {
|
||||
layer.encrypt_outbound(cell);
|
||||
}
|
||||
Ok(tag)
|
||||
Ok(tag.try_into().expect("wrong SENDME digest size"))
|
||||
}
|
||||
|
||||
/// Add a new layer to this OutboundClientCrypt
|
||||
|
|
Loading…
Reference in New Issue