Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typing in minioadmin.py #1367

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions minio/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from Crypto.Cipher import AES, ChaCha20_Poly1305
from Crypto.Cipher._mode_gcm import GcmMode
from Crypto.Cipher.ChaCha20_Poly1305 import ChaCha20Poly1305Cipher
from urllib3 import HTTPResponse
from urllib3.response import BaseHTTPResponse

#
# Encrypted Message Format:
Expand Down Expand Up @@ -138,7 +138,7 @@ class DecryptReader:
APIs.
"""

def __init__(self, response: HTTPResponse, secret: bytes):
def __init__(self, response: BaseHTTPResponse, secret: bytes):
self._response = response
self._secret = secret
self._payload = None
Expand All @@ -156,6 +156,7 @@ def __init__(self, response: HTTPResponse, secret: bytes):
)
self._chunk = b""
self._count = 0
self._is_closed = False

def __enter__(self):
return self
Expand Down Expand Up @@ -193,13 +194,14 @@ def _decrypt(self, payload: bytes, last_chunk: bool = False) -> bytes:

def _read_chunk(self) -> bool:
"""Read a chunk at least one byte more than chunk size."""
if self._response.isclosed():
if self._is_closed:
return True

while len(self._chunk) != (1 + _MAX_CHUNK_SIZE):
chunk = self._response.read(1 + _MAX_CHUNK_SIZE - len(self._chunk))
self._chunk += chunk
if len(chunk) == 0:
self._is_closed = True
return True

return False
Expand Down Expand Up @@ -235,7 +237,7 @@ def stream(self, num_bytes=32*1024):
break


def decrypt(response: HTTPResponse, secret_key: str) -> bytes:
def decrypt(response: BaseHTTPResponse, secret_key: str) -> bytes:
"""Decrypt response data."""
result = b""
with DecryptReader(response, secret_key.encode()) as reader:
Expand Down
Loading