From 21e8cc14d55f753db5bb0bf2a285ae444277b442 Mon Sep 17 00:00:00 2001
From: Matt Johnston <matt@ucc.asn.au>
Date: Thu, 22 Sep 2022 23:36:38 +0800
Subject: [PATCH] Fix various warnings, remove dead code

---
 async/src/async_door.rs  |  2 +-
 sshproto/src/channel.rs  | 92 +++-------------------------------------
 sshproto/src/conn.rs     | 25 ++---------
 sshproto/src/lib.rs      |  7 ++-
 sshproto/src/runner.rs   |  5 +--
 sshproto/src/servauth.rs |  2 +-
 sshproto/src/sshnames.rs |  1 -
 sshproto/src/sshwire.rs  |  2 +-
 sshproto/src/traffic.rs  |  4 --
 9 files changed, 17 insertions(+), 123 deletions(-)

diff --git a/async/src/async_door.rs b/async/src/async_door.rs
index 9dd764c..a76f3d5 100644
--- a/async/src/async_door.rs
+++ b/async/src/async_door.rs
@@ -19,7 +19,7 @@ use core::ops::DerefMut;
 use std::sync::Arc;
 
 use door_sshproto as door;
-use door::{Runner, Result, Event, ChanEvent, Behaviour};
+use door::{Runner, Result, Behaviour};
 
 use pretty_hex::PrettyHex;
 
