11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/mtproto/type/auth_key/dh_gen_response.rb', line 11
def self.parse(body)
constructor = body[0, 4].unpack1('L<')
offset = 4
nonce = body[offset, 16]
offset += 16
server_nonce = body[offset, 16]
offset += 16
new_nonce_hash = body[offset, 16]
case constructor
when CONSTRUCTOR_DH_GEN_OK
{ status: :ok, nonce: nonce, server_nonce: server_nonce, new_nonce_hash: new_nonce_hash }
when CONSTRUCTOR_DH_GEN_RETRY
{ status: :retry, nonce: nonce, server_nonce: server_nonce, new_nonce_hash: new_nonce_hash }
when CONSTRUCTOR_DH_GEN_FAIL
{ status: :fail, nonce: nonce, server_nonce: server_nonce, new_nonce_hash: new_nonce_hash }
else
raise "Unexpected constructor: 0x#{constructor.to_s(16)}"
end
end
|