From: Sascha Steinbiss Date: Sat, 11 May 2024 23:52:31 +0000 (+0200) Subject: mqtt: run rustfmt X-Git-Tag: suricata-8.0.0-beta1~1047 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e047ad25e21378b210d75299cf81174e5bf69765;p=thirdparty%2Fsuricata.git mqtt: run rustfmt --- diff --git a/rust/src/jsonbuilder.rs b/rust/src/jsonbuilder.rs index 94bcaa3cfc..bc09fb43cc 100644 --- a/rust/src/jsonbuilder.rs +++ b/rust/src/jsonbuilder.rs @@ -562,7 +562,9 @@ impl JsonBuilder { } /// Set a key and a string value (from bytes) on an object, with a limited size - pub fn set_string_from_bytes_limited(&mut self, key: &str, val: &[u8], limit: usize) -> Result<&mut Self, JsonError> { + pub fn set_string_from_bytes_limited( + &mut self, key: &str, val: &[u8], limit: usize, + ) -> Result<&mut Self, JsonError> { let mut valtrunc = Vec::new(); let val = if val.len() > limit { let additional_bytes = val.len() - limit; @@ -723,12 +725,12 @@ impl JsonBuilder { } fn push_float(&mut self, val: f64) -> Result<(), JsonError> { - if val.is_nan() || val.is_infinite() { - self.push_str("null")?; - } else { - self.push_str(&val.to_string())?; - } - Ok(()) + if val.is_nan() || val.is_infinite() { + self.push_str("null")?; + } else { + self.push_str(&val.to_string())?; + } + Ok(()) } /// Encode a string into the buffer, escaping as needed. diff --git a/rust/src/mqtt/detect.rs b/rust/src/mqtt/detect.rs index df0c78e849..7a79c70652 100644 --- a/rust/src/mqtt/detect.rs +++ b/rust/src/mqtt/detect.rs @@ -410,28 +410,31 @@ pub extern "C" fn rs_mqtt_tx_unsuback_has_reason_code(tx: &MQTTTransaction, code #[cfg(test)] mod test { use super::*; + use crate::core::Direction; use crate::mqtt::mqtt::MQTTTransaction; use crate::mqtt::mqtt_message::*; use crate::mqtt::parser::FixedHeader; - use crate::core::Direction; use std; #[test] fn test_multi_unsubscribe() { - let mut t = MQTTTransaction::new(MQTTMessage { - header: FixedHeader { - message_type: MQTTTypeCode::UNSUBSCRIBE, - dup_flag: false, - qos_level: 0, - retain: false, - remaining_length: 0, + let mut t = MQTTTransaction::new( + MQTTMessage { + header: FixedHeader { + message_type: MQTTTypeCode::UNSUBSCRIBE, + dup_flag: false, + qos_level: 0, + retain: false, + remaining_length: 0, + }, + op: MQTTOperation::UNSUBSCRIBE(MQTTUnsubscribeData { + message_id: 1, + topics: vec!["foo".to_string(), "baar".to_string()], + properties: None, + }), }, - op: MQTTOperation::UNSUBSCRIBE(MQTTUnsubscribeData { - message_id: 1, - topics: vec!["foo".to_string(), "baar".to_string()], - properties: None, - }), - }, Direction::ToServer); + Direction::ToServer, + ); t.msg.push(MQTTMessage { header: FixedHeader { message_type: MQTTTypeCode::UNSUBSCRIBE, @@ -470,29 +473,32 @@ mod test { #[test] fn test_multi_subscribe() { - let mut t = MQTTTransaction::new(MQTTMessage { - header: FixedHeader { - message_type: MQTTTypeCode::SUBSCRIBE, - dup_flag: false, - qos_level: 0, - retain: false, - remaining_length: 0, + let mut t = MQTTTransaction::new( + MQTTMessage { + header: FixedHeader { + message_type: MQTTTypeCode::SUBSCRIBE, + dup_flag: false, + qos_level: 0, + retain: false, + remaining_length: 0, + }, + op: MQTTOperation::SUBSCRIBE(MQTTSubscribeData { + message_id: 1, + topics: vec![ + MQTTSubscribeTopicData { + topic_name: "foo".to_string(), + qos: 0, + }, + MQTTSubscribeTopicData { + topic_name: "baar".to_string(), + qos: 1, + }, + ], + properties: None, + }), }, - op: MQTTOperation::SUBSCRIBE(MQTTSubscribeData { - message_id: 1, - topics: vec![ - MQTTSubscribeTopicData { - topic_name: "foo".to_string(), - qos: 0, - }, - MQTTSubscribeTopicData { - topic_name: "baar".to_string(), - qos: 1, - }, - ], - properties: None, - }), - }, Direction::ToServer); + Direction::ToServer, + ); t.msg.push(MQTTMessage { header: FixedHeader { message_type: MQTTTypeCode::SUBSCRIBE, diff --git a/rust/src/mqtt/logger.rs b/rust/src/mqtt/logger.rs index 4ebdd1541c..f7a6587883 100644 --- a/rust/src/mqtt/logger.rs +++ b/rust/src/mqtt/logger.rs @@ -26,7 +26,9 @@ use std; pub const MQTT_LOG_PASSWORDS: u32 = BIT_U32!(0); #[inline] -fn log_mqtt_topic(js: &mut JsonBuilder, t: &MQTTSubscribeTopicData, max_log_len: usize ) -> Result<(), JsonError> { +fn log_mqtt_topic( + js: &mut JsonBuilder, t: &MQTTSubscribeTopicData, max_log_len: usize, +) -> Result<(), JsonError> { js.start_object()?; js.set_string_limited("topic", &t.topic_name, max_log_len)?; js.set_uint("qos", t.qos as u64)?; diff --git a/rust/src/mqtt/mqtt.rs b/rust/src/mqtt/mqtt.rs index b33069f709..1fa6280c6d 100644 --- a/rust/src/mqtt/mqtt.rs +++ b/rust/src/mqtt/mqtt.rs @@ -142,7 +142,7 @@ impl MQTTState { connected: false, skip_request: 0, skip_response: 0, - max_msg_len: unsafe { MAX_MSG_LEN}, + max_msg_len: unsafe { MAX_MSG_LEN }, tx_index_completed: 0, } } @@ -597,7 +597,14 @@ impl MQTTState { ) { let hdr = stream_slice.as_slice(); //MQTT payload has a fixed header of 2 bytes - let _mqtt_hdr = Frame::new(flow, stream_slice, hdr, 2, MQTTFrameType::Header as u8, None); + let _mqtt_hdr = Frame::new( + flow, + stream_slice, + hdr, + 2, + MQTTFrameType::Header as u8, + None, + ); SCLogDebug!("mqtt_hdr Frame {:?}", _mqtt_hdr); let rem_length = input.header.remaining_length as usize; let data = &hdr[2..rem_length + 2]; diff --git a/rust/src/mqtt/parser.rs b/rust/src/mqtt/parser.rs index eb1de176f4..83ed5d712c 100644 --- a/rust/src/mqtt/parser.rs +++ b/rust/src/mqtt/parser.rs @@ -242,8 +242,7 @@ fn parse_connack(protocol_version: u8) -> impl Fn(&[u8]) -> IResult<&[u8], MQTTC #[inline] fn parse_publish( - protocol_version: u8, - has_id: bool, + protocol_version: u8, has_id: bool, ) -> impl Fn(&[u8]) -> IResult<&[u8], MQTTPublishData> { move |i: &[u8]| { let (i, topic) = parse_mqtt_string(i)?; @@ -414,8 +413,7 @@ fn parse_unsuback(protocol_version: u8) -> impl Fn(&[u8]) -> IResult<&[u8], MQTT #[inline] fn parse_disconnect( - remaining_len: usize, - protocol_version: u8, + remaining_len: usize, protocol_version: u8, ) -> impl Fn(&[u8]) -> IResult<&[u8], MQTTDisconnectData> { move |input: &[u8]| { if protocol_version < 5 { @@ -486,11 +484,7 @@ fn parse_auth(i: &[u8]) -> IResult<&[u8], MQTTAuthData> { #[inline] fn parse_remaining_message<'a>( - full: &'a [u8], - len: usize, - skiplen: usize, - header: FixedHeader, - message_type: MQTTTypeCode, + full: &'a [u8], len: usize, skiplen: usize, header: FixedHeader, message_type: MQTTTypeCode, protocol_version: u8, ) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], MQTTMessage> { move |input: &'a [u8]| { @@ -632,9 +626,7 @@ fn parse_remaining_message<'a>( } pub fn parse_message( - input: &[u8], - protocol_version: u8, - max_msg_size: u32, + input: &[u8], protocol_version: u8, max_msg_size: u32, ) -> IResult<&[u8], MQTTMessage> { // Parse the fixed header first. This is identical across versions and can // be between 2 and 5 bytes long. @@ -939,7 +931,7 @@ mod tests { #[test] fn test_parse_msgidonly_v5() { let buf = [ - 0x00, 0x01, /* Message Identifier: 1 */ + 0x00, 0x01, /* Message Identifier: 1 */ 0x00, /* Reason Code: 0 */ 0x00, /* Properties */ 0x00, 0x61, 0x75, 0x74, 0x6f, 0x2d, 0x42, 0x34, 0x33, 0x45, 0x38, 0x30,