aboutsummaryrefslogtreecommitdiff
path: root/src/message/signalproxy/rpccall/passwordchange.rs
blob: b96b92666d262b1faef8966aca705a5bde18b18f (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use crate::primitive::{PeerPtr, Variant};

use super::{Direction, RpcCallType};

#[derive(Clone, Debug, PartialEq)]
pub struct ChangePassword {
    /// Always zero, only has a value within of the core itself.
    peer: PeerPtr,
    /// Username
    user: String,
    /// Old Password
    before: String,
    // New Password
    after: String,
}

impl RpcCallType for ChangePassword {
    const NAME: &str = "2changePassword(PeerPtr,QString,QString,QString)";
    const DIRECTION: Direction = Direction::ClientToServer;

    fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> {
        Ok(vec![
            Variant::ByteArray(Self::NAME.to_string()),
            self.peer.clone().into(),
            self.user.clone().into(),
            self.before.clone().into(),
            self.after.clone().into(),
        ])
    }

    fn from_network(
        size: usize,
        input: &mut crate::primitive::VariantList,
    ) -> Result<(usize, super::RpcCall), crate::ProtocolError>
    where
        Self: Sized,
    {
        Ok((
            size,
            Self {
                peer: input.remove(0).try_into().unwrap(),
                user: input.remove(0).try_into().unwrap(),
                before: input.remove(0).try_into().unwrap(),
                after: input.remove(0).try_into().unwrap(),
            }
            .into(),
        ))
    }
}

/// Returns if the recent password change attempt has been a success.
/// This is one of the few responses which only gets sent to the client which sent the original request.
#[derive(Clone, Debug, PartialEq)]
pub struct PasswordChanged {
    /// Always zero, only has a value within of the core itself.
    peer: PeerPtr,
    success: bool,
}

impl RpcCallType for PasswordChanged {
    const NAME: &str = "2passwordChanged(PeerPtr,bool)";
    const DIRECTION: Direction = Direction::ServerToClient;

    fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> {
        Ok(vec![
            Variant::ByteArray(Self::NAME.to_string()),
            self.peer.clone().into(),
            self.success.clone().into(),
        ])
    }

    fn from_network(
        size: usize,
        input: &mut crate::primitive::VariantList,
    ) -> Result<(usize, super::RpcCall), crate::ProtocolError>
    where
        Self: Sized,
    {
        Ok((
            size,
            Self {
                peer: input.remove(0).try_into().unwrap(),
                success: input.remove(0).try_into().unwrap(),
            }
            .into(),
        ))
    }
}