Avoid using BinaryWriter where possible

This commit is contained in:
Lonami Exo
2017-09-27 21:23:59 +02:00
parent 8a605f21e6
commit c667a00281
4 changed files with 26 additions and 40 deletions

View File

@@ -1,7 +1,8 @@
import struct
from hashlib import sha1
from .. import helpers as utils
from ..extensions import BinaryReader, BinaryWriter
from ..extensions import BinaryReader
class AuthKey:
@@ -17,10 +18,5 @@ class AuthKey:
"""Calculates the new nonce hash based on
the current class fields' values
"""
with BinaryWriter() as writer:
writer.write(new_nonce)
writer.write_byte(number)
writer.write_long(self.aux_hash, signed=False)
new_nonce_hash = utils.calc_msg_key(writer.get_bytes())
return new_nonce_hash
data = new_nonce + struct.pack('<BQ', number, self.aux_hash)
return utils.calc_msg_key(data)

View File

@@ -7,7 +7,7 @@ except ImportError:
rsa = None
raise ImportError('Missing module "rsa", please install via pip.')
from ..extensions import BinaryWriter
from ..tl import TLObject
# {fingerprint: Crypto.PublicKey.RSA._RSAobj} dictionary
@@ -34,11 +34,10 @@ def _compute_fingerprint(key):
"""For a given Crypto.RSA key, computes its 8-bytes-long fingerprint
in the same way that Telegram does.
"""
with BinaryWriter() as writer:
writer.tgwrite_bytes(get_byte_array(key.n))
writer.tgwrite_bytes(get_byte_array(key.e))
# Telegram uses the last 8 bytes as the fingerprint
return sha1(writer.get_bytes()).digest()[-8:]
n = TLObject.serialize_bytes(get_byte_array(key.n))
e = TLObject.serialize_bytes(get_byte_array(key.e))
# Telegram uses the last 8 bytes as the fingerprint
return sha1(n + e).digest()[-8:]
def add_key(pub):