diff options
Diffstat (limited to '')
| -rw-r--r-- | src/message/handshake/clientinit.rs | 2 | ||||
| -rw-r--r-- | src/message/handshake/clientinitack.rs | 2 | ||||
| -rw-r--r-- | src/message/handshake/clientinitreject.rs | 2 | ||||
| -rw-r--r-- | src/message/handshake/clientlogin.rs | 2 | ||||
| -rw-r--r-- | src/message/handshake/clientloginack.rs | 2 | ||||
| -rw-r--r-- | src/message/handshake/connack.rs | 4 | ||||
| -rw-r--r-- | src/message/handshake/features.rs | 27 | ||||
| -rw-r--r-- | src/message/handshake/init.rs | 11 | ||||
| -rw-r--r-- | src/message/handshake/protocol.rs | 4 | ||||
| -rw-r--r-- | src/message/handshake/sessioninit.rs | 6 | ||||
| -rw-r--r-- | src/message/handshake/types.rs | 6 |
11 files changed, 33 insertions, 35 deletions
diff --git a/src/message/handshake/clientinit.rs b/src/message/handshake/clientinit.rs index 94d52cf..9d35243 100644 --- a/src/message/handshake/clientinit.rs +++ b/src/message/handshake/clientinit.rs @@ -59,7 +59,7 @@ impl HandshakeSerialize for ClientInit { "FeatureList".to_string(), Variant::StringList(self.feature_list.clone()), ); - return HandshakeSerialize::serialize(&values); + HandshakeSerialize::serialize(&values) } } diff --git a/src/message/handshake/clientinitack.rs b/src/message/handshake/clientinitack.rs index 21e65de..f3f4640 100644 --- a/src/message/handshake/clientinitack.rs +++ b/src/message/handshake/clientinitack.rs @@ -41,7 +41,7 @@ impl HandshakeSerialize for ClientInitAck { "FeatureList".to_string(), Variant::StringList(self.feature_list.clone()), ); - return HandshakeSerialize::serialize(&values); + HandshakeSerialize::serialize(&values) } } diff --git a/src/message/handshake/clientinitreject.rs b/src/message/handshake/clientinitreject.rs index 7c4bb72..fca5388 100644 --- a/src/message/handshake/clientinitreject.rs +++ b/src/message/handshake/clientinitreject.rs @@ -17,7 +17,7 @@ impl HandshakeSerialize for ClientInitReject { Variant::String("ClientInitReject".to_string()), ); values.insert("ErrorString".to_string(), Variant::String(self.error.clone())); - return HandshakeSerialize::serialize(&values); + HandshakeSerialize::serialize(&values) } } diff --git a/src/message/handshake/clientlogin.rs b/src/message/handshake/clientlogin.rs index b619e48..4be4442 100644 --- a/src/message/handshake/clientlogin.rs +++ b/src/message/handshake/clientlogin.rs @@ -16,7 +16,7 @@ impl HandshakeSerialize for ClientLogin { values.insert("MsgType".to_string(), Variant::String("ClientLogin".to_string())); values.insert("User".to_string(), Variant::String(self.user.clone())); values.insert("Password".to_string(), Variant::String(self.password.clone())); - return HandshakeSerialize::serialize(&values); + HandshakeSerialize::serialize(&values) } } diff --git a/src/message/handshake/clientloginack.rs b/src/message/handshake/clientloginack.rs index 8a12f60..de26274 100644 --- a/src/message/handshake/clientloginack.rs +++ b/src/message/handshake/clientloginack.rs @@ -14,7 +14,7 @@ impl HandshakeSerialize for ClientLoginAck { "MsgType".to_string(), Variant::String("ClientLoginAck".to_string()), ); - return HandshakeSerialize::serialize(&values); + HandshakeSerialize::serialize(&values) } } diff --git a/src/message/handshake/connack.rs b/src/message/handshake/connack.rs index d325cb9..e3accdd 100644 --- a/src/message/handshake/connack.rs +++ b/src/message/handshake/connack.rs @@ -47,13 +47,13 @@ impl crate::serialize::Deserialize for ConnAck { let (elen, extra) = i16::parse(&b[flen..])?; let (vlen, version) = i8::parse(&b[(flen + elen)..])?; - return Ok(( + Ok(( flen + elen + vlen, Self { flags, extra, version, }, - )); + )) } } diff --git a/src/message/handshake/features.rs b/src/message/handshake/features.rs index e7557e9..af967d4 100644 --- a/src/message/handshake/features.rs +++ b/src/message/handshake/features.rs @@ -49,19 +49,18 @@ pub enum Feature { impl Feature { pub fn get() -> StringList { - let mut features = StringList::new(); - features.push("ExtendedFeatures".to_string()); - #[cfg(feature = "long-message-id")] - features.push("LongMessageId".to_string()); - #[cfg(feature = "long-time")] - features.push("LongTime".to_string()); - #[cfg(feature = "rich-messages")] - features.push("RichMessages".to_string()); - #[cfg(feature = "sender-prefixes")] - features.push("SenderPrefixes".to_string()); - #[cfg(feature = "authenticators")] - features.push("Authenticators".to_string()); - - return features; + vec![ + "ExtendedFeatures".to_string(), + #[cfg(feature = "long-message-id")] + "LongMessageId".to_string(), + #[cfg(feature = "long-time")] + "LongTime".to_string(), + #[cfg(feature = "rich-messages")] + "RichMessages".to_string(), + #[cfg(feature = "sender-prefixes")] + "SenderPrefixes".to_string(), + #[cfg(feature = "authenticators")] + "Authenticators".to_string(), + ] } } diff --git a/src/message/handshake/init.rs b/src/message/handshake/init.rs index 9f011ed..e303802 100644 --- a/src/message/handshake/init.rs +++ b/src/message/handshake/init.rs @@ -1,7 +1,7 @@ use crate::serialize::{Deserialize, Serialize}; /// The first few bytes sent to the core to initialize the connection and setup if we want to use tls and compression -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Init { pub tls: bool, pub compression: bool, @@ -9,10 +9,7 @@ pub struct Init { impl Init { pub fn new() -> Self { - Self { - tls: false, - compression: false, - } + Self::default() } pub fn compression(mut self, v: bool) -> Self { @@ -47,7 +44,7 @@ impl Init { init.extend(handshake.serialize().unwrap()); init.extend(crate::message::Protocol::Datastream.serialize()); - return init; + init } pub fn parse(buf: &[u8]) -> Self { @@ -66,6 +63,6 @@ impl Init { init.tls = true } - return init; + init } } diff --git a/src/message/handshake/protocol.rs b/src/message/handshake/protocol.rs index 73a82b9..2a7d9ac 100644 --- a/src/message/handshake/protocol.rs +++ b/src/message/handshake/protocol.rs @@ -1,13 +1,15 @@ use crate::serialize::{Deserialize, Serialize}; +#[derive(Debug, Default)] pub enum Protocol { Legacy = 0x00000001, + #[default] Datastream = 0x00000002, } impl Protocol { pub fn new() -> Self { - Protocol::Datastream + Protocol::default() } pub fn serialize(self) -> Vec<u8> { diff --git a/src/message/handshake/sessioninit.rs b/src/message/handshake/sessioninit.rs index e2a29ad..b3a0932 100644 --- a/src/message/handshake/sessioninit.rs +++ b/src/message/handshake/sessioninit.rs @@ -37,7 +37,7 @@ impl From<VariantMap> for SessionInit { network_ids: network_ids .iter() .map(|network| match network { - Variant::NetworkId(network) => network.clone(), + Variant::NetworkId(network) => *network, _ => unimplemented!(), }) .collect(), @@ -72,10 +72,10 @@ impl HandshakeSerialize for SessionInit { Variant::VariantList( self.network_ids .iter() - .map(|id| Variant::NetworkId(id.clone())) + .map(|id| Variant::NetworkId(*id)) .collect(), ), ); - return HandshakeSerialize::serialize(&values); + HandshakeSerialize::serialize(&values) } } diff --git a/src/message/handshake/types.rs b/src/message/handshake/types.rs index bebeb4c..9bd8aec 100644 --- a/src/message/handshake/types.rs +++ b/src/message/handshake/types.rs @@ -10,7 +10,7 @@ use crate::message::handshake::{HandshakeDeserialize, HandshakeSerialize}; use crate::primitive::VariantMap; impl HandshakeSerialize for VariantMap { - fn serialize<'a>(&'a self) -> Result<Vec<u8>, ProtocolError> { + fn serialize(&self) -> Result<Vec<u8>, ProtocolError> { let mut res: Vec<u8> = Vec::new(); for (k, v) in self { @@ -22,7 +22,7 @@ impl HandshakeSerialize for VariantMap { let len: i32 = (self.len() * 2).try_into().unwrap(); util::insert_bytes(0, &mut res, &mut (len).to_be_bytes()); - return Ok(res); + Ok(res) } } @@ -47,7 +47,7 @@ impl HandshakeDeserialize for VariantMap { }; } - return Ok((pos, map)); + Ok((pos, map)) } } |
