Class: MTProto::UnencryptedMessage
- Inherits:
-
Object
- Object
- MTProto::UnencryptedMessage
- Extended by:
- Binary
- Includes:
- Binary
- Defined in:
- lib/mtproto/unencrypted_message.rb
Overview
The unencrypted MTProto transport envelope (auth_key_id=0 | msg_id | len | body), used for the plaintext request/response of the DH key exchange. Its encrypted sibling is EncryptedMessage; the runtime never decrypts through this class.
Instance Attribute Summary collapse
-
#auth_key_id ⇒ Object
readonly
Returns the value of attribute auth_key_id.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#msg_id ⇒ Object
readonly
Returns the value of attribute msg_id.
Class Method Summary collapse
Instance Method Summary collapse
- #bytes ⇒ Object
-
#initialize(body, msg_id: self.class.generate_msg_id, auth_key_id: 0) ⇒ UnencryptedMessage
constructor
A new instance of UnencryptedMessage.
Methods included from Binary
Constructor Details
#initialize(body, msg_id: self.class.generate_msg_id, auth_key_id: 0) ⇒ UnencryptedMessage
Returns a new instance of UnencryptedMessage.
13 14 15 16 17 |
# File 'lib/mtproto/unencrypted_message.rb', line 13 def initialize(body, msg_id: self.class.generate_msg_id, auth_key_id: 0) @auth_key_id = auth_key_id @msg_id = msg_id @body = body end |
Instance Attribute Details
#auth_key_id ⇒ Object (readonly)
Returns the value of attribute auth_key_id.
11 12 13 |
# File 'lib/mtproto/unencrypted_message.rb', line 11 def auth_key_id @auth_key_id end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
11 12 13 |
# File 'lib/mtproto/unencrypted_message.rb', line 11 def body @body end |
#msg_id ⇒ Object (readonly)
Returns the value of attribute msg_id.
11 12 13 |
# File 'lib/mtproto/unencrypted_message.rb', line 11 def msg_id @msg_id end |
Class Method Details
.generate_msg_id ⇒ Object
35 36 37 |
# File 'lib/mtproto/unencrypted_message.rb', line 35 def self.generate_msg_id (Time.now.to_f * (2**32)).to_i & ~3 end |
.parse(packet) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/mtproto/unencrypted_message.rb', line 19 def self.parse(packet) data = packet.data msg_id = b_u64(data[8, 8]) body_length = b_u32(data[16, 4]) body = data[20, body_length] new(body, msg_id: msg_id, auth_key_id: 0) end |
Instance Method Details
#bytes ⇒ Object
28 29 30 31 32 33 |
# File 'lib/mtproto/unencrypted_message.rb', line 28 def bytes u64_b(@auth_key_id) + u64_b(@msg_id) + u32_b(@body.length) + @body end |