2017-09-27 22:23:59 +03:00
|
|
|
import struct
|
2017-06-02 17:49:03 +03:00
|
|
|
from hashlib import sha1
|
|
|
|
|
2017-05-21 14:02:54 +03:00
|
|
|
from .. import helpers as utils
|
2017-09-27 22:23:59 +03:00
|
|
|
from ..extensions import BinaryReader
|
2016-08-28 20:26:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
class AuthKey:
|
2016-09-08 17:11:37 +03:00
|
|
|
def __init__(self, data):
|
|
|
|
self.key = data
|
2016-08-28 20:26:06 +03:00
|
|
|
|
2017-06-02 17:49:03 +03:00
|
|
|
with BinaryReader(sha1(self.key).digest()) as reader:
|
2016-08-28 20:26:06 +03:00
|
|
|
self.aux_hash = reader.read_long(signed=False)
|
|
|
|
reader.read(4)
|
|
|
|
self.key_id = reader.read_long(signed=False)
|
|
|
|
|
|
|
|
def calc_new_nonce_hash(self, new_nonce, number):
|
2017-09-04 18:10:04 +03:00
|
|
|
"""Calculates the new nonce hash based on
|
|
|
|
the current class fields' values
|
|
|
|
"""
|
2017-09-28 12:36:51 +03:00
|
|
|
new_nonce = new_nonce.to_bytes(32, 'little', signed=True)
|
2017-09-27 22:23:59 +03:00
|
|
|
data = new_nonce + struct.pack('<BQ', number, self.aux_hash)
|
|
|
|
return utils.calc_msg_key(data)
|