diff --git a/sshproto/src/channel.rs b/sshproto/src/channel.rs
index 5fd560f..175a2e1 100644
--- a/sshproto/src/channel.rs
+++ b/sshproto/src/channel.rs
@@ -30,7 +30,7 @@ pub enum ChanOpened {
 pub(crate) struct Channels {
     ch: [Option<Channel>; config::MAX_CHANNELS],
 
-    /// The size of data last set with `ChanEvent::DataIn`.
+    /// The size of channel data last set with `DataIn`.
     pending_input: Option<PendInput>,
 }
 
@@ -252,7 +252,7 @@ impl Channels {
         let r = match &p.ty {
             ChannelOpenType::Session => {
                 // unwrap: earlier test ensures b.server() succeeds
-                let mut bserv = b.server().unwrap();
+                let bserv = b.server().unwrap();
                 bserv.open_session(ch.num())
             }
             ChannelOpenType::ForwardedTcpip(t) => b.open_tcp_forwarded(ch.num(), t),
@@ -319,7 +319,7 @@ impl Channels {
     ) -> Result<Dispatched> {
         trace!("chan dispatch");
         let mut disp = Dispatched(None);
-        let r = match packet {
+        match packet {
             Packet::ChannelOpen(p) => {
                 self.dispatch_open(&p, s, b)?;
             }
@@ -481,7 +481,7 @@ impl TryFrom<&packets::Pty<'_>> for Pty {
     type Error = Error;
     fn try_from(p: &packets::Pty) -> Result<Self, Self::Error> {
         warn!("TODO implement pty modes");
-        let term = p.term.as_ascii()?.try_into().map_err(|e| Error::BadString)?;
+        let term = p.term.as_ascii()?.try_into().map_err(|_| Error::BadString)?;
         Ok(Pty {
             term,
             cols: p.cols,
@@ -668,7 +668,7 @@ impl Channel {
     fn dispatch_server_request(
         &self,
         p: &packets::ChannelRequest,
-        s: &mut TrafSend,
+        _s: &mut TrafSend,
         b: &mut dyn ServBehaviour,
     ) -> Result<bool> {
         if !matches!(self.ty, ChanType::Session) {
@@ -749,88 +749,6 @@ pub(crate) struct DataIn {
     pub len: usize,
 }
 
-/// Application API
-#[derive(Debug)]
-pub enum ChanEvent<'a> {
-    // TODO: perhaps this one should go a level above since it isn't for existing channels?
-    OpenSuccess { num: u32 },
-
-    // TODO details
-    // OpenRequest { },
-    ReqPty { num: u32, want_reply: bool, pty: packets::Pty<'a> },
-
-    Req { num: u32, req: ChannelReqType<'a> },
-    // TODO closein/closeout/eof, etc. Should also return the exit status etc
-    Eof { num: u32 },
-
-    Close { num: u32 },
-    // TODO: responses to a previous ChanMsg?
-}
-
-/// An event returned from `Channel::dispatch()`.
-/// Most are propagated to the application, `DataIn is caught by `runner`
-#[derive(Debug)]
-pub(crate) enum ChanEventMaker {
-    /// Channel data is ready with `channel_input()`. This breaks the `Packet` abstraction
-    /// by returning the offset into the payload buffer, used by `traffic`.
-    DataIn(DataIn),
-
-    OpenSuccess {
-        num: u32,
-    },
-
-    // A ChannelRequest. Will be split into separate ChanEvent variants
-    // for each type.
-    Req,
-    // TODO closein/closeout/eof, etc. Should also return the exit status etc
-    Eof {
-        num: u32,
-    },
-
-    Close {
-        num: u32,
-    },
-    // TODO: responses to a previous ChanMsg?
-}
-
-impl ChanEventMaker {
-    // To be called on the same packet that created the ChanEventMaker.
-    pub fn make<'p>(&self, packet: Packet<'p>) -> Option<ChanEvent<'p>> {
-        match self {
-            // Datain is handled at the traffic level, not propagated as an Event
-            Self::DataIn(_) => {
-                debug!("DataIn should not be reached");
-                None
-            }
-            Self::OpenSuccess { num } => Some(ChanEvent::OpenSuccess { num: *num }),
-            Self::Req => {
-                if let Packet::ChannelRequest(ChannelRequest {
-                    num,
-                    want_reply,
-                    req,
-                }) = packet
-                {
-                    match req {
-                        ChannelReqType::Pty(pty) => {
-                            Some(ChanEvent::ReqPty { num, want_reply, pty })
-                        }
-                        _ => {
-                            warn!("Unhandled {:?}", self);
-                            None
-                        }
-                    }
-                } else {
-                    // TODO: return a bug result?
-                    warn!("Req event maker but not request packet");
-                    None
-                }
-            }
-            Self::Eof { num } => Some(ChanEvent::Eof { num: *num }),
-            Self::Close { num } => Some(ChanEvent::Close { num: *num }),
-        }
-    }
-}
-
 struct PendInput {
     chan: u32,
     len: usize,
diff --git a/sshproto/src/conn.rs b/sshproto/src/conn.rs
index fc1e941..b18de6a 100644
--- a/sshproto/src/conn.rs
+++ b/sshproto/src/conn.rs
@@ -18,7 +18,7 @@ use encrypt::KeyState;
 use packets::{Packet,ParseContext};
 use server::Server;
 use traffic::TrafSend;
-use channel::{Channels, ChanEvent, ChanEventMaker};
+use channel::Channels;
 use config::MAX_CHANNELS;
 use kex::{SessId, AlgoConfig};
 
@@ -84,18 +84,6 @@ enum ConnState {
     // Cleanup ??
 }
 
-// Application API
-#[derive(Debug)]
-pub enum Event<'a> {
-    Channel(ChanEvent<'a>),
-    CliAuthed,
-}
-
-pub(crate) enum EventMaker {
-    Channel(ChanEventMaker),
-    CliAuthed,
-}
-
 pub(crate) struct Dispatched(pub Option<channel::DataIn>);
 
 impl Conn {
@@ -135,7 +123,7 @@ impl Conn {
         match self.state {
             ConnState::SendIdent => {
                 s.send_version(ident::OUR_VERSION)?;
-                let p = self.kex.send_kexinit(&self.algo_conf, s)?;
+                self.kex.send_kexinit(&self.algo_conf, s)?;
                 // TODO: first_follows would have a second packet here
                 self.state = ConnState::ReceiveIdent
             }
@@ -250,7 +238,7 @@ impl Conn {
                     done_auth: matches!(self.state, ConnState::Authed),
                     output: None,
                 };
-                let r = self.kex.handle_kexinit(
+                self.kex.handle_kexinit(
                     &packet,
                     self.cliserv.is_client(),
                     &self.algo_conf,
@@ -280,7 +268,7 @@ impl Conn {
             Packet::KexDHReply(p) => {
                 match self.state {
                     ConnState::InKex { done_auth: _, ref mut output } => {
-                        if let ClientServer::Client(cli) = &mut self.cliserv {
+                        if let ClientServer::Client(_cli) = &mut self.cliserv {
                             if self.kex.maybe_discard_packet() {
                                 // ok
                             } else {
@@ -415,10 +403,5 @@ mod tests {
     use crate::doorlog::*;
     use crate::conn::*;
     use crate::error::Error;
-
-    // #[test]
-    // fn event_variants() {
-    //     // TODO sanity check event variants.
-    // }
 }
 
diff --git a/sshproto/src/lib.rs b/sshproto/src/lib.rs
index b77e37a..a85260d 100644
--- a/sshproto/src/lib.rs
+++ b/sshproto/src/lib.rs
@@ -46,12 +46,11 @@ pub mod config;
 // Application API
 pub use behaviour::{Behaviour, ServBehaviour, CliBehaviour,
     BhError, BhResult, ResponseString};
-pub use sshwire::{TextString};
+pub use sshwire::TextString;
 
 pub use runner::Runner;
 pub use sign::SignKey;
 pub use packets::PubKey;
 pub use error::{Error,Result};
-pub use channel::{ChanMsg, ChanMsgDetails, ChanEvent, Pty, ChanOpened};
-pub use sshnames::{ChanFail};
-pub use conn::Event;
+pub use channel::{ChanMsg, ChanMsgDetails, Pty, ChanOpened};
+pub use sshnames::ChanFail;
diff --git a/sshproto/src/runner.rs b/sshproto/src/runner.rs
index 12a6df0..e95920d 100644
--- a/sshproto/src/runner.rs
+++ b/sshproto/src/runner.rs
@@ -8,12 +8,11 @@ use core::task::{Poll, Waker};
 
 use pretty_hex::PrettyHex;
 
-use crate::{*, channel::ChanEvent};
+use crate::*;
 use encrypt::KeyState;
 use traffic::{TrafIn, TrafOut, TrafSend};
 
 use conn::{Conn, Dispatched};
-use channel::ChanEventMaker;
 
 pub struct Runner<'a> {
     conn: Conn,
@@ -249,7 +248,7 @@ impl<'a> Runner<'a> {
         self.conn.channels.send_allowed(chan).map(|s| s.min(buf_space))
     }
 
-    pub fn term_window_change(&self, chan: u32, wc: packets::WinChange) -> Result<()> {
+    pub fn term_window_change(&self, _chan: u32, _wc: packets::WinChange) -> Result<()> {
         todo!();
         // self.conn.channels.term_window_change(chan, wc)
     }
diff --git a/sshproto/src/servauth.rs b/sshproto/src/servauth.rs
index b7b2f70..32ad66d 100644
--- a/sshproto/src/servauth.rs
+++ b/sshproto/src/servauth.rs
@@ -16,7 +16,7 @@ pub(crate) struct ServAuth {
 }
 
 impl ServAuth {
-    pub fn new(b: &mut dyn ServBehaviour) -> Self {
+    pub fn new(_b: &mut dyn ServBehaviour) -> Self {
         Self { authed: false }
     }
 
diff --git a/sshproto/src/sshnames.rs b/sshproto/src/sshnames.rs
index 5a73a73..97b179b 100644
--- a/sshproto/src/sshnames.rs
+++ b/sshproto/src/sshnames.rs
@@ -50,7 +50,6 @@ pub const SSH_AUTHMETHOD_PASSWORD: &str = "password";
 pub const SSH_AUTHMETHOD_PUBLICKEY: &str = "publickey";
 /// [RFC4256](https://tools.ietf.org/html/rfc4256)
 pub const SSH_AUTHMETHOD_INTERACTIVE: &str = "keyboard-interactive";
-pub(crate) const NUM_AUTHMETHOD: usize = 3;
 
 /// [RFC4254](https://tools.ietf.org/html/rfc4254)
 pub const SSH_EXTENDED_DATA_STDERR: u32 = 1;
diff --git a/sshproto/src/sshwire.rs b/sshproto/src/sshwire.rs
index 0cf26ba..35c96d6 100644
--- a/sshproto/src/sshwire.rs
+++ b/sshproto/src/sshwire.rs
@@ -159,7 +159,7 @@ where
 {
     let mut s = EncodeLen { pos: 0 };
     value.enc(&mut s)?;
-    s.pos.try_into().map_err(|e| WireError::NoRoom)
+    s.pos.try_into().map_err(|_| WireError::NoRoom)
 }
 
 struct EncodeBytes<'a> {
diff --git a/sshproto/src/traffic.rs b/sshproto/src/traffic.rs
index a648911..e412876 100644
--- a/sshproto/src/traffic.rs
+++ b/sshproto/src/traffic.rs
@@ -288,10 +288,6 @@ impl<'a> TrafOut<'a> {
         let (idx, len) = match self.state {
             TxState::Idle => (0, 0),
             TxState::Write { idx, len } => (idx, len),
-            _ => {
-                trace!("bad state {:?}", self.state);
-                Err(Error::bug())?
-            }
         };
 
         // Use the remainder of our buffer to write the packet. Payload starts
-- 
GitLab