Class: MTProto::Type::AuthKey::DHGenResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/type/auth_key/dh_gen_response.rb

Constant Summary collapse

CONSTRUCTOR_DH_GEN_OK =
0x3bcbf734
CONSTRUCTOR_DH_GEN_RETRY =
0x46dc1fb9
CONSTRUCTOR_DH_GEN_FAIL =
0xa69dae02

Class Method Summary collapse

Class Method Details

.parse(body) ⇒ Object



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