From 0df72449b8596ce22ceb5798c294c676bc45e8f2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 8 Jul 2022 12:15:41 +0100 Subject: [PATCH] chancell: PaddingNegotiate: Provide two constructors, not one We don't really want the caller to pass ignored timeout parameters. And this makes more semantic sense. The stop constructor uses zero, which is what C Tor does. See https://gitlab.torproject.org/tpo/core/torspec/-/merge_requests/76 --- crates/tor-cell/src/chancell/msg.rs | 21 ++++++++++++++------- crates/tor-cell/tests/testvec_chanmsg.rs | 8 +++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/tor-cell/src/chancell/msg.rs b/crates/tor-cell/src/chancell/msg.rs index 90397f54c..8723df419 100644 --- a/crates/tor-cell/src/chancell/msg.rs +++ b/crates/tor-cell/src/chancell/msg.rs @@ -816,18 +816,25 @@ pub struct PaddingNegotiate { ito_high_ms: u16, } impl PaddingNegotiate { - /// Create a new PaddingNegotiate message. - /// - /// If `start` is true, this is a message to enable padding. Otherwise - /// this is a message to disable padding. - pub fn new(start: bool, ito_low_ms: u16, ito_high_ms: u16) -> Self { - let command = if start { 2 } else { 1 }; + /// Create a new PADDING_NEGOTIATE START message. + pub fn start(ito_low_ms: u16, ito_high_ms: u16) -> Self { + // Tor Spec section 7.3 Self { - command, + command: 2, ito_low_ms, ito_high_ms, } } + + /// Create a new PADDING_NEGOTIATE STOP message. + pub fn stop() -> Self { + // Tor Spec section 7.3 + Self { + command: 1, + ito_low_ms: 0, + ito_high_ms: 0, + } + } } impl Body for PaddingNegotiate { fn into_message(self) -> ChanMsg { diff --git a/crates/tor-cell/tests/testvec_chanmsg.rs b/crates/tor-cell/tests/testvec_chanmsg.rs index e483b22ef..a6a018048 100644 --- a/crates/tor-cell/tests/testvec_chanmsg.rs +++ b/crates/tor-cell/tests/testvec_chanmsg.rs @@ -395,7 +395,13 @@ fn test_padding_negotiate() { fbody( cmd, "00 02 0100 0200", - &msg::PaddingNegotiate::new(true, 256, 512).into(), + &msg::PaddingNegotiate::start(256, 512).into(), + ); + + fbody( + cmd, + "00 01 0000 0000", + &msg::PaddingNegotiate::stop().into(), ); assert_eq!(