rust: fix lint warning for clippy::enum's name

Ticket: #4597
pull/7996/head
Haleema Khan 4 years ago committed by Victor Julien
parent 5365fdccf7
commit 6c922e0b98

@ -27,11 +27,11 @@ pub const HTTP2_DECOMPRESSION_CHUNK_SIZE: usize = 0x1000; // 4096
#[repr(u8)] #[repr(u8)]
#[derive(Copy, Clone, PartialOrd, PartialEq, Debug)] #[derive(Copy, Clone, PartialOrd, PartialEq, Debug)]
pub enum HTTP2ContentEncoding { pub enum HTTP2ContentEncoding {
HTTP2ContentEncodingUnknown = 0, Unknown = 0,
HTTP2ContentEncodingGzip = 1, Gzip = 1,
HTTP2ContentEncodingBr = 2, Br = 2,
HTTP2ContentEncodingDeflate = 3, Deflate = 3,
HTTP2ContentEncodingUnrecognized = 4, Unrecognized = 4,
} }
//a cursor turning EOF into blocking errors //a cursor turning EOF into blocking errors
@ -160,28 +160,28 @@ fn http2_decompress<'a>(
impl HTTP2DecoderHalf { impl HTTP2DecoderHalf {
pub fn new() -> HTTP2DecoderHalf { pub fn new() -> HTTP2DecoderHalf {
HTTP2DecoderHalf { HTTP2DecoderHalf {
encoding: HTTP2ContentEncoding::HTTP2ContentEncodingUnknown, encoding: HTTP2ContentEncoding::Unknown,
decoder: HTTP2Decompresser::UNASSIGNED, decoder: HTTP2Decompresser::UNASSIGNED,
} }
} }
pub fn http2_encoding_fromvec(&mut self, input: &[u8]) { pub fn http2_encoding_fromvec(&mut self, input: &[u8]) {
//use first encoding... //use first encoding...
if self.encoding == HTTP2ContentEncoding::HTTP2ContentEncodingUnknown { if self.encoding == HTTP2ContentEncoding::Unknown {
if input == b"gzip" { if input == b"gzip" {
self.encoding = HTTP2ContentEncoding::HTTP2ContentEncodingGzip; self.encoding = HTTP2ContentEncoding::Gzip;
self.decoder = HTTP2Decompresser::GZIP(GzDecoder::new(HTTP2cursor::new())); self.decoder = HTTP2Decompresser::GZIP(GzDecoder::new(HTTP2cursor::new()));
} else if input == b"deflate" { } else if input == b"deflate" {
self.encoding = HTTP2ContentEncoding::HTTP2ContentEncodingDeflate; self.encoding = HTTP2ContentEncoding::Deflate;
self.decoder = HTTP2Decompresser::DEFLATE(DeflateDecoder::new(HTTP2cursor::new())); self.decoder = HTTP2Decompresser::DEFLATE(DeflateDecoder::new(HTTP2cursor::new()));
} else if input == b"br" { } else if input == b"br" {
self.encoding = HTTP2ContentEncoding::HTTP2ContentEncodingBr; self.encoding = HTTP2ContentEncoding::Br;
self.decoder = HTTP2Decompresser::BROTLI(brotli::Decompressor::new( self.decoder = HTTP2Decompresser::BROTLI(brotli::Decompressor::new(
HTTP2cursor::new(), HTTP2cursor::new(),
HTTP2_DECOMPRESSION_CHUNK_SIZE, HTTP2_DECOMPRESSION_CHUNK_SIZE,
)); ));
} else { } else {
self.encoding = HTTP2ContentEncoding::HTTP2ContentEncodingUnrecognized; self.encoding = HTTP2ContentEncoding::Unrecognized;
} }
} }
} }

@ -53,7 +53,6 @@
#![allow(clippy::match_ref_pats)] #![allow(clippy::match_ref_pats)]
#![allow(clippy::module_inception)] #![allow(clippy::module_inception)]
#![allow(clippy::needless_range_loop)] #![allow(clippy::needless_range_loop)]
#![allow(clippy::enum_variant_names)]
#![allow(clippy::if_same_then_else)] #![allow(clippy::if_same_then_else)]
#![allow(clippy::match_like_matches_macro)] #![allow(clippy::match_like_matches_macro)]
#![allow(clippy::extra_unused_lifetimes)] #![allow(clippy::extra_unused_lifetimes)]

@ -30,34 +30,34 @@ use std::fmt;
#[derive(PartialEq, Eq, Copy, Clone, Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum MessageCode { pub enum MessageCode {
SshMsgDisconnect, Disconnect,
SshMsgIgnore, Ignore,
SshMsgUnimplemented, Unimplemented,
SshMsgDebug, Debug,
SshMsgServiceRequest, ServiceRequest,
SshMsgServiceAccept, ServiceAccept,
SshMsgKexinit, Kexinit,
SshMsgNewKeys, NewKeys,
SshMsgKexdhInit, KexdhInit,
SshMsgKexdhReply, KexdhReply,
SshMsgUndefined(u8), Undefined(u8),
} }
impl MessageCode { impl MessageCode {
fn from_u8(value: u8) -> MessageCode { fn from_u8(value: u8) -> MessageCode {
match value { match value {
1 => MessageCode::SshMsgDisconnect, 1 => MessageCode::Disconnect,
2 => MessageCode::SshMsgIgnore, 2 => MessageCode::Ignore,
3 => MessageCode::SshMsgUnimplemented, 3 => MessageCode::Unimplemented,
4 => MessageCode::SshMsgDebug, 4 => MessageCode::Debug,
5 => MessageCode::SshMsgServiceRequest, 5 => MessageCode::ServiceRequest,
6 => MessageCode::SshMsgServiceAccept, 6 => MessageCode::ServiceAccept,
20 => MessageCode::SshMsgKexinit, 20 => MessageCode::Kexinit,
21 => MessageCode::SshMsgNewKeys, 21 => MessageCode::NewKeys,
30 => MessageCode::SshMsgKexdhInit, 30 => MessageCode::KexdhInit,
31 => MessageCode::SshMsgKexdhReply, 31 => MessageCode::KexdhReply,
_ => MessageCode::SshMsgUndefined(value), _ => MessageCode::Undefined(value),
} }
} }
} }

