Class: MTProto::Type::AuthKey::ServerDHParams

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

Constant Summary collapse

CONSTRUCTOR =
0xd0e8075c

Class Method Summary collapse

Class Method Details

.parse(body) ⇒ Object



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
# File 'lib/mtproto/type/auth_key/server_dh_params.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

  length_byte = body[offset].ord
  offset += 1

  if length_byte == 254
    length_bytes = body[offset, 3].bytes
    encrypted_answer_length = length_bytes[0] | (length_bytes[1] << 8) | (length_bytes[2] << 16)
    offset += 3
  else
    encrypted_answer_length = length_byte
  end

  encrypted_answer = body[offset, encrypted_answer_length]

  {
    nonce: nonce,
    server_nonce: server_nonce,
    encrypted_answer: encrypted_answer
  }
end