# Path: telethon/_misc/tlobject.py
# _EPOCH_NAIVE = datetime(*time.gmtime(0)[:6])
# _EPOCH_NAIVE_LOCAL = datetime(*time.localtime(0)[:6])
# _EPOCH = _EPOCH_NAIVE.replace(tzinfo=timezone.utc)
#     CONSTRUCTOR_ID = None
#     SUBCLASS_OF_ID = None
# def _datetime_to_timestamp(dt):
# def _json_default(value):
#     def _serialize_bytes(data):
#     def _serialize_datetime(dt):
#     def __eq__(self, o):
#     def __ne__(self, o):
#     def __repr__(self):
#     def __str__(self):
#     def stringify(self):
#     def to_dict(self):
#     def __bytes__(self):
#     def _bytes(self):
#     def _from_reader(cls, reader):
#     def _read_result(reader):
#     async def _resolve(self, client, utils):
# class TLObject:
# class TLRequest(TLObject):


import os
import struct
    import rsa
    import rsa.core
from hashlib import sha1
from .._misc import tlobject


# {fingerprint: (Crypto.PublicKey.RSA._RSAobj, old)} dictionary
_server_keys = {}


def get_byte_array(integer):
    """Return the variable length bytes corresponding to the given int"""
    # Operate in big endian (unlike most of Telegram API) since:
    # > "...pq is a representation of a natural number
    #    (in binary *big endian* format)..."
    # > "...current value of dh_prime equals
    #    (in *big-endian* byte order)..."
    # Reference: https://core.telegram.org/mtproto/auth_key
    return int.to_bytes(
        integer,
        (integer.bit_length() + 8 - 1) // 8,  # 8 bits per byte,
        byteorder='big',
        signed=False
    )


def _compute_fingerprint(key):
    """
    Given a RSA key, computes its fingerprint like Telegram does.

    :param key: the Crypto.RSA key.
    :return: its 8-bytes-long fingerprint.
    """
    n = tlobject.TLObject._serialize_bytes(get_byte_array(key.n))

# Path: telethon/_misc/tlobject.py
# _EPOCH_NAIVE = datetime(*time.gmtime(0)[:6])
# _EPOCH_NAIVE_LOCAL = datetime(*time.localtime(0)[:6])
# _EPOCH = _EPOCH_NAIVE.replace(tzinfo=timezone.utc)
#     CONSTRUCTOR_ID = None
#     SUBCLASS_OF_ID = None
# def _datetime_to_timestamp(dt):
# def _json_default(value):
#     def _serialize_bytes(data):
#     def _serialize_datetime(dt):
#     def __eq__(self, o):
#     def __ne__(self, o):
#     def __repr__(self):
#     def __str__(self):
#     def stringify(self):
#     def to_dict(self):
#     def __bytes__(self):
#     def _bytes(self):
#     def _from_reader(cls, reader):
#     def _read_result(reader):
#     async def _resolve(self, client, utils):
# class TLObject:
# class TLRequest(TLObject):


# Path: telethon/_crypto/rsa.py
import os
import struct
    import rsa
    import rsa.core
from hashlib import sha1
from .._misc import tlobject



# {fingerprint: (Crypto.PublicKey.RSA._RSAobj, old)} dictionary
_server_keys = {}


def get_byte_array(integer):
    """Return the variable length bytes corresponding to the given int"""
    # Operate in big endian (unlike most of Telegram API) since:
    # > "...pq is a representation of a natural number
    #    (in binary *big endian* format)..."
    # > "...current value of dh_prime equals
    #    (in *big-endian* byte order)..."
    # Reference: https://core.telegram.org/mtproto/auth_key
    return int.to_bytes(
        integer,
        (integer.bit_length() + 8 - 1) // 8,  # 8 bits per byte,
        byteorder='big',
        signed=False
    )


def _compute_fingerprint(key):
    """
    Given a RSA key, computes its fingerprint like Telegram does.

    :param key: the Crypto.RSA key.
    :return: its 8-bytes-long fingerprint.
    """
    n = tlobject.TLObject._serialize_bytes(get_byte_array(key.n))

    e = tlobject.TLObject._serialize_bytes(get_byte_array(key.e))