Fix CdnDecrypter not being async

This commit is contained in:
Lonami Exo 2017-10-07 09:50:23 +02:00
parent 77c99db066
commit ef43e2e336
2 changed files with 7 additions and 7 deletions

View File

@ -19,7 +19,7 @@ class CdnDecrypter:
self.cdn_file_hashes = cdn_file_hashes self.cdn_file_hashes = cdn_file_hashes
@staticmethod @staticmethod
def prepare_decrypter(client, cdn_client, cdn_redirect): async def prepare_decrypter(client, cdn_client, cdn_redirect):
"""Prepares a CDN decrypter, returning (decrypter, file data). """Prepares a CDN decrypter, returning (decrypter, file data).
'client' should be an existing client not connected to a CDN. 'client' should be an existing client not connected to a CDN.
'cdn_client' should be an already-connected TelegramBareClient 'cdn_client' should be an already-connected TelegramBareClient
@ -38,14 +38,14 @@ class CdnDecrypter:
cdn_aes, cdn_redirect.cdn_file_hashes cdn_aes, cdn_redirect.cdn_file_hashes
) )
cdn_file = cdn_client(GetCdnFileRequest( cdn_file = await cdn_client(GetCdnFileRequest(
file_token=cdn_redirect.file_token, file_token=cdn_redirect.file_token,
offset=cdn_redirect.cdn_file_hashes[0].offset, offset=cdn_redirect.cdn_file_hashes[0].offset,
limit=cdn_redirect.cdn_file_hashes[0].limit limit=cdn_redirect.cdn_file_hashes[0].limit
)) ))
if isinstance(cdn_file, CdnFileReuploadNeeded): if isinstance(cdn_file, CdnFileReuploadNeeded):
# We need to use the original client here # We need to use the original client here
client(ReuploadCdnFileRequest( await client(ReuploadCdnFileRequest(
file_token=cdn_redirect.file_token, file_token=cdn_redirect.file_token,
request_token=cdn_file.request_token request_token=cdn_file.request_token
)) ))
@ -59,13 +59,13 @@ class CdnDecrypter:
return decrypter, cdn_file return decrypter, cdn_file
def get_file(self): async def get_file(self):
"""Calls GetCdnFileRequest and decrypts its bytes. """Calls GetCdnFileRequest and decrypts its bytes.
Also ensures that the file hasn't been tampered. Also ensures that the file hasn't been tampered.
""" """
if self.cdn_file_hashes: if self.cdn_file_hashes:
cdn_hash = self.cdn_file_hashes.pop(0) cdn_hash = self.cdn_file_hashes.pop(0)
cdn_file = self.client(GetCdnFileRequest( cdn_file = await self.client(GetCdnFileRequest(
self.file_token, cdn_hash.offset, cdn_hash.limit self.file_token, cdn_hash.offset, cdn_hash.limit
)) ))
cdn_file.bytes = self.cdn_aes.encrypt(cdn_file.bytes) cdn_file.bytes = self.cdn_aes.encrypt(cdn_file.bytes)

View File

@ -615,7 +615,7 @@ class TelegramBareClient:
try: try:
if cdn_decrypter: if cdn_decrypter:
result = cdn_decrypter.get_file() result = await cdn_decrypter.get_file()
else: else:
result = await client(GetFileRequest( result = await client(GetFileRequest(
input_location, offset, part_size input_location, offset, part_size
@ -623,7 +623,7 @@ class TelegramBareClient:
if isinstance(result, FileCdnRedirect): if isinstance(result, FileCdnRedirect):
cdn_decrypter, result = \ cdn_decrypter, result = \
CdnDecrypter.prepare_decrypter( await CdnDecrypter.prepare_decrypter(
client, client,
await self._get_cdn_client(result), await self._get_cdn_client(result),
result result