Class: MTProto::Type::AuthKey::ReqDHParams

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

Constant Summary collapse

CONSTRUCTOR =
0xd712e4be

Class Method Summary collapse

Class Method Details

.build(nonce:, server_nonce:, p:, q:, public_key_fingerprint:, encrypted_data:) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mtproto/type/auth_key/req_dh_params.rb', line 11

def self.build(nonce:, server_nonce:, p:, q:, public_key_fingerprint:, encrypted_data:)
  raise ArgumentError, 'Nonce must be 16 bytes' unless nonce.bytesize == 16
  raise ArgumentError, 'Server nonce must be 16 bytes' unless server_nonce.bytesize == 16

  p_bytes = Serializer.integer_to_bytes(p)
  q_bytes = Serializer.integer_to_bytes(q)

  body = Serializer.serialize_int(CONSTRUCTOR)
  body += nonce
  body += server_nonce
  body += Serializer.serialize_bytes(p_bytes)
  body += Serializer.serialize_bytes(q_bytes)
  body += Serializer.serialize_long(public_key_fingerprint)
  body += Serializer.serialize_bytes(encrypted_data)

  body
end