From: Jason Ish Date: Wed, 5 Oct 2022 14:58:55 +0000 (-0600) Subject: rust: fix clippy lints for clippy::redundant_field_names X-Git-Tag: suricata-7.0.0-beta1~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=565da0d0af7011dd31318c25b1420c10a053d3e3;p=thirdparty%2Fsuricata.git rust: fix clippy lints for clippy::redundant_field_names --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 9eb4518eac..2d22e7a49a 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -250,8 +250,8 @@ impl AppLayerResult { pub fn incomplete(consumed: u32, needed: u32) -> Self { return Self { status: 1, - consumed: consumed, - needed: needed, + consumed, + needed, }; } @@ -479,7 +479,7 @@ pub struct AppLayerGetTxIterTuple { impl AppLayerGetTxIterTuple { pub fn with_values(tx_ptr: *mut std::os::raw::c_void, tx_id: u64, has_next: bool) -> AppLayerGetTxIterTuple { AppLayerGetTxIterTuple { - tx_ptr: tx_ptr, tx_id: tx_id, has_next: has_next, + tx_ptr, tx_id, has_next, } } pub fn not_found() -> AppLayerGetTxIterTuple { diff --git a/rust/src/dcerpc/detect.rs b/rust/src/dcerpc/detect.rs index 5d616a6642..ab9c637ab8 100644 --- a/rust/src/dcerpc/detect.rs +++ b/rust/src/dcerpc/detect.rs @@ -145,9 +145,9 @@ fn parse_iface_data(arg: &str) -> Result { } Ok(DCEIfaceData { - if_uuid: if_uuid, - du16: du16, - any_frag: any_frag, + if_uuid, + du16, + any_frag, }) } diff --git a/rust/src/detect/byte_math.rs b/rust/src/detect/byte_math.rs index beb40ec864..2d7c67aeed 100644 --- a/rust/src/detect/byte_math.rs +++ b/rust/src/detect/byte_math.rs @@ -466,20 +466,20 @@ mod tests { result: &str, base: ByteMathBase, endian: ByteMathEndian, bitmask_val: u32, flags: u8, ) { let bmd = DetectByteMathData { - nbytes: nbytes, - offset: offset, - oper: oper, + nbytes, + offset, + oper, rvalue_str: if !rvalue_str.is_empty() { CString::new(rvalue_str).unwrap().into_raw() } else { std::ptr::null_mut() }, - rvalue: rvalue, + rvalue, result: CString::new(result).unwrap().into_raw(), - base: base, - endian: endian, - bitmask_val: bitmask_val, - flags: flags, + base, + endian, + bitmask_val, + flags, ..Default::default() }; diff --git a/rust/src/detect/iprep.rs b/rust/src/detect/iprep.rs index feefb8ab1e..4018ea97a4 100644 --- a/rust/src/detect/iprep.rs +++ b/rust/src/detect/iprep.rs @@ -99,9 +99,9 @@ pub fn detect_parse_iprep(i: &str) -> IResult<&str, DetectIPRepData> { let (i, arg1) = map_opt(digit1, |s: &str| s.parse::().ok())(i)?; let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?; let du8 = DetectUintData:: { - arg1: arg1, + arg1, arg2: 0, - mode: mode, + mode, }; return Ok((i, DetectIPRepData { du8, cat, cmd })); } diff --git a/rust/src/detect/stream_size.rs b/rust/src/detect/stream_size.rs index 394cd781a1..cb8c826697 100644 --- a/rust/src/detect/stream_size.rs +++ b/rust/src/detect/stream_size.rs @@ -70,9 +70,9 @@ pub fn detect_parse_stream_size(i: &str) -> IResult<&str, DetectStreamSizeData> let (i, arg1) = map_opt(digit1, |s: &str| s.parse::().ok())(i)?; let (i, _) = all_consuming(take_while(|c| c == ' '))(i)?; let du32 = DetectUintData:: { - arg1: arg1, + arg1, arg2: 0, - mode: mode, + mode, }; Ok((i, DetectStreamSizeData { flags, du32 })) } diff --git a/rust/src/detect/uint.rs b/rust/src/detect/uint.rs index 4d99047572..6cf31b2dbc 100644 --- a/rust/src/detect/uint.rs +++ b/rust/src/detect/uint.rs @@ -162,7 +162,7 @@ fn detect_parse_uint_start_symbol(i: &str) -> IResult<&str, De DetectUintData { arg1, arg2: T::min_value(), - mode: mode, + mode, }, )) } diff --git a/rust/src/dhcp/dhcp.rs b/rust/src/dhcp/dhcp.rs index 626c368809..407a5c47ad 100644 --- a/rust/src/dhcp/dhcp.rs +++ b/rust/src/dhcp/dhcp.rs @@ -85,7 +85,7 @@ impl DHCPTransaction { pub fn new(id: u64, message: DHCPMessage) -> DHCPTransaction { DHCPTransaction { tx_id: id, - message: message, + message, tx_data: applayer::AppLayerTxData::new(), } } diff --git a/rust/src/dhcp/parser.rs b/rust/src/dhcp/parser.rs index cb7d2f8c61..9f6397fd44 100644 --- a/rust/src/dhcp/parser.rs +++ b/rust/src/dhcp/parser.rs @@ -102,13 +102,13 @@ pub fn parse_header(i: &[u8]) -> IResult<&[u8], DHCPHeader> { Ok(( i, DHCPHeader { - opcode: opcode, - htype: htype, - hlen: hlen, - hops: hops, - txid: txid, - seconds: seconds, - flags: flags, + opcode, + htype, + hlen, + hops, + txid, + seconds, + flags, clientip: clientip.to_vec(), yourip: yourip.to_vec(), serverip: serverip.to_vec(), @@ -129,7 +129,7 @@ pub fn parse_clientid_option(i: &[u8]) -> IResult<&[u8], DHCPOption> { Ok(( i, DHCPOption { - code: code, + code, data: None, option: DHCPOptionWrapper::ClientId(DHCPOptClientId { htype: 1, @@ -146,9 +146,9 @@ pub fn parse_address_time_option(i: &[u8]) -> IResult<&[u8], DHCPOption> { Ok(( i, DHCPOption { - code: code, + code, data: None, - option: DHCPOptionWrapper::TimeValue(DHCPOptTimeValue { seconds: seconds }), + option: DHCPOptionWrapper::TimeValue(DHCPOptTimeValue { seconds }), }, )) } @@ -160,7 +160,7 @@ pub fn parse_generic_option(i: &[u8]) -> IResult<&[u8], DHCPOption> { Ok(( i, DHCPOption { - code: code, + code, data: None, option: DHCPOptionWrapper::Generic(DHCPOptGeneric { data: data.to_vec(), @@ -226,10 +226,10 @@ pub fn dhcp_parse(input: &[u8]) -> IResult<&[u8], DHCPMessage> { } } let message = DHCPMessage { - header: header, - options: options, - malformed_options: malformed_options, - truncated_options: truncated_options, + header, + options, + malformed_options, + truncated_options, }; return Ok((next, message)); } diff --git a/rust/src/http2/detect.rs b/rust/src/http2/detect.rs index 2cdb60449f..58f62d1c65 100644 --- a/rust/src/http2/detect.rs +++ b/rust/src/http2/detect.rs @@ -875,7 +875,7 @@ fn http2_tx_set_header(state: &mut HTTP2State, name: &[u8], input: &[u8]) { let hs = parser::HTTP2FrameHeaders { padlength: None, priority: None, - blocks: blocks, + blocks, }; let txdata = HTTP2FrameTypeData::HEADERS(hs); let tx = state.find_or_create_tx(&head, &txdata, Direction::ToServer); @@ -1038,7 +1038,7 @@ mod tests { let hs = parser::HTTP2FrameHeaders { padlength: None, priority: None, - blocks: blocks, + blocks, }; let txdata = HTTP2FrameTypeData::HEADERS(hs); tx.frames_ts.push(HTTP2Frame { diff --git a/rust/src/jsonbuilder.rs b/rust/src/jsonbuilder.rs index 8fde424dd8..e3d47dad92 100644 --- a/rust/src/jsonbuilder.rs +++ b/rust/src/jsonbuilder.rs @@ -106,7 +106,7 @@ impl JsonBuilder { let mut buf = String::with_capacity(capacity); buf.push('{'); Self { - buf: buf, + buf, state: vec![State::None, State::ObjectFirst], init_type: Type::Object, } @@ -121,7 +121,7 @@ impl JsonBuilder { let mut buf = String::with_capacity(capacity); buf.push('['); Self { - buf: buf, + buf, state: vec![State::None, State::ArrayFirst], init_type: Type::Array, } diff --git a/rust/src/krb/krb5.rs b/rust/src/krb/krb5.rs index 0399733c06..3370502b23 100644 --- a/rust/src/krb/krb5.rs +++ b/rust/src/krb/krb5.rs @@ -242,7 +242,7 @@ impl KRB5Transaction { etype: None, ticket_etype: None, error_code: None, - id: id, + id, tx_data: applayer::AppLayerTxData::new(), } } diff --git a/rust/src/ntp/ntp.rs b/rust/src/ntp/ntp.rs index 5b3601a2b3..63cb0bb751 100644 --- a/rust/src/ntp/ntp.rs +++ b/rust/src/ntp/ntp.rs @@ -155,7 +155,7 @@ impl NTPTransaction { pub fn new(id: u64) -> NTPTransaction { NTPTransaction { xid: 0, - id: id, + id, tx_data: applayer::AppLayerTxData::new(), } } diff --git a/rust/src/quic/crypto.rs b/rust/src/quic/crypto.rs index 22821728fc..c86b9958c3 100644 --- a/rust/src/quic/crypto.rs +++ b/rust/src/quic/crypto.rs @@ -77,7 +77,7 @@ impl PacketKey { let key = Aes128Gcm::new(GenericArray::from_slice(&secret)); let mut r = PacketKey { - key: key, + key, iv: [0u8; AES128_IV_LEN], }; hkdf_expand_label(&hk, b"quic iv", &mut r.iv, AES128_IV_LEN as u16); diff --git a/rust/src/quic/parser.rs b/rust/src/quic/parser.rs index aafc51b367..69d93a7dda 100644 --- a/rust/src/quic/parser.rs +++ b/rust/src/quic/parser.rs @@ -237,8 +237,8 @@ impl QuicHeader { rest, QuicHeader { flags, - ty: ty, - version: version, + ty, + version, version_buf: version_buf.to_vec(), dcid: dcid.to_vec(), scid: Vec::new(), diff --git a/rust/src/quic/quic.rs b/rust/src/quic/quic.rs index 2dfe2e608f..846b493199 100644 --- a/rust/src/quic/quic.rs +++ b/rust/src/quic/quic.rs @@ -73,13 +73,13 @@ impl QuicTransaction { fn new_empty(client: bool, header: QuicHeader) -> Self { QuicTransaction { tx_id: 0, - header: header, + header, cyu: Vec::new(), sni: None, ua: None, extv: Vec::new(), ja3: None, - client: client, + client, tx_data: AppLayerTxData::new(), } } diff --git a/rust/src/smb/auth.rs b/rust/src/smb/auth.rs index c6289e7af8..d92a0c9f44 100644 --- a/rust/src/smb/auth.rs +++ b/rust/src/smb/auth.rs @@ -143,7 +143,7 @@ fn parse_secblob_spnego(blob: &[u8]) -> Option let s = SpnegoRequest { krb: kticket, - ntlmssp: ntlmssp, + ntlmssp, }; Some(s) } @@ -181,9 +181,9 @@ fn parse_ntlmssp_blob(blob: &[u8]) -> Option domain.retain(|&i|i != 0x00); let d = NtlmsspData { - host: host, - user: user, - domain: domain, + host, + user, + domain, version: ad.version, }; ntlmssp_data = Some(d); diff --git a/rust/src/smb/dcerpc.rs b/rust/src/smb/dcerpc.rs index 2be850c528..26de2f9402 100644 --- a/rust/src/smb/dcerpc.rs +++ b/rust/src/smb/dcerpc.rs @@ -76,9 +76,9 @@ pub struct DCERPCIface { impl DCERPCIface { pub fn new(uuid: Vec, ver: u16, ver_min: u16) -> Self { Self { - uuid: uuid, - ver:ver, - ver_min:ver_min, + uuid, + ver, + ver_min, ..Default::default() } } @@ -106,15 +106,15 @@ impl SMBTransactionDCERPC { context_id: 0, req_cmd: req, req_set: true, - call_id: call_id, + call_id, ..Default::default() } } fn new_response(call_id: u32) -> Self { - return Self { - call_id: call_id, + return Self { + call_id, ..Default::default() - } + }; } pub fn set_result(&mut self, res: u8) { self.res_set = true; diff --git a/rust/src/smb/smb.rs b/rust/src/smb/smb.rs index 42af767ce7..4ab807c46d 100644 --- a/rust/src/smb/smb.rs +++ b/rust/src/smb/smb.rs @@ -169,7 +169,7 @@ impl SMBVerCmdStat { smb_ver: 1, smb1_cmd: cmd, status_set: true, - status: status, + status, ..Default::default() } } @@ -186,7 +186,7 @@ impl SMBVerCmdStat { smb_ver: 2, smb2_cmd: cmd, status_set: true, - status: status, + status, ..Default::default() } } @@ -312,11 +312,11 @@ impl SMBTransactionSetFilePathInfo { -> Self { return Self { - filename: filename, fid: fid, - subcmd: subcmd, - loi: loi, - delete_on_close: delete_on_close, - } + filename, fid, + subcmd, + loi, + delete_on_close, + }; } } @@ -369,8 +369,8 @@ pub struct SMBTransactionRename { impl SMBTransactionRename { pub fn new(fuid: Vec, oldname: Vec, newname: Vec) -> Self { return Self { - fuid: fuid, oldname: oldname, newname: newname, - } + fuid, oldname, newname, + }; } } @@ -414,7 +414,7 @@ impl SMBTransactionCreate { disposition: disp, delete_on_close: del, directory: dir, - filename: filename, + filename, ..Default::default() } } @@ -434,10 +434,10 @@ pub struct SMBTransactionNegotiate { impl SMBTransactionNegotiate { pub fn new(smb_ver: u8) -> Self { return Self { - smb_ver: smb_ver, + smb_ver, server_guid: Vec::with_capacity(16), ..Default::default() - } + }; } } @@ -456,9 +456,9 @@ pub struct SMBTransactionTreeConnect { impl SMBTransactionTreeConnect { pub fn new(share_name: Vec) -> Self { return Self { - share_name:share_name, + share_name, ..Default::default() - } + }; } } @@ -532,8 +532,8 @@ pub struct SMBFileGUIDOffset { impl SMBFileGUIDOffset { pub fn new(guid: Vec, offset: u64) -> Self { Self { - guid:guid, - offset:offset, + guid, + offset, } } } @@ -565,10 +565,10 @@ impl SMBCommonHdr { } pub fn new(rec_type: u32, ssn_id: u64, tree_id: u32, msg_id: u64) -> Self { Self { - rec_type : rec_type, - ssn_id : ssn_id, - tree_id : tree_id, - msg_id : msg_id, + rec_type, + ssn_id, + tree_id, + msg_id, } } pub fn from2(r: &Smb2Record, rec_type: u32) -> SMBCommonHdr { @@ -582,10 +582,10 @@ impl SMBCommonHdr { }; SMBCommonHdr { - rec_type : rec_type, + rec_type, ssn_id : r.session_id, - tree_id : tree_id, - msg_id : msg_id, + tree_id, + msg_id, } } @@ -601,10 +601,10 @@ impl SMBCommonHdr { }; SMBCommonHdr { - rec_type : rec_type, + rec_type, ssn_id : r.session_id, tree_id : 0, - msg_id : msg_id, + msg_id, } } pub fn from1(r: &SmbRecord, rec_type: u32) -> SMBCommonHdr { @@ -618,10 +618,10 @@ impl SMBCommonHdr { }; SMBCommonHdr { - rec_type : rec_type, + rec_type, ssn_id : r.ssn_id as u64, - tree_id : tree_id, - msg_id : msg_id, + tree_id, + msg_id, } } @@ -641,7 +641,7 @@ pub struct SMBHashKeyHdrGuid { impl SMBHashKeyHdrGuid { pub fn new(hdr: SMBCommonHdr, guid: Vec) -> Self { Self { - hdr: hdr, guid: guid, + hdr, guid, } } } @@ -655,8 +655,8 @@ pub struct SMBTree { impl SMBTree { pub fn new(name: Vec, is_pipe: bool) -> Self { Self { - name:name, - is_pipe:is_pipe, + name, + is_pipe, } } } diff --git a/rust/src/smb/smb1_session.rs b/rust/src/smb/smb1_session.rs index ad3f330fda..30c1637a48 100644 --- a/rust/src/smb/smb1_session.rs +++ b/rust/src/smb/smb1_session.rs @@ -56,9 +56,9 @@ pub fn smb1_session_setup_request_host_info(r: &SmbRecord, blob: &[u8]) -> Sessi SCLogDebug!("name1 {:?} name2 {:?} name3 {:?}", native_os,native_lm,primary_domain); SessionSetupRequest { - native_os:native_os, - native_lm:native_lm, - primary_domain:primary_domain, + native_os, + native_lm, + primary_domain, } } else { let (native_os, native_lm, primary_domain) = match smb_get_ascii_string(blob) { @@ -78,9 +78,9 @@ pub fn smb1_session_setup_request_host_info(r: &SmbRecord, blob: &[u8]) -> Sessi SCLogDebug!("session_setup_request_host_info: not unicode"); SessionSetupRequest { - native_os: native_os, - native_lm: native_lm, - primary_domain: primary_domain, + native_os, + native_lm, + primary_domain, } } } @@ -102,8 +102,8 @@ pub fn smb1_session_setup_response_host_info(r: &SmbRecord, blob: &[u8]) -> Sess SCLogDebug!("name1 {:?} name2 {:?}", native_os,native_lm); SessionSetupResponse { - native_os:native_os, - native_lm:native_lm, + native_os, + native_lm, } } else { SCLogDebug!("session_setup_response_host_info: not unicode"); @@ -117,8 +117,8 @@ pub fn smb1_session_setup_response_host_info(r: &SmbRecord, blob: &[u8]) -> Sess _ => { (Vec::new(), Vec::new()) }, }; SessionSetupResponse { - native_os: native_os, - native_lm: native_lm, + native_os, + native_lm, } } } diff --git a/rust/src/smb/smb2_ioctl.rs b/rust/src/smb/smb2_ioctl.rs index 0a5eb8d135..997ed4ef01 100644 --- a/rust/src/smb/smb2_ioctl.rs +++ b/rust/src/smb/smb2_ioctl.rs @@ -32,8 +32,8 @@ pub struct SMBTransactionIoctl { impl SMBTransactionIoctl { pub fn new(func: u32) -> Self { return Self { - func: func, - } + func, + }; } } diff --git a/rust/src/snmp/snmp.rs b/rust/src/snmp/snmp.rs index f2f2e59b74..2344acedaf 100644 --- a/rust/src/snmp/snmp.rs +++ b/rust/src/snmp/snmp.rs @@ -245,7 +245,7 @@ impl<'a> SNMPTransaction<'a> { community: None, usm: None, encrypted: false, - id: id, + id, tx_data: applayer::AppLayerTxData::new(), } }