proto: Fix a type-complexity warning.

This commit is contained in:
Nick Mathewson 2023-08-04 09:29:50 -04:00
parent 65a0ac5512
commit d46e638ff0
2 changed files with 21 additions and 9 deletions

View File

@ -623,11 +623,13 @@ impl ClientCirc {
seed: impl handshake::KeyGenerator, seed: impl handshake::KeyGenerator,
params: CircParameters, params: CircParameters,
) -> Result<()> { ) -> 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 (tx, rx) = oneshot::channel();
let message = CtrlMsg::ExtendVirtual { let message = CtrlMsg::ExtendVirtual {
cell_crypto: (outbound, inbound, binding), cell_crypto: (fwd, back, binding),
params, params,
done: tx, done: tx,
}; };

View File

@ -42,19 +42,25 @@ pub enum HandshakeRole {
Responder, 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<dyn OutboundClientLayer + Send>,
/// The inbound cryptogarphic layer to use for this hop
pub(crate) back: Box<dyn InboundClientLayer + Send>,
/// A circuit binding key for this hop.
pub(crate) binding: Option<CircuitBinding>,
}
impl RelayProtocol { impl RelayProtocol {
/// Construct the cell-crypto layers that are needed for a given set of /// Construct the cell-crypto layers that are needed for a given set of
/// circuit hop parameters. /// circuit hop parameters.
#[allow(clippy::type_complexity)] // XXXX
pub(crate) fn construct_layers( pub(crate) fn construct_layers(
self, self,
role: HandshakeRole, role: HandshakeRole,
keygen: impl KeyGenerator, keygen: impl KeyGenerator,
) -> Result<( ) -> Result<BoxedClientLayer> {
Box<dyn OutboundClientLayer + Send>,
Box<dyn InboundClientLayer + Send>,
Option<CircuitBinding>,
)> {
match self { match self {
RelayProtocol::HsV3 => { RelayProtocol::HsV3 => {
let seed_needed = Tor1Hsv3RelayCrypto::seed_len(); let seed_needed = Tor1Hsv3RelayCrypto::seed_len();
@ -65,7 +71,11 @@ impl RelayProtocol {
HandshakeRole::Initiator => (fwd, back), HandshakeRole::Initiator => (fwd, back),
HandshakeRole::Responder => (back, fwd), 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),
})
} }
} }
} }