This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtelegramsession.cpp
126 lines (105 loc) · 2.84 KB
/
telegramsession.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "telegramsession.h"
#include "crypto.h"
#include "apivalues.h"
#include "apivalues.default.h"
AuthKey::AuthKey() :
key(), id(), auxHash()
{
}
AuthKey& AuthKey::operator =(QByteArray key)
{
this->key = key;
TelegramPacket hash(hashSHA1(key));
QVariant var;
readUInt64(hash, var);
auxHash = var.toULongLong();
hash.skipRawBytes(4);
readUInt64(hash, var);
id = var.toULongLong();
return *this;
}
QByteArray AuthKey::calcNewNonceHash(QByteArray newNonce, quint8 number)
{
TelegramPacket packet;
packet.writeRawBytes(newNonce);
writeUInt8(packet, number);
writeUInt64(packet, auxHash);
return hashSHA1(packet.toByteArray()).mid(4, 16);
}
AuthKey& AuthKey::deserialize(QVariantMap obj)
{
key = obj["key"].toByteArray();
id = obj["id"].toULongLong();
auxHash = obj["auxHash"].toULongLong();
return *this;
}
QVariantMap AuthKey::serialize()
{
QVariantMap obj;
obj["key"] = key;
obj["id"] = id;
obj["auxHash"] = auxHash;
return obj;
}
TelegramSession::TelegramSession() :
authKey(),
salt(),
timeOffset(),
id(),
lastMessageId(),
sequence(),
userId(),
currentDc(DC_NUMBER),
currentIp(DC_IP),
currentPort(DC_PORT),
migrateDc(),
importId(),
importBytes(),
lastPhoneNumber(),
lastPhoneCodeHash()
{
}
TelegramSession& TelegramSession::deserialize(QVariantMap obj)
{
authKey.deserialize(obj["authKey"].toMap());
salt = obj["salt"].toULongLong();
timeOffset = obj["timeOffset"].toInt();
id = obj["id"].toLongLong();
lastMessageId = obj["lastMessageId"].toLongLong();
sequence = obj["sequence"].toInt();
userId = obj["userId"].toLongLong();
currentDc = obj["currentDc"].toInt();
currentIp = obj["currentIp"].toString();
currentPort = obj["currentPort"].toInt();
if (!currentPort || !currentDc || currentIp.isEmpty()) {
currentIp = DC_IP;
currentPort = DC_PORT;
currentDc = DC_NUMBER;
}
migrateDc = obj["migrateDc"].toInt();
importId = obj["importId"].toInt();
importBytes = obj["importBytes"].toByteArray();
lastPhoneNumber = obj["lastPhoneNumber"].toString();
lastPhoneCodeHash = obj["lastPhoneCodeHash"].toString();
return *this;
}
QVariantMap TelegramSession::serialize()
{
QVariantMap obj;
obj["authKey"] = authKey.serialize();
obj["salt"] = salt;
obj["timeOffset"] = timeOffset;
obj["id"] = id;
obj["lastMessageId"] = lastMessageId;
obj["sequence"] = sequence;
obj["userId"] = userId;
obj["currentDc"] = currentDc;
obj["currentIp"] = currentIp;
obj["currentPort"] = currentPort;
obj["migrateDc"] = migrateDc;
obj["importId"] = importId;
obj["importBytes"] = importBytes;
obj["lastPhoneNumber"] = lastPhoneNumber;
obj["lastPhoneCodeHash"] = lastPhoneCodeHash;
return obj;
}