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
This commit is contained in:
parent
ecd6f16b6e
commit
0df72449b8
|
@ -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 {
|
||||
|
|
|
@ -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!(
|
||||
|
|
Loading…
Reference in New Issue