- async mautrix.crypto.attachments.async_encrypt_attachment(data)
Async generator to encrypt data in order to send it as an encrypted attachment.
This function lazily encrypts and yields data, thus it can be used to encrypt large files without fully loading them into memory if an iterable or async iterable of bytes is passed as data.
data (Union[bytes, Iterable[bytes], AsyncIterable[bytes], io.BufferedIOBase]) – The data to encrypt. Passing an async iterable allows the file data to be read in an asynchronous and lazy (without reading the entire file into memory) way. Passing a non-async iterable or standard open binary file object will still allow the data to be read lazily, but not asynchronously.
The encrypted bytes for each chunk of data. The last yielded value will be a dict containing the info needed to decrypt data. The keys are: | key: AES-CTR JWK key object. | iv: Base64 encoded 16 byte AES-CTR IV. | hashes.sha256: Base64 encoded SHA-256 hash of the ciphertext.
- Return type
- async mautrix.crypto.attachments.async_generator_from_data(data, chunk_size=4096)
- async mautrix.crypto.attachments.async_inplace_encrypt_attachment(data)
- mautrix.crypto.attachments.decrypt_attachment(ciphertext, key, hash, iv, inplace=False)
Decrypt an encrypted attachment.
key (str) – AES_CTR JWK key object.
hash (str) – Base64 encoded SHA-256 hash of the ciphertext.
iv (str) – Base64 encoded 16 byte AES-CTR IV.
inplace (bool) – Should the decryption be performed in-place? The input must be a bytearray or writable memoryview to use this.
The plaintext bytes.
EncryptionError – if the integrity check fails.
- Return type
Encrypt data in order to send it as an encrypted attachment.
Generator to encrypt data in order to send it as an encrypted attachment.
encrypt_attachment(), this function lazily encrypts and yields data, thus it can be used to encrypt large files without fully loading them into memory if an iterable of bytes is passed as data.