Skip to content

Commit

Permalink
Add typing in minioadmin.py
Browse files Browse the repository at this point in the history
Signed-off-by: Bala.FA <bala@minio.io>
  • Loading branch information
balamurugana committed Dec 4, 2023
1 parent 3f87658 commit 84c9d80
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 121 deletions.
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

0 comments on commit 84c9d80

Please sign in to comment.