decrypt streams

Skip to first unread message

Erick Rodrigues

Mar 11, 2022, 12:41:54 AM3/11/22
to python-gnupg
Hi all,

As far as I understood while reading the documentation when working with decrypt or decrypt_file methods we have two options:
1 - write the decrypted file to disk
2 - load the decrypted file content into a variable

Is it possible to get a stream instead of any of these 2?

Any help will be greatly appreciated.

Vinay Sajip

Mar 11, 2022, 12:44:56 AM3/11/22
to python-gnupg
Dear Erick,

Not using this library. It intermediates between the caller and the gpg executable, so the streams are encapsulated internally. You can use the Python subprocess module directly if you need to work with streams.

Erick Rodrigues

Mar 11, 2022, 5:35:31 PM3/11/22
to python-gnupg
Hi Vinay, thanks for taking the time to respond my question!

I actually made it work by doing this:

def write_stream(stream):
def write(data):
return False
return True
return write

# - small snippet from the code
with smart_open.smart_open(file_to_write, 'wb') as s3_file_write:
pipe_to_stream = utils.write_stream(s3_file_write)
gpg.on_data = pipe_to_stream
with smart_open.smart_open(file_to_open, 'rb') as s3_file_read:
gpg.decrypt_file(s3_file_read, passphrase=passphrase)

Vinay Sajip

Mar 11, 2022, 5:40:23 PM3/11/22
to python-gnupg
Dear Erick,

Glad on_data worked for your use case. It's not strictly a stream interface, though it does allow processing data in chunks.
Reply all
Reply to author
0 new messages