Beautify some Vec->array code in tor-proto.

[T;N] supports TryFrom<Vec<T>>, and has since Rust 1.48: we can just
use that.

This resolves an XXXX comment.
This commit is contained in:
Nick Mathewson 2021-12-08 13:59:17 -05:00
parent 91ab3a7eda
commit d0b217d1a5
1 changed files with 7 additions and 6 deletions

View File

@ -12,6 +12,7 @@ use crate::crypto::cell::{
use crate::util::err::ReactorError;
use crate::{Error, Result};
use std::collections::VecDeque;
use std::convert::TryFrom;
use std::marker::PhantomData;
use std::pin::Pin;
use tor_cell::chancell::msg::{ChanMsg, Relay};
@ -823,13 +824,13 @@ impl Reactor {
.ok_or_else(|| Error::CircProto(format!("Couldn't find {} hop", hopnum)))?;
let auth: Option<[u8; 20]> = match msg.into_tag() {
Some(v) if v.len() == 20 => {
// XXXX ugly code.
let mut tag = [0_u8; 20];
(&mut tag).copy_from_slice(&v[..]);
Some(tag)
Some(v) => {
if let Ok(tag) = <[u8; 20]>::try_from(v) {
Some(tag)
} else {
return Err(Error::CircProto("malformed tag on circuit sendme".into()));
}
}
Some(_) => return Err(Error::CircProto("malformed tag on circuit sendme".into())),
None => {
if !hop.auth_sendme_optional {
return Err(Error::CircProto("missing tag on circuit sendme".into()));