aboutsummaryrefslogtreecommitdiff
path: root/src/message/handshake/clientlogin.rs
blob: b619e486549d82b47a7eeac4e9d8b2fa2bd7e073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::error::ProtocolError;
use crate::primitive::{Variant, VariantMap};
use crate::HandshakeSerialize;

/// Login to the core with user data
/// username and password are transmitted in plain text
#[derive(Debug, Clone)]
pub struct ClientLogin {
    pub user: String,
    pub password: String,
}

impl HandshakeSerialize for ClientLogin {
    fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
        let mut values: VariantMap = VariantMap::new();
        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);
    }
}

impl From<VariantMap> for ClientLogin {
    fn from(mut input: VariantMap) -> Self {
        ClientLogin {
            user: input.remove("User").unwrap().try_into().unwrap(),
            password: input.remove("Password").unwrap().try_into().unwrap(),
        }
    }
}