]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/clippy: fix lint: new_without_default
authorJason Ish <jason.ish@oisf.net>
Mon, 28 Nov 2022 23:20:40 +0000 (17:20 -0600)
committerVictor Julien <vjulien@oisf.net>
Tue, 6 Dec 2022 13:10:11 +0000 (14:10 +0100)
20 files changed:
rust/src/applayertemplate/template.rs
rust/src/bittorrent_dht/bittorrent_dht.rs
rust/src/dcerpc/detect.rs
rust/src/dns/dns.rs
rust/src/http2/http2.rs
rust/src/ike/ike.rs
rust/src/krb/detect.rs
rust/src/krb/krb5.rs
rust/src/lib.rs
rust/src/modbus/modbus.rs
rust/src/mqtt/mqtt.rs
rust/src/nfs/nfs.rs
rust/src/ntp/ntp.rs
rust/src/pgsql/pgsql.rs
rust/src/rfb/rfb.rs
rust/src/sip/sip.rs
rust/src/smb/smb.rs
rust/src/snmp/snmp.rs
rust/src/ssh/ssh.rs
rust/src/telnet/telnet.rs

index a69475a5fb06662a63c5fee546e98b76b39b52b7..14ea6ff7ab90f66193ded0103c233540dc03ed3b 100644 (file)
@@ -37,9 +37,15 @@ pub struct TemplateTransaction {
     tx_data: AppLayerTxData,
 }
 
