Coretex
coretex.cryptography.aes.decryptor.StreamDecryptor Class Reference

Public Member Functions

Generator[bytes, None, None] feed (self, bytes data)
 
bytes flush (self)
 

Detailed Description

    Implements functionality for decrypting a stream of bytes
    using AES 256.

Definition at line 28 of file decryptor.py.

Member Function Documentation

◆ feed()

Generator[bytes, None, None] coretex.cryptography.aes.decryptor.StreamDecryptor.feed (   self,
bytes  data 
)
    Decrypts the data using AES 256.

    Parameters
    ----------
    data : bytes
        data which should be decrypted

    Returns
    -------
    Generator[bytes, None, None] -> yields decrypted data in chunks

Definition at line 49 of file decryptor.py.

49  def feed(self, data: bytes) -> Generator[bytes, None, None]:
50  """
51  Decrypts the data using AES 256.
52 
53  Parameters
54  ----------
55  data : bytes
56  data which should be decrypted
57 
58  Returns
59  -------
60  Generator[bytes, None, None] -> yields decrypted data in chunks
61  """
62 
63  self._buffer.append(data)
64 
65  while self._buffer.remaining >= self.chunkSize:
66  chunk = self._buffer.getBytes(self.chunkSize)
67  yield self._decryptor.update(chunk)
68 

◆ flush()

bytes coretex.cryptography.aes.decryptor.StreamDecryptor.flush (   self)
    Decrypts any remaining data using AES 256.

    Returns
    -------
    bytes -> decrypted data

Definition at line 69 of file decryptor.py.

69  def flush(self) -> bytes:
70  """
71  Decrypts any remaining data using AES 256.
72 
73  Returns
74  -------
75  bytes -> decrypted data
76  """
77 
78  # Decrypt chunk
79  chunk = self._buffer.getRemaining()
80  chunk = self._decryptor.update(chunk) + self._decryptor.finalize()
81 
82  # Unpad chunk
83  try:
84  unpadder = padding.PKCS7(AES_BLOCK_SIZE * 8).unpadder()
85  return unpadder.update(chunk) + unpadder.finalize()
86  except ValueError:
87  # If unpadding failed either the key is wrong or
88  # the padding was not performed during encryption
89  # because ciphertext bytes were divisible by AES
90  # block size so there was no need for padding
91  return chunk
92 
93 

The documentation for this class was generated from the following file: