Expose key and iv parameter in downloads/uploads (#1397)

This commit is contained in:
painor
2020-03-04 16:12:34 +01:00
committed by GitHub
parent 1ec38aa5b2
commit 0e0052888f
2 changed files with 28 additions and 2 deletions

View File

@@ -8,6 +8,8 @@ import typing
import inspect
from io import BytesIO
from ..crypto import AES
from .. import utils, helpers, hints
from ..tl import types, functions, custom
@@ -439,6 +441,8 @@ class UploadMethods:
part_size_kb: float = None,
file_name: str = None,
use_cache: type = None,
key: bytes = None,
iv: bytes = None,
progress_callback: 'hints.ProgressCallback' = None) -> 'types.TypeInputFile':
"""
Uploads a file to Telegram's servers, without sending it.
@@ -476,6 +480,12 @@ class UploadMethods:
backward-compatibility (and it may get its use back in
the future).
key ('bytes', optional):
In case of an encrypted upload (secret chats) a key is supplied
iv ('bytes', optional):
In case of an encrypted upload (secret chats) an iv is supplied
progress_callback (`callable`, optional):
A callback function accepting two parameters:
``(sent bytes, total)``.
@@ -586,6 +596,10 @@ class UploadMethods:
# Read the file by in chunks of size part_size
part = stream.read(part_size)
# encryption part if needed
if key and iv:
part = AES.encrypt_ige(part, key, iv)
# The SavePartRequest is different depending on whether
# the file is too large or not (over or less than 10MB)
if is_large: