aboutsummaryrefslogtreecommitdiff
path: root/src/message/handshake/clientlogin.rs
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2021-01-02 19:57:06 +0100
committerMax Audron <audron@cocaine.farm>2021-01-02 19:57:06 +0100
commit13734288dbc63c48af0b8f75f0453f0d30b750a7 (patch)
tree6396e113041ca61e26aaed3a782da445e461549d /src/message/handshake/clientlogin.rs
parentupdate (diff)
rework handshakemessage parsing
Diffstat (limited to 'src/message/handshake/clientlogin.rs')
-rw-r--r--src/message/handshake/clientlogin.rs26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/message/handshake/clientlogin.rs b/src/message/handshake/clientlogin.rs
index 769245b..dffd996 100644
--- a/src/message/handshake/clientlogin.rs
+++ b/src/message/handshake/clientlogin.rs
@@ -1,12 +1,11 @@
-use crate::error::ProtocolError;
use crate::primitive::{Variant, VariantMap};
-use crate::{HandshakeDeserialize, HandshakeSerialize};
+use crate::HandshakeSerialize;
use failure::Error;
/// Login to the core with user data
/// username and password are transmitted in plain text
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct ClientLogin {
pub user: String,
pub password: String,
@@ -28,22 +27,11 @@ impl HandshakeSerialize for ClientLogin {
}
}
-impl HandshakeDeserialize for ClientLogin {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
- let (len, values): (usize, VariantMap) = HandshakeDeserialize::parse(b)?;
-
- let msgtype = match_variant!(&values["MsgType"], Variant::StringUTF8);
-
- if msgtype == "ClientLogin" {
- return Ok((
- len,
- Self {
- user: match_variant!(values["User"], Variant::String),
- password: match_variant!(values["Password"], Variant::String),
- },
- ));
- } else {
- bail!(ProtocolError::WrongMsgType);
+impl From<VariantMap> for ClientLogin {
+ fn from(input: VariantMap) -> Self {
+ ClientLogin {
+ user: match_variant!(input.get("User").unwrap(), Variant::String),
+ password: match_variant!(input.get("Password").unwrap(), Variant::String),
}
}
}