Skip to content

Commit

Permalink
Fix clippy warnings (lifetimes elision)
Browse files Browse the repository at this point in the history
  • Loading branch information
chifflier committed Mar 13, 2024
1 parent a105ac1 commit 83ca552
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/mpint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn parse_ssh_mpint(i: &[u8]) -> IResult<&[u8], BigInt> {
} else {
let (i, b) = bits(pair(
btake::<_, _, _, Error<_>>(1usize),
btake((i.len() * 8usize - 1) as usize),
btake(i.len() * 8usize - 1),
))(i)?;
let sign: u8 = b.0;
let number = MpUint(b.1);
Expand Down
29 changes: 13 additions & 16 deletions src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ use cookie_factory::gen::{set_be_u32, set_be_u8};
use cookie_factory::*;
use std::iter::repeat;

fn gen_string<'a, 'b>(
x: (&'a mut [u8], usize),
s: &'b [u8],
) -> Result<(&'a mut [u8], usize), GenError> {
fn gen_string<'a>(x: (&'a mut [u8], usize), s: &[u8]) -> Result<(&'a mut [u8], usize), GenError> {
do_gen!(x, gen_be_u32!(s.len() as u32) >> gen_slice!(s))
}

fn gen_packet_key_exchange<'a, 'b>(
fn gen_packet_key_exchange<'a>(
x: (&'a mut [u8], usize),
p: &'b SshPacketKeyExchange,
p: &SshPacketKeyExchange,
) -> Result<(&'a mut [u8], usize), GenError> {
do_gen!(
x,
Expand All @@ -34,29 +31,29 @@ fn gen_packet_key_exchange<'a, 'b>(
)
}

fn gen_packet_dh_reply<'a, 'b>(
fn gen_packet_dh_reply<'a>(
x: (&'a mut [u8], usize),
p: &'b SshPacketDhReply,
p: &SshPacketDhReply,
) -> Result<(&'a mut [u8], usize), GenError> {
do_gen!(
x,
gen_string(p.pubkey_and_cert) >> gen_string(p.f) >> gen_string(p.signature)
)
}

fn gen_packet_disconnect<'a, 'b>(
fn gen_packet_disconnect<'a>(
x: (&'a mut [u8], usize),
p: &'b SshPacketDisconnect,
p: &SshPacketDisconnect,
) -> Result<(&'a mut [u8], usize), GenError> {
do_gen!(
x,
gen_be_u32!(p.reason_code) >> gen_string(p.description) >> gen_string(p.lang)
)
}

fn gen_packet_debug<'a, 'b>(
fn gen_packet_debug<'a>(
x: (&'a mut [u8], usize),
p: &'b SshPacketDebug,
p: &SshPacketDebug,
) -> Result<(&'a mut [u8], usize), GenError> {
do_gen!(
x,
Expand All @@ -81,9 +78,9 @@ fn packet_payload_type(p: &SshPacket) -> u8 {
}
}

fn gen_packet_payload<'a, 'b>(
fn gen_packet_payload<'a>(
x: (&'a mut [u8], usize),
p: &'b SshPacket,
p: &SshPacket,
) -> Result<(&'a mut [u8], usize), GenError> {
match *p {
SshPacket::Disconnect(ref p) => gen_packet_disconnect(x, p),
Expand All @@ -110,9 +107,9 @@ fn padding_len(payload: usize) -> usize {
}

/// Serialize an SSH packet from its intermediate representation.
pub fn gen_ssh_packet<'a, 'b>(
pub fn gen_ssh_packet<'a>(
x: (&'a mut [u8], usize),
p: &'b SshPacket,
p: &SshPacket,
) -> Result<(&'a mut [u8], usize), GenError> {
do_gen!(
x,
Expand Down
2 changes: 1 addition & 1 deletion src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn parse_name(s: &[u8]) -> IResult<&[u8], &[u8]> {
take_while1(is_us_ascii)(s)
}

fn parse_name_list<'a>(i: &'a [u8]) -> IResult<&'a [u8], Vec<&str>> {
fn parse_name_list(i: &[u8]) -> IResult<&[u8], Vec<&str>> {
use nom::bytes::complete::tag;
match separated_list1(tag(","), map_res(complete(parse_name), str::from_utf8))(i) {
Ok((rem, res)) => Ok((rem, res)),
Expand Down
12 changes: 6 additions & 6 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use nom::Err;

use super::ssh::*;

static CLIENT_KEY_EXCHANGE: &'static [u8] = include_bytes!("../assets/client_init.raw");
static CLIENT_DH_INIT: &'static [u8] = include_bytes!("../assets/dh_init.raw");
static SERVER_DH_REPLY: &'static [u8] = include_bytes!("../assets/dh_reply.raw");
static SERVER_NEW_KEYS: &'static [u8] = include_bytes!("../assets/new_keys.raw");
static SERVER_COMPAT: &'static [u8] = include_bytes!("../assets/server_compat.raw");
static CLIENT_KEY_EXCHANGE: &[u8] = include_bytes!("../assets/client_init.raw");
static CLIENT_DH_INIT: &[u8] = include_bytes!("../assets/dh_init.raw");
static SERVER_DH_REPLY: &[u8] = include_bytes!("../assets/dh_reply.raw");
static SERVER_NEW_KEYS: &[u8] = include_bytes!("../assets/new_keys.raw");
static SERVER_COMPAT: &[u8] = include_bytes!("../assets/server_compat.raw");

#[test]
fn test_identification() {
Expand Down Expand Up @@ -137,7 +137,7 @@ fn test_new_keys() {
let keys = SshPacket::NewKeys;
let padding: &[u8] = &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
let expected = Ok((b"" as &[u8], (keys, padding)));
let res = parse_ssh_packet(&SERVER_NEW_KEYS);
let res = parse_ssh_packet(SERVER_NEW_KEYS);
assert_eq!(res, expected);
}

Expand Down

0 comments on commit 83ca552

Please sign in to comment.