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,
}
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.

@ -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;

@ -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,
};
}
}
}

@ -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 _;
}

@ -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 {

@ -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.

@ -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(),

@ -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,

@ -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)]

@ -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> {

@ -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 {

@ -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()

@ -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()
}
}

@ -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 {

@ -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 {

@ -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) {

@ -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,

@ -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()
}
}

@ -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) {

@ -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 {

Loading…
Cancel
Save