diff --git a/crates/tor-proto/src/circuit.rs b/crates/tor-proto/src/circuit.rs index f30964055..7372a8ea1 100644 --- a/crates/tor-proto/src/circuit.rs +++ b/crates/tor-proto/src/circuit.rs @@ -623,11 +623,13 @@ impl ClientCirc { seed: impl handshake::KeyGenerator, params: CircParameters, ) -> Result<()> { - let (outbound, inbound, binding) = protocol.construct_layers(role, seed)?; + use self::handshake::BoxedClientLayer; + + let BoxedClientLayer { fwd, back, binding } = protocol.construct_layers(role, seed)?; let (tx, rx) = oneshot::channel(); let message = CtrlMsg::ExtendVirtual { - cell_crypto: (outbound, inbound, binding), + cell_crypto: (fwd, back, binding), params, done: tx, }; diff --git a/crates/tor-proto/src/circuit/handshake.rs b/crates/tor-proto/src/circuit/handshake.rs index f8803a648..a771aa4ac 100644 --- a/crates/tor-proto/src/circuit/handshake.rs +++ b/crates/tor-proto/src/circuit/handshake.rs @@ -42,19 +42,25 @@ pub enum HandshakeRole { Responder, } +/// A set of type-erased cryptographic layers to use for a single hop at a +/// client. +pub(crate) struct BoxedClientLayer { + /// The outbound cryptographic layer to use for this hop + pub(crate) fwd: Box, + /// The inbound cryptogarphic layer to use for this hop + pub(crate) back: Box, + /// A circuit binding key for this hop. + pub(crate) binding: Option, +} + impl RelayProtocol { /// Construct the cell-crypto layers that are needed for a given set of /// circuit hop parameters. - #[allow(clippy::type_complexity)] // XXXX pub(crate) fn construct_layers( self, role: HandshakeRole, keygen: impl KeyGenerator, - ) -> Result<( - Box, - Box, - Option, - )> { + ) -> Result { match self { RelayProtocol::HsV3 => { let seed_needed = Tor1Hsv3RelayCrypto::seed_len(); @@ -65,7 +71,11 @@ impl RelayProtocol { HandshakeRole::Initiator => (fwd, back), HandshakeRole::Responder => (back, fwd), }; - Ok((Box::new(fwd), Box::new(back), Some(binding))) + Ok(BoxedClientLayer { + fwd: Box::new(fwd), + back: Box::new(back), + binding: Some(binding), + }) } } }