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
|
# File 'lib/mtproto/type/auth_key/res_pq.rb', line 9
def self.parse(body)
constructor = body[0, 4].unpack1('L<')
raise "Unexpected constructor: 0x#{constructor.to_s(16)}" unless constructor == CONSTRUCTOR
offset = 4
nonce = body[offset, 16]
offset += 16
server_nonce = body[offset, 16]
offset += 16
pq_length_byte = body[offset].unpack1('C')
offset += 1
pq_length = if pq_length_byte == 254
body[offset, 3].unpack1('L<') & 0xffffff
offset += 3
else
pq_length_byte
end
pq = body[offset, pq_length]
offset += pq_length
offset += padding_length(pq_length + 1)
vector_constructor = body[offset, 4].unpack1('L<')
offset += 4
raise 'Expected vector constructor' unless vector_constructor == 0x1cb5c415
fingerprints_count = body[offset, 4].unpack1('L<')
offset += 4
fingerprints = []
fingerprints_count.times do
fingerprints << body[offset, 8].unpack1('Q<')
offset += 8
end
{
nonce: nonce,
server_nonce: server_nonce,
pq: pq,
fingerprints: fingerprints
}
end
|