+impl Default for TemplateTransaction {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl TemplateTransaction {
     pub fn new() -> TemplateTransaction {
-        TemplateTransaction {
+        Self {
             tx_id: 0,
             request: None,
             response: None,
@@ -54,6 +60,7 @@ impl Transaction for TemplateTransaction {
     }
 }
 
+#[derive(Default)]
 pub struct TemplateState {
     state_data: AppLayerStateData,
     tx_id: u64,
@@ -74,13 +81,7 @@ impl State<TemplateTransaction> for TemplateState {
 
 impl TemplateState {
     pub fn new() -> Self {
-        Self {
-            state_data: AppLayerStateData::new(),
-            tx_id: 0,
-            transactions: VecDeque::new(),
-            request_gap: false,
-            response_gap: false,
-        }
+        Default::default()
     }
 
     // Free a transaction by ID.
index c06bfb0dcee8018e596f6bc4d98be3bd0ab58c6a..10b2498388d3ae574aacae0038e1b2c3bc81b646 100644 (file)
@@ -32,6 +32,7 @@ pub enum BitTorrentDHTEvent {
     MalformedPacket,
 }
 
+#[derive(Default)]
 pub struct BitTorrentDHTTransaction {
     tx_id: u64,
     pub request_type: Option<String>,
@@ -45,17 +46,8 @@ pub struct BitTorrentDHTTransaction {
 }
 
 impl BitTorrentDHTTransaction {
-    pub fn new() -> BitTorrentDHTTransaction {
-        BitTorrentDHTTransaction {
-            tx_id: 0,
-            request_type: None,
-            request: None,
-            response: None,
-            error: None,
-            transaction_id: Vec::new(),
-            client_version: None,
-            tx_data: AppLayerTxData::new(),
-        }
+    pub fn new() -> Self {
+        Self::default()
     }
 
     /// Set an event on the transaction
@@ -86,7 +78,7 @@ impl BitTorrentDHTState {
     }
 
     fn new_tx(&mut self) -> BitTorrentDHTTransaction {
-        let mut tx = BitTorrentDHTTransaction::new();
+        let mut tx = BitTorrentDHTTransaction::default();
         self.tx_id += 1;
         tx.tx_id = self.tx_id;
         return tx;
index ab9c637ab88f462b378791d004b8de52aee49be0..e0857f56be1f3ba612089f85cf8655a3651ba6c3 100644 (file)
@@ -39,12 +39,18 @@ pub struct DCEOpnumRange {
     pub range2: u32,
 }
 
+impl Default for DCEOpnumRange {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl DCEOpnumRange {
     pub fn new() -> Self {
-        return Self {
+        Self {
             range1: DETECT_DCE_OPNUM_RANGE_UNINITIALIZED,
             range2: DETECT_DCE_OPNUM_RANGE_UNINITIALIZED,
-        };
+        }
     }
 }
 
index 4a52d8ee40c6da66811426706fe7426c694f385e..c9eb443060ff99bf8ac49fbf60ad2b8a5f315f72 100644 (file)
@@ -235,7 +235,7 @@ pub struct DNSResponse {
     pub authorities: Vec<DNSAnswerEntry>,
 }
 
-#[derive(Debug)]
+#[derive(Debug, Default)]
 pub struct DNSTransaction {
     pub id: u64,
     pub request: Option<DNSRequest>,
@@ -250,14 +250,8 @@ impl Transaction for DNSTransaction {
 }
 
 impl DNSTransaction {
-
     pub fn new() -> Self {
-        return Self {
-            id: 0,
-            request: None,
-            response: None,
-            tx_data: AppLayerTxData::new(),
-        }
+        Default::default()
     }
 
     /// Get the DNS transactions ID (not the internal tracking ID).
@@ -342,11 +336,7 @@ impl State<DNSTransaction> for DNSState {
 impl DNSState {
 
     pub fn new() -> Self {
-            Default::default()
-    }
-
-    pub fn new_tcp() -> Self {
-            Default::default()
+        Default::default()
     }
 
     pub fn new_tx(&mut self) -> DNSTransaction {
@@ -684,7 +674,7 @@ pub extern "C" fn rs_dns_state_new(_orig_state: *mut std::os::raw::c_void, _orig
 /// Returns *mut DNSState
 #[no_mangle]
 pub extern "C" fn rs_dns_state_tcp_new() -> *mut std::os::raw::c_void {
-    let state = DNSState::new_tcp();
+    let state = DNSState::new();
     let boxed = Box::new(state);
     return Box::into_raw(boxed) as *mut _;
 }
index 1b758331840826631cab55880b98addaf65ef04f..9f4fc7f30ac9b9608970ea598b46cf7a39140c56 100644 (file)
@@ -152,9 +152,15 @@ impl Transaction for HTTP2Transaction {
     }
 }
 
+impl Default for HTTP2Transaction {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl HTTP2Transaction {
-    pub fn new() -> HTTP2Transaction {
-        HTTP2Transaction {
+    pub fn new() -> Self {
+        Self {
             tx_id: 0,
             stream_id: 0,
             child_stream_id: 0,
@@ -386,6 +392,12 @@ pub struct HTTP2DynTable {
     pub overflow: u8,
 }
 
+impl Default for HTTP2DynTable {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl HTTP2DynTable {
     pub fn new() -> Self {
         Self {
@@ -418,6 +430,12 @@ impl State<HTTP2Transaction> for HTTP2State {
     }
 }
 
+impl Default for HTTP2State {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl HTTP2State {
     pub fn new() -> Self {
         Self {
index 8064df47092f1e7d92be8dcc8cad17baa31bef9d..6ed1896d785a13681b45a86103d4b165c80d0daf 100644 (file)
@@ -60,9 +60,15 @@ pub struct IkeHeaderWrapper {
     pub ikev2_header: IkeV2Header,
 }
 
+impl Default for IkeHeaderWrapper {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl IkeHeaderWrapper {
-    pub fn new() -> IkeHeaderWrapper {
-        IkeHeaderWrapper {
+    pub fn new() -> Self {
+        Self {
             spi_initiator: String::new(),
             spi_responder: String::new(),
             maj_ver: 0,
@@ -93,6 +99,7 @@ pub struct IkePayloadWrapper {
     pub ikev2_payload_types: Vec<IkePayloadType>,
 }
 
+#[derive(Default)]
 pub struct IKETransaction {
     tx_id: u64,
 
@@ -116,18 +123,8 @@ impl Transaction for IKETransaction {
 }
 
 impl IKETransaction {
-    pub fn new() -> IKETransaction {
-        IKETransaction {
-            tx_id: 0,
-            ike_version: 0,
-            direction: Direction::ToServer,
-            hdr: IkeHeaderWrapper::new(),
-            payload_types: Default::default(),
-            notify_types: vec![],
-            logged: LoggerFlags::new(),
-            tx_data: applayer::AppLayerTxData::new(),
-            errors: 0,
-        }
+    pub fn new() -> Self {
+        Default::default()
     }
 
     /// Set an event.
index 6274c1b37b99f0b6b13500847546dbad6c36f0ac..c66162f4b519f3e7babed097f54e61dd514f68b4 100644 (file)
@@ -87,9 +87,15 @@ pub struct DetectKrb5TicketEncryptionList {
     other: Vec<EncryptionType>,
 }
 
+impl Default for DetectKrb5TicketEncryptionList {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl DetectKrb5TicketEncryptionList {
-    pub fn new() -> DetectKrb5TicketEncryptionList {
-        DetectKrb5TicketEncryptionList {
+    pub fn new() -> Self {
+        Self {
             positive: [false; KRB_TICKET_FASTARRAY_SIZE],
             negative: [false; KRB_TICKET_FASTARRAY_SIZE],
             other: Vec::new(),
index 247dd2194b67d9fc8d9604c382d78d8365a89870..9ae498fbbd92a68d38d0a90efae7ee05d20e2ebf 100644 (file)
@@ -102,9 +102,15 @@ pub fn to_hex_string(bytes: &[u8]) -> String {
     s
 }
 
+impl Default for KRB5State {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl KRB5State {
     pub fn new() -> KRB5State {
-        KRB5State{
+        Self {
             state_data: AppLayerStateData::new(),
             req_id: 0,
             record_ts: 0,
index d3b989c429c146c880eeeaa250552b0d1b35cc61..dfac0f15edceef956979927c944a77fe4b9e2f5a 100644 (file)
@@ -34,7 +34,6 @@
 #![allow(clippy::manual_find)]
 #![allow(clippy::match_like_matches_macro)]
 #![allow(clippy::module_inception)]
-#![allow(clippy::new_without_default)]
 #![allow(clippy::result_unit_err)]
 #![allow(clippy::type_complexity)]
 #![allow(clippy::upper_case_acronyms)]
index 2ffc24f85825bafac0eed3e3702899f08e45a47c..3c6a699fb6d723637f24a1f4aeaa8e38058415b7 100644 (file)
@@ -89,6 +89,7 @@ impl ModbusTransaction {
     }
 }
 
+#[derive(Default)]
 pub struct ModbusState {
     state_data: AppLayerStateData,
     pub transactions: Vec<ModbusTransaction>,
@@ -108,12 +109,7 @@ impl State<ModbusTransaction> for ModbusState {
 
 impl ModbusState {
     pub fn new() -> Self {
-        Self {
-            state_data: AppLayerStateData::new(),
-            transactions: Vec::new(),
-            tx_id: 0,
-            givenup: false,
-        }
+        Default::default()
     }
 
     pub fn get_tx(&mut self, tx_id: u64) -> Option<&mut ModbusTransaction> {
index b55e8d29520a2fe2f8e8f7390eef2a9ac121f448..2e7b47fb8f8b019f0ce387e03b0699e5370de015 100644 (file)
@@ -118,6 +118,12 @@ impl State<MQTTTransaction> for MQTTState {
     }
 }
 
+impl Default for MQTTState {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl MQTTState {
     pub fn new() -> Self {
         Self {
index 26960cdccfbbe8fddffa572b2e9620daa25d5e58..21dd0dd5d248097e9dd33cafdea36b7986e5915a 100644 (file)
@@ -211,6 +211,12 @@ pub struct NFSTransaction {
     pub tx_data: AppLayerTxData,
 }
 
+impl Default for NFSTransaction {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl NFSTransaction {
     pub fn new() -> Self {
         return Self {
@@ -342,6 +348,12 @@ pub struct NFSState {
     ts: u64,
 }
 
+impl Default for NFSState {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl State<NFSTransaction> for NFSState {
     fn get_transaction_count(&self) -> usize {
         self.transactions.len()
index f6514f4cbe506cb3b384672d333971832d520eb0..6e6f775903b7dacd5a367ef0c6a417d09f7c0c4b 100644 (file)
@@ -35,6 +35,7 @@ pub enum NTPEvent {
     NotResponse,
 }
 
+#[derive(Default)]
 pub struct NTPState {
     state_data: AppLayerStateData,
 
@@ -48,7 +49,7 @@ pub struct NTPState {
     tx_id: u64,
 }
 
-#[derive(Debug)]
+#[derive(Debug, Default)]
 pub struct NTPTransaction {
     /// The NTP reference ID
     pub xid: u32,
@@ -66,13 +67,8 @@ impl Transaction for NTPTransaction {
 }
 
 impl NTPState {
-    pub fn new() -> NTPState {
-        NTPState {
-            state_data: AppLayerStateData::new(),
-            transactions: Vec::new(),
-            events: 0,
-            tx_id: 0,
-        }
+    pub fn new() -> Self {
+        Default::default()
     }
 }
 
index 0a0eaaaf4b7fe58ea0f0151be7344d5e1ae572c1..44118273730be28052098a2a96c93fe066a9a8d5 100644 (file)
@@ -62,9 +62,15 @@ impl Transaction for PgsqlTransaction {
     }
 }
 
+impl Default for PgsqlTransaction {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl PgsqlTransaction {
-    pub fn new() -> PgsqlTransaction {
-        PgsqlTransaction {
+    pub fn new() -> Self {
+        Self {
             tx_id: 0,
             tx_state: PgsqlTransactionState::Init,
             request: None,
@@ -140,6 +146,12 @@ impl State<PgsqlTransaction> for PgsqlState {
     }
 }
 
+impl Default for PgsqlState {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+    
 impl PgsqlState {
     pub fn new() -> Self {
         Self {
index e579edadb1f2e959bcfcd2f352f960c72a2e0861..ba5bdca8b1e70aa937c23fd0440c88dc7c65b882 100644 (file)
@@ -53,9 +53,15 @@ impl Transaction for RFBTransaction {
     }
 }
 
+impl Default for RFBTransaction {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl RFBTransaction {
-    pub fn new() -> RFBTransaction {
-        RFBTransaction {
+    pub fn new() -> Self {
+        Self {
             tx_id: 0,
             complete: false,
             chosen_security_type: None,
@@ -95,6 +101,12 @@ impl State<RFBTransaction> for RFBState {
 
 }
 
+impl Default for RFBState {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl RFBState {
     pub fn new() -> Self {
         Self {
index ff4d01200c7ee160d25086e1b9df8e068959cbe0..a52f5560687e10dd062c763393a1db2c576b15ce 100755 (executable)
@@ -45,6 +45,7 @@ pub enum SIPEvent {
     InvalidData,
 }
 
+#[derive(Default)]
 pub struct SIPState {
     state_data: AppLayerStateData,
     transactions: Vec<SIPTransaction>,
@@ -78,11 +79,7 @@ impl Transaction for SIPTransaction {
 
 impl SIPState {
     pub fn new() -> SIPState {
-        SIPState {
-            state_data: AppLayerStateData::new(),
-            transactions: Vec::new(),
-            tx_id: 0,
-        }
+        Default::default()
     }
 
     pub fn free(&mut self) {
index 32ce5f621896d0c32d1c9bd48de0310467218413..54407bbe9e917ba8c6cbfa425607b644b9929c21 100644 (file)
@@ -488,12 +488,18 @@ impl Transaction for SMBTransaction {
     }
 }
 
+impl Default for SMBTransaction {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SMBTransaction {
     pub fn new() -> Self {
         return Self {
               id: 0,
               vercmd: SMBVerCmdStat::new(),
-              hdr: SMBCommonHdr::init(),
+              hdr: SMBCommonHdr::default(),
               request_done: false,
               response_done: false,
               type_data: None,
@@ -560,9 +566,6 @@ pub struct SMBCommonHdr {
 }
 
 impl SMBCommonHdr {
-    pub fn init() -> Self {
-        Default::default()
-    }
     pub fn new(rec_type: u32, ssn_id: u64, tree_id: u32, msg_id: u64) -> Self {
         Self {
             rec_type,
index 43d6ba5455a0980d732fd94ee87b3014b56d102a..f1e58ded4a93b104c5b666c57d797947bef80dae 100644 (file)
@@ -36,6 +36,7 @@ pub enum SNMPEvent {
     VersionMismatch,
 }
 
+#[derive(Default)]
 pub struct SNMPState<'a> {
     state_data: AppLayerStateData,
 
@@ -89,12 +90,7 @@ impl<'a> Transaction for SNMPTransaction<'a> {
 
 impl<'a> SNMPState<'a> {
     pub fn new() -> SNMPState<'a> {
-        SNMPState{
-            state_data: AppLayerStateData::new(),
-            version: 0,
-            transactions: Vec::new(),
-            tx_id: 0,
-        }
+        Default::default()
     }
 }
 
index 21c4d1ad3e9f8ef5711ee778d5d8e5c95ef82d68..aa05c59b72b22e4c920b2137bbe32885e25bcf26 100644 (file)
@@ -62,9 +62,15 @@ pub struct SshHeader {
     pub hassh_string: Vec<u8>,
 }
 
+impl Default for SshHeader {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl SshHeader {
     pub fn new() -> SshHeader {
-        SshHeader {
+        Self {
             record_left: 0,
             record_left_msg: parser::MessageCode::Undefined(0),
 
@@ -78,6 +84,7 @@ impl SshHeader {
     }
 }
 
+#[derive(Default)]
 pub struct SSHTransaction {
     pub srv_hdr: SshHeader,
     pub cli_hdr: SshHeader,
@@ -87,14 +94,11 @@ pub struct SSHTransaction {
 
 impl SSHTransaction {
     pub fn new() -> SSHTransaction {
-        SSHTransaction {
-            srv_hdr: SshHeader::new(),
-            cli_hdr: SshHeader::new(),
-            tx_data: AppLayerTxData::new(),
-        }
+        Default::default()
     }
 }
 
+#[derive(Default)]
 pub struct SSHState {
     state_data: AppLayerStateData,
     transaction: SSHTransaction,
@@ -102,10 +106,7 @@ pub struct SSHState {
 
 impl SSHState {
     pub fn new() -> Self {
-        Self {
-            state_data: AppLayerStateData::new(),
-            transaction: SSHTransaction::new(),
-        }
+        Default::default()
     }
 
     fn set_event(&mut self, event: SSHEvent) {
index 86e345874618c4f757e0134fcacaca53177158fc..75c752dd2038566e46ce3bca1ff0fccb203d11b0 100644 (file)
@@ -35,17 +35,15 @@ pub enum TelnetFrameType {
     Data,
 }
 
+#[derive(Default)]
 pub struct TelnetTransaction {
     tx_id: u64,
     tx_data: AppLayerTxData,
 }
 
 impl TelnetTransaction {
-    pub fn new() -> TelnetTransaction {
-        TelnetTransaction {
-            tx_id: 0,
-            tx_data: AppLayerTxData::new(),
-        }
+    pub fn new() -> Self {
+        Default::default()
     }
 }
 
@@ -92,6 +90,12 @@ impl State<TelnetTransaction> for TelnetState {
     }
 }
 
+impl Default for TelnetState {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl TelnetState {
     pub fn new() -> Self {
         Self {