decrypt streams

Visto 153 veces
Saltar al primer mensaje no leído

Erick Rodrigues

no leída,
11 mar 2022, 0:41:5411/3/22
a 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

no leída,
11 mar 2022, 0:44:5611/3/22
a 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

no leída,
11 mar 2022, 17:35:3111/3/22
a python-gnupg
Hi Vinay, thanks for taking the time to respond my question!

I actually made it work by doing this:

# utils.py
def write_stream(stream):
def write(data):
try:
stream.write(data)
return False
except:
return True
return write

# index.py - 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

no leída,
11 mar 2022, 17:40:2311/3/22
a 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.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos