From 287176e870e664f0461a8439cb33e3da68a0bfe3 Mon Sep 17 00:00:00 2001 From: Pierre Chifflier Date: Wed, 13 Mar 2024 11:42:27 +0100 Subject: [PATCH] Use a functional-style `snd` function to simplify code --- src/ssh.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ssh.rs b/src/ssh.rs index 35e6b7f..3eae177 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -85,6 +85,11 @@ fn parse_name_list(i: &[u8]) -> IResult<&[u8], Vec<&str>> { } } +/// Return the second component of a pair. +fn snd(tuple: (A, B)) -> B { + tuple.1 +} + /// SSH Algorithm Negotiation /// /// Defined in [RFC4253 section 7.1](https://tools.ietf.org/html/rfc4253#section-7.1). @@ -144,43 +149,43 @@ fn parse_packet_key_exchange(i: &[u8]) -> IResult<&[u8], SshPacket> { impl<'a> SshPacketKeyExchange<'a> { pub fn get_kex_algs(&self) -> Result, nom::Err>> { - parse_name_list(self.kex_algs).map(|x| x.1) + parse_name_list(self.kex_algs).map(snd) } pub fn get_server_host_key_algs(&self) -> Result, nom::Err>> { - parse_name_list(self.server_host_key_algs).map(|x| x.1) + parse_name_list(self.server_host_key_algs).map(snd) } pub fn get_encr_algs_client_to_server(&self) -> Result, nom::Err>> { - parse_name_list(self.encr_algs_client_to_server).map(|x| x.1) + parse_name_list(self.encr_algs_client_to_server).map(snd) } pub fn get_encr_algs_server_to_client(&self) -> Result, nom::Err>> { - parse_name_list(self.encr_algs_server_to_client).map(|x| x.1) + parse_name_list(self.encr_algs_server_to_client).map(snd) } pub fn get_mac_algs_client_to_server(&self) -> Result, nom::Err>> { - parse_name_list(self.mac_algs_client_to_server).map(|x| x.1) + parse_name_list(self.mac_algs_client_to_server).map(snd) } pub fn get_mac_algs_server_to_client(&self) -> Result, nom::Err>> { - parse_name_list(self.mac_algs_server_to_client).map(|x| x.1) + parse_name_list(self.mac_algs_server_to_client).map(snd) } pub fn get_comp_algs_client_to_server(&self) -> Result, nom::Err>> { - parse_name_list(self.comp_algs_client_to_server).map(|x| x.1) + parse_name_list(self.comp_algs_client_to_server).map(snd) } pub fn get_comp_algs_server_to_client(&self) -> Result, nom::Err>> { - parse_name_list(self.comp_algs_server_to_client).map(|x| x.1) + parse_name_list(self.comp_algs_server_to_client).map(snd) } pub fn get_langs_client_to_server(&self) -> Result, nom::Err>> { - parse_name_list(self.langs_client_to_server).map(|x| x.1) + parse_name_list(self.langs_client_to_server).map(snd) } pub fn get_langs_server_to_client(&self) -> Result, nom::Err>> { - parse_name_list(self.langs_server_to_client).map(|x| x.1) + parse_name_list(self.langs_server_to_client).map(snd) } }