@ -66,7 +66,7 @@ impl SshHeader {
pub fn new() -> SshHeader { pub fn new() -> SshHeader {
SshHeader { SshHeader {
record_left: 0, record_left: 0,
record_left_msg: parser::MessageCode::SshMsgUndefined(0), record_left_msg: parser::MessageCode::Undefined(0),
flags: SSHConnectionState::SshStateInProgress, flags: SSHConnectionState::SshStateInProgress,
protover: Vec::new(), protover: Vec::new(),
@ -132,7 +132,7 @@ impl SSHState {
let start = hdr.record_left as usize; let start = hdr.record_left as usize;
match hdr.record_left_msg { match hdr.record_left_msg {
// parse reassembled tcp segments // parse reassembled tcp segments
parser::MessageCode::SshMsgKexinit if hassh_is_enabled() => { parser::MessageCode::Kexinit if hassh_is_enabled() => {
if let Ok((_rem, key_exchange)) = if let Ok((_rem, key_exchange)) =
parser::ssh_parse_key_exchange(&input[..start]) parser::ssh_parse_key_exchange(&input[..start])
{ {
@ -142,7 +142,7 @@ impl SSHState {
&resp, &resp,
); );
} }
hdr.record_left_msg = parser::MessageCode::SshMsgUndefined(0); hdr.record_left_msg = parser::MessageCode::Undefined(0);
} }
_ => {} _ => {}
} }
@ -156,14 +156,14 @@ impl SSHState {
Ok((rem, head)) => { Ok((rem, head)) => {
SCLogDebug!("SSH valid record {}", head); SCLogDebug!("SSH valid record {}", head);
match head.msg_code { match head.msg_code {
parser::MessageCode::SshMsgKexinit if hassh_is_enabled() => { parser::MessageCode::Kexinit if hassh_is_enabled() => {
//let endkex = SSH_RECORD_HEADER_LEN + head.pkt_len - 2; //let endkex = SSH_RECORD_HEADER_LEN + head.pkt_len - 2;
let endkex = input.len() - rem.len(); let endkex = input.len() - rem.len();
if let Ok((_, key_exchange)) = parser::ssh_parse_key_exchange(&input[SSH_RECORD_HEADER_LEN..endkex]) { if let Ok((_, key_exchange)) = parser::ssh_parse_key_exchange(&input[SSH_RECORD_HEADER_LEN..endkex]) {
key_exchange.generate_hassh(&mut hdr.hassh_string, &mut hdr.hassh, &resp); key_exchange.generate_hassh(&mut hdr.hassh_string, &mut hdr.hassh, &resp);
} }
} }
parser::MessageCode::SshMsgNewKeys => { parser::MessageCode::NewKeys => {
hdr.flags = SSHConnectionState::SshStateFinished; hdr.flags = SSHConnectionState::SshStateFinished;
if ohdr.flags >= SSHConnectionState::SshStateFinished { if ohdr.flags >= SSHConnectionState::SshStateFinished {
unsafe { unsafe {
@ -190,15 +190,15 @@ impl SSHState {
hdr.record_left = head.pkt_len - 2 - remlen; hdr.record_left = head.pkt_len - 2 - remlen;
//header with rem as incomplete data //header with rem as incomplete data
match head.msg_code { match head.msg_code {
parser::MessageCode::SshMsgNewKeys => { parser::MessageCode::NewKeys => {
hdr.flags = SSHConnectionState::SshStateFinished; hdr.flags = SSHConnectionState::SshStateFinished;
} }
parser::MessageCode::SshMsgKexinit if hassh_is_enabled() => { parser::MessageCode::Kexinit if hassh_is_enabled() => {
// check if buffer is bigger than maximum reassembled packet size // check if buffer is bigger than maximum reassembled packet size
hdr.record_left = head.pkt_len - 2; hdr.record_left = head.pkt_len - 2;
if hdr.record_left < SSH_MAX_REASSEMBLED_RECORD_LEN as u32 { if hdr.record_left < SSH_MAX_REASSEMBLED_RECORD_LEN as u32 {
// saving type of incomplete kex message // saving type of incomplete kex message
hdr.record_left_msg = parser::MessageCode::SshMsgKexinit; hdr.record_left_msg = parser::MessageCode::Kexinit;
return AppLayerResult::incomplete( return AppLayerResult::incomplete(
(il - rem.len()) as u32, (il - rem.len()) as u32,
(head.pkt_len - 2) as u32 (head.pkt_len - 2) as u32

Loading…
Cancel
Save