tor-proto: Remove use of arrayref.

This commit is contained in:
Nick Mathewson 2023-06-01 10:32:00 -04:00
parent 244ec5dce2
commit 46d2a768a1
4 changed files with 10 additions and 6 deletions

1
Cargo.lock generated
View File

@ -4377,7 +4377,6 @@ dependencies = [
name = "tor-proto"
version = "0.10.0"
dependencies = [
"arrayref",
"asynchronous-codec",
"bytes",
"cipher",

View File

@ -48,7 +48,6 @@ tokio = ["tokio-crate", "tokio-util"]
__is_experimental = []
[dependencies]
arrayref = "0.3"
asynchronous-codec = "0.6.0"
bytes = "1"
cipher = { version = "0.4.1", features = ["zeroize"] }

View File

@ -1,6 +1,5 @@
//! Implementations for the channel handshake
use arrayref::array_ref;
use asynchronous_codec as futures_codec;
use futures::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use futures::sink::SinkExt;
@ -209,7 +208,11 @@ impl<T: AsyncRead + AsyncWrite + Send + Unpin + 'static, S: SleepProvider>
if hdr[0..3] != [0, 0, ChanCmd::VERSIONS.into()] {
return not_relay();
}
let msglen = u16::from_be_bytes(*array_ref![hdr, 3, 2]);
let msglen = u16::from_be_bytes(
hdr[3..5]
.try_into()
.expect("Two-byte field was not two bytes!?"),
);
let mut msg = vec![0; msglen as usize];
self.tls
.read_exact(&mut msg)

View File

@ -414,10 +414,13 @@ pub(crate) mod tor1 {
rcvd: &mut GenericArray<u8, D::OutputSize>,
) -> bool {
use crate::util::ct;
use arrayref::array_ref;
// Validate 'Recognized' field
let recognized = u16::from_be_bytes(*array_ref![self.0, 1, 2]);
let recognized = u16::from_be_bytes(
self.0[1..3]
.try_into()
.expect("Two-byte field was not two bytes!?"),
);
if recognized != 0 {
return false;
}