2016-09-17 21:42:34 +03:00
|
|
|
import telethon.helpers as utils
|
2016-11-30 00:29:42 +03:00
|
|
|
from telethon.utils import BinaryReader, BinaryWriter
|
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
|
|
|
|
2016-08-30 18:40:49 +03:00
|
|
|
with BinaryReader(utils.sha1(self.key)) 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):
|
2016-09-04 12:07:18 +03:00
|
|
|
"""Calculates the new nonce hash based on the current class fields' values"""
|
2016-08-28 20:26:06 +03:00
|
|
|
with BinaryWriter() as writer:
|
|
|
|
writer.write(new_nonce)
|
|
|
|
writer.write_byte(number)
|
|
|
|
writer.write_long(self.aux_hash, signed=False)
|
|
|
|
|
2016-09-08 17:11:37 +03:00
|
|
|
new_nonce_hash = utils.calc_msg_key(writer.get_bytes())
|
2016-08-28 20:26:06 +03:00
|
|
|
return new_nonce_hash
|