mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Move utils.calc_msg_key into auth_key (cyclic imports py3.4)
This commit is contained in:
parent
59a1a6aef2
commit
f4182376f1
|
@ -4,7 +4,6 @@ This module holds the AuthKey class.
|
|||
import struct
|
||||
from hashlib import sha1
|
||||
|
||||
from .. import helpers as utils
|
||||
from ..extensions import BinaryReader
|
||||
|
||||
|
||||
|
@ -36,4 +35,6 @@ class AuthKey:
|
|||
"""
|
||||
new_nonce = new_nonce.to_bytes(32, 'little', signed=True)
|
||||
data = new_nonce + struct.pack('<BQ', number, self.aux_hash)
|
||||
return utils.calc_msg_key(data)
|
||||
|
||||
# Calculates the message key from the given data
|
||||
return sha1(data).digest()[4:20]
|
||||
|
|
|
@ -91,11 +91,6 @@ def calc_key(auth_key, msg_key, client):
|
|||
return aes_key, aes_iv
|
||||
|
||||
|
||||
def calc_msg_key(data):
|
||||
"""Calculates the message key from the given data"""
|
||||
return sha1(data).digest()[4:20]
|
||||
|
||||
|
||||
def generate_key_data_from_nonce(server_nonce, new_nonce):
|
||||
"""Generates the key data corresponding to the given nonce"""
|
||||
server_nonce = server_nonce.to_bytes(16, 'little', signed=True)
|
||||
|
|
|
@ -99,13 +99,6 @@ class CryptoTests(unittest.TestCase):
|
|||
assert iv == expected_iv, 'Invalid IV (expected ("{}"), got ("{}"))'.format(
|
||||
expected_iv, iv)
|
||||
|
||||
@staticmethod
|
||||
def test_calc_msg_key():
|
||||
value = utils.calc_msg_key(b'Some random message')
|
||||
expected = b'\xdfAa\xfc\x10\xab\x89\xd2\xfe\x19C\xf1\xdd~\xbf\x81'
|
||||
assert value == expected, 'Value ("{}") does not equal expected ("{}")'.format(
|
||||
value, expected)
|
||||
|
||||
@staticmethod
|
||||
def test_generate_key_data_from_nonce():
|
||||
server_nonce = int.from_bytes(b'The 16-bit nonce', byteorder='little')
|
||||
|
|
Loading…
Reference in New Issue
Block a user