rust/clippy: fix lint: new_without_default

pull/8251/head
Jason Ish 3 years ago committed by Victor Julien
parent c4cf062a6f
commit da12b77f18

@ -37,9 +37,15 @@ pub struct TemplateTransaction {
tx_data: AppLayerTxData, tx_data: AppLayerTxData,
} }
impl Default for TemplateTransaction {
fn default() -> Self {
Self::new()
}
}
impl TemplateTransaction { impl TemplateTransaction {
pub fn new() -> TemplateTransaction { pub fn new() -> TemplateTransaction {
TemplateTransaction { Self {
tx_id: 0, tx_id: 0,
request: None, request: None,
response: None, response: None,
@ -54,6 +60,7 @@ impl Transaction for TemplateTransaction {
} }
} }
#[derive(Default)]
pub struct TemplateState { pub struct TemplateState {
state_data: AppLayerStateData, state_data: AppLayerStateData,
tx_id: u64, tx_id: u64,
@ -74,13 +81,7 @@ impl State<TemplateTransaction> for TemplateState {
impl TemplateState { impl TemplateState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Default::default()
state_data: AppLayerStateData::new(),
tx_id: 0,
transactions: VecDeque::new(),
request_gap: false,
response_gap: false,
}
} }
// Free a transaction by ID. // Free a transaction by ID.

@ -32,6 +32,7 @@ pub enum BitTorrentDHTEvent {
MalformedPacket, MalformedPacket,
} }
#[derive(Default)]
pub struct BitTorrentDHTTransaction { pub struct BitTorrentDHTTransaction {
tx_id: u64, tx_id: u64,
pub request_type: Option<String>, pub request_type: Option<String>,
@ -45,17 +46,8 @@ pub struct BitTorrentDHTTransaction {
} }
impl BitTorrentDHTTransaction { impl BitTorrentDHTTransaction {
pub fn new() -> BitTorrentDHTTransaction { pub fn new() -> Self {
BitTorrentDHTTransaction { Self::default()
tx_id: 0,
request_type: None,
request: None,
response: None,
error: None,
transaction_id: Vec::new(),
client_version: None,
tx_data: AppLayerTxData::new(),
}
} }
/// Set an event on the transaction /// Set an event on the transaction
@ -86,7 +78,7 @@ impl BitTorrentDHTState {
} }
fn new_tx(&mut self) -> BitTorrentDHTTransaction { fn new_tx(&mut self) -> BitTorrentDHTTransaction {
let mut tx = BitTorrentDHTTransaction::new(); let mut tx = BitTorrentDHTTransaction::default();
self.tx_id += 1; self.tx_id += 1;
tx.tx_id = self.tx_id; tx.tx_id = self.tx_id;
return tx; return tx;

@ -39,12 +39,18 @@ pub struct DCEOpnumRange {
pub range2: u32, pub range2: u32,
} }
impl Default for DCEOpnumRange {
fn default() -> Self {
Self::new()
}
}
impl DCEOpnumRange { impl DCEOpnumRange {
pub fn new() -> Self { pub fn new() -> Self {
return Self { Self {
range1: DETECT_DCE_OPNUM_RANGE_UNINITIALIZED, range1: DETECT_DCE_OPNUM_RANGE_UNINITIALIZED,
range2: DETECT_DCE_OPNUM_RANGE_UNINITIALIZED, range2: DETECT_DCE_OPNUM_RANGE_UNINITIALIZED,
}; }
} }
} }

@ -235,7 +235,7 @@ pub struct DNSResponse {
pub authorities: Vec<DNSAnswerEntry>, pub authorities: Vec<DNSAnswerEntry>,
} }
#[derive(Debug)] #[derive(Debug, Default)]
pub struct DNSTransaction { pub struct DNSTransaction {
pub id: u64, pub id: u64,
pub request: Option<DNSRequest>, pub request: Option<DNSRequest>,
@ -250,14 +250,8 @@ impl Transaction for DNSTransaction {
} }
impl DNSTransaction { impl DNSTransaction {
pub fn new() -> Self { pub fn new() -> Self {
return Self { Default::default()
id: 0,
request: None,
response: None,
tx_data: AppLayerTxData::new(),
}
} }
/// Get the DNS transactions ID (not the internal tracking ID). /// Get the DNS transactions ID (not the internal tracking ID).
@ -342,11 +336,7 @@ impl State<DNSTransaction> for DNSState {
impl DNSState { impl DNSState {
pub fn new() -> Self { pub fn new() -> Self {
Default::default() Default::default()
}
pub fn new_tcp() -> Self {
Default::default()
} }
pub fn new_tx(&mut self) -> DNSTransaction { 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 /// Returns *mut DNSState
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_dns_state_tcp_new() -> *mut std::os::raw::c_void { 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); let boxed = Box::new(state);
return Box::into_raw(boxed) as *mut _; return Box::into_raw(boxed) as *mut _;
} }

@ -152,9 +152,15 @@ impl Transaction for HTTP2Transaction {
} }
} }
impl Default for HTTP2Transaction {
fn default() -> Self {
Self::new()
}
}
impl HTTP2Transaction { impl HTTP2Transaction {
pub fn new() -> HTTP2Transaction { pub fn new() -> Self {
HTTP2Transaction { Self {
tx_id: 0, tx_id: 0,
stream_id: 0, stream_id: 0,
child_stream_id: 0, child_stream_id: 0,
@ -386,6 +392,12 @@ pub struct HTTP2DynTable {
pub overflow: u8, pub overflow: u8,
} }
impl Default for HTTP2DynTable {
fn default() -> Self {
Self::new()
}
}
impl HTTP2DynTable { impl HTTP2DynTable {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
@ -418,6 +430,12 @@ impl State<HTTP2Transaction> for HTTP2State {
} }
} }
impl Default for HTTP2State {
fn default() -> Self {
Self::new()
}
}
impl HTTP2State { impl HTTP2State {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {

@ -60,9 +60,15 @@ pub struct IkeHeaderWrapper {
pub ikev2_header: IkeV2Header, pub ikev2_header: IkeV2Header,
} }
impl Default for IkeHeaderWrapper {
fn default() -> Self {
Self::new()
}
}
impl IkeHeaderWrapper { impl IkeHeaderWrapper {
pub fn new() -> IkeHeaderWrapper { pub fn new() -> Self {
IkeHeaderWrapper { Self {
spi_initiator: String::new(), spi_initiator: String::new(),
spi_responder: String::new(), spi_responder: String::new(),
maj_ver: 0, maj_ver: 0,
@ -93,6 +99,7 @@ pub struct IkePayloadWrapper {
pub ikev2_payload_types: Vec<IkePayloadType>, pub ikev2_payload_types: Vec<IkePayloadType>,
} }
#[derive(Default)]
pub struct IKETransaction { pub struct IKETransaction {
tx_id: u64, tx_id: u64,
@ -116,18 +123,8 @@ impl Transaction for IKETransaction {
} }
impl IKETransaction { impl IKETransaction {
pub fn new() -> IKETransaction { pub fn new() -> Self {
IKETransaction { Default::default()
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,
}
} }
/// Set an event. /// Set an event.

@ -87,9 +87,15 @@ pub struct DetectKrb5TicketEncryptionList {
other: Vec<EncryptionType>, other: Vec<EncryptionType>,
} }
impl Default for DetectKrb5TicketEncryptionList {
fn default() -> Self {
Self::new()
}
}
impl DetectKrb5TicketEncryptionList { impl DetectKrb5TicketEncryptionList {
pub fn new() -> DetectKrb5TicketEncryptionList { pub fn new() -> Self {
DetectKrb5TicketEncryptionList { Self {
positive: [false; KRB_TICKET_FASTARRAY_SIZE], positive: [false; KRB_TICKET_FASTARRAY_SIZE],
negative: [false; KRB_TICKET_FASTARRAY_SIZE], negative: [false; KRB_TICKET_FASTARRAY_SIZE],
other: Vec::new(), other: Vec::new(),

@ -102,9 +102,15 @@ pub fn to_hex_string(bytes: &[u8]) -> String {
s s
} }
impl Default for KRB5State {
fn default() -> Self {
Self::new()
}
}
impl KRB5State { impl KRB5State {
pub fn new() -> KRB5State { pub fn new() -> KRB5State {
KRB5State{ Self {
state_data: AppLayerStateData::new(), state_data: AppLayerStateData::new(),
req_id: 0, req_id: 0,
record_ts: 0, record_ts: 0,

@ -34,7 +34,6 @@
#![allow(clippy::manual_find)] #![allow(clippy::manual_find)]
#![allow(clippy::match_like_matches_macro)] #![allow(clippy::match_like_matches_macro)]
#![allow(clippy::module_inception)] #![allow(clippy::module_inception)]
#![allow(clippy::new_without_default)]
#![allow(clippy::result_unit_err)] #![allow(clippy::result_unit_err)]
#![allow(clippy::type_complexity)] #![allow(clippy::type_complexity)]
#![allow(clippy::upper_case_acronyms)] #![allow(clippy::upper_case_acronyms)]

@ -89,6 +89,7 @@ impl ModbusTransaction {
} }
} }
#[derive(Default)]
pub struct ModbusState { pub struct ModbusState {
state_data: AppLayerStateData, state_data: AppLayerStateData,
pub transactions: Vec<ModbusTransaction>, pub transactions: Vec<ModbusTransaction>,
@ -108,12 +109,7 @@ impl State<ModbusTransaction> for ModbusState {
impl ModbusState { impl ModbusState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Default::default()
state_data: AppLayerStateData::new(),
transactions: Vec::new(),
tx_id: 0,
givenup: false,
}
} }
pub fn get_tx(&mut self, tx_id: u64) -> Option<&mut ModbusTransaction> { pub fn get_tx(&mut self, tx_id: u64) -> Option<&mut ModbusTransaction> {

@ -118,6 +118,12 @@ impl State<MQTTTransaction> for MQTTState {
} }
} }
impl Default for MQTTState {
fn default() -> Self {
Self::new()
}
}
impl MQTTState { impl MQTTState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {

@ -211,6 +211,12 @@ pub struct NFSTransaction {
pub tx_data: AppLayerTxData, pub tx_data: AppLayerTxData,
} }
impl Default for NFSTransaction {
fn default() -> Self {
Self::new()
}
}
impl NFSTransaction { impl NFSTransaction {
pub fn new() -> Self { pub fn new() -> Self {
return Self { return Self {
@ -342,6 +348,12 @@ pub struct NFSState {
ts: u64, ts: u64,
} }
impl Default for NFSState {
fn default() -> Self {
Self::new()
}
}
impl State<NFSTransaction> for NFSState { impl State<NFSTransaction> for NFSState {
fn get_transaction_count(&self) -> usize { fn get_transaction_count(&self) -> usize {
self.transactions.len() self.transactions.len()

@ -35,6 +35,7 @@ pub enum NTPEvent {
NotResponse, NotResponse,
} }
#[derive(Default)]
pub struct NTPState { pub struct NTPState {
state_data: AppLayerStateData, state_data: AppLayerStateData,
@ -48,7 +49,7 @@ pub struct NTPState {
tx_id: u64, tx_id: u64,
} }
#[derive(Debug)] #[derive(Debug, Default)]
pub struct NTPTransaction { pub struct NTPTransaction {
/// The NTP reference ID /// The NTP reference ID
pub xid: u32, pub xid: u32,
@ -66,13 +67,8 @@ impl Transaction for NTPTransaction {
} }
impl NTPState { impl NTPState {
pub fn new() -> NTPState { pub fn new() -> Self {
NTPState { Default::default()
state_data: AppLayerStateData::new(),
transactions: Vec::new(),
events: 0,
tx_id: 0,
}
} }
} }

@ -62,9 +62,15 @@ impl Transaction for PgsqlTransaction {
} }
} }
impl Default for PgsqlTransaction {
fn default() -> Self {
Self::new()
}
}
impl PgsqlTransaction { impl PgsqlTransaction {
pub fn new() -> PgsqlTransaction { pub fn new() -> Self {
PgsqlTransaction { Self {
tx_id: 0, tx_id: 0,
tx_state: PgsqlTransactionState::Init, tx_state: PgsqlTransactionState::Init,
request: None, request: None,
@ -140,6 +146,12 @@ impl State<PgsqlTransaction> for PgsqlState {
} }
} }
impl Default for PgsqlState {
fn default() -> Self {
Self::new()
}
}
impl PgsqlState { impl PgsqlState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {

@ -53,9 +53,15 @@ impl Transaction for RFBTransaction {
} }
} }
impl Default for RFBTransaction {
fn default() -> Self {
Self::new()
}
}
impl RFBTransaction { impl RFBTransaction {
pub fn new() -> RFBTransaction { pub fn new() -> Self {
RFBTransaction { Self {
tx_id: 0, tx_id: 0,
complete: false, complete: false,
chosen_security_type: None, chosen_security_type: None,
@ -95,6 +101,12 @@ impl State<RFBTransaction> for RFBState {
} }
impl Default for RFBState {
fn default() -> Self {
Self::new()
}
}
impl RFBState { impl RFBState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {

@ -45,6 +45,7 @@ pub enum SIPEvent {
InvalidData, InvalidData,
} }
#[derive(Default)]
pub struct SIPState { pub struct SIPState {
state_data: AppLayerStateData, state_data: AppLayerStateData,
transactions: Vec<SIPTransaction>, transactions: Vec<SIPTransaction>,
@ -78,11 +79,7 @@ impl Transaction for SIPTransaction {
impl SIPState { impl SIPState {
pub fn new() -> SIPState { pub fn new() -> SIPState {
SIPState { Default::default()
state_data: AppLayerStateData::new(),
transactions: Vec::new(),
tx_id: 0,
}
} }
pub fn free(&mut self) { pub fn free(&mut self) {

@ -488,12 +488,18 @@ impl Transaction for SMBTransaction {
} }
} }
impl Default for SMBTransaction {
fn default() -> Self {
Self::new()
}
}
impl SMBTransaction { impl SMBTransaction {
pub fn new() -> Self { pub fn new() -> Self {
return Self { return Self {
id: 0, id: 0,
vercmd: SMBVerCmdStat::new(), vercmd: SMBVerCmdStat::new(),
hdr: SMBCommonHdr::init(), hdr: SMBCommonHdr::default(),
request_done: false, request_done: false,
response_done: false, response_done: false,
type_data: None, type_data: None,
@ -560,9 +566,6 @@ pub struct SMBCommonHdr {
} }
impl 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 { pub fn new(rec_type: u32, ssn_id: u64, tree_id: u32, msg_id: u64) -> Self {
Self { Self {
rec_type, rec_type,

@ -36,6 +36,7 @@ pub enum SNMPEvent {
VersionMismatch, VersionMismatch,
} }
#[derive(Default)]
pub struct SNMPState<'a> { pub struct SNMPState<'a> {
state_data: AppLayerStateData, state_data: AppLayerStateData,
@ -89,12 +90,7 @@ impl<'a> Transaction for SNMPTransaction<'a> {
impl<'a> SNMPState<'a> { impl<'a> SNMPState<'a> {
pub fn new() -> SNMPState<'a> { pub fn new() -> SNMPState<'a> {
SNMPState{ Default::default()
state_data: AppLayerStateData::new(),
version: 0,
transactions: Vec::new(),
tx_id: 0,
}
} }
} }

@ -62,9 +62,15 @@ pub struct SshHeader {
pub hassh_string: Vec<u8>, pub hassh_string: Vec<u8>,
} }
impl Default for SshHeader {
fn default() -> Self {
Self::new()
}
}
impl SshHeader { impl SshHeader {
pub fn new() -> SshHeader { pub fn new() -> SshHeader {
SshHeader { Self {
record_left: 0, record_left: 0,
record_left_msg: parser::MessageCode::Undefined(0), record_left_msg: parser::MessageCode::Undefined(0),
@ -78,6 +84,7 @@ impl SshHeader {
} }
} }
#[derive(Default)]
pub struct SSHTransaction { pub struct SSHTransaction {
pub srv_hdr: SshHeader, pub srv_hdr: SshHeader,
pub cli_hdr: SshHeader, pub cli_hdr: SshHeader,
@ -87,14 +94,11 @@ pub struct SSHTransaction {
impl SSHTransaction { impl SSHTransaction {
pub fn new() -> SSHTransaction { pub fn new() -> SSHTransaction {
SSHTransaction { Default::default()
srv_hdr: SshHeader::new(),
cli_hdr: SshHeader::new(),
tx_data: AppLayerTxData::new(),
}
} }
} }
#[derive(Default)]
pub struct SSHState { pub struct SSHState {
state_data: AppLayerStateData, state_data: AppLayerStateData,
transaction: SSHTransaction, transaction: SSHTransaction,
@ -102,10 +106,7 @@ pub struct SSHState {
impl SSHState { impl SSHState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Default::default()
state_data: AppLayerStateData::new(),
transaction: SSHTransaction::new(),
}
} }
fn set_event(&mut self, event: SSHEvent) { fn set_event(&mut self, event: SSHEvent) {

@ -35,17 +35,15 @@ pub enum TelnetFrameType {
Data, Data,
} }
#[derive(Default)]
pub struct TelnetTransaction { pub struct TelnetTransaction {
tx_id: u64, tx_id: u64,
tx_data: AppLayerTxData, tx_data: AppLayerTxData,
} }
impl TelnetTransaction { impl TelnetTransaction {
pub fn new() -> TelnetTransaction { pub fn new() -> Self {
TelnetTransaction { Default::default()
tx_id: 0,
tx_data: AppLayerTxData::new(),
}
} }
} }
@ -92,6 +90,12 @@ impl State<TelnetTransaction> for TelnetState {
} }
} }
impl Default for TelnetState {
fn default() -> Self {
Self::new()
}
}
impl TelnetState { impl TelnetState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {

Loading…
Cancel
Save