use pgpy if python-gnupg fails
This commit is contained in:
parent
9210459a72
commit
5a190ed840
|
@ -424,10 +424,17 @@ def prepare_pgp_message(orig_msg: Message, pgp_fingerprint: str, public_key: str
|
||||||
x = random.randint(0, 9)
|
x = random.randint(0, 9)
|
||||||
if x >= 5:
|
if x >= 5:
|
||||||
LOG.d("encrypt using python-gnupg")
|
LOG.d("encrypt using python-gnupg")
|
||||||
|
try:
|
||||||
encrypted_data = pgp_utils.encrypt_file(
|
encrypted_data = pgp_utils.encrypt_file(
|
||||||
BytesIO(orig_msg.as_bytes()), pgp_fingerprint
|
BytesIO(orig_msg.as_bytes()), pgp_fingerprint
|
||||||
)
|
)
|
||||||
second.set_payload(encrypted_data)
|
second.set_payload(encrypted_data)
|
||||||
|
except PGPException:
|
||||||
|
LOG.exception("Cannot encrypt using python-gnupg, use pgpy")
|
||||||
|
encrypted_data = pgp_utils.encrypt_file_with_pgpy(
|
||||||
|
orig_msg.as_bytes(), public_key
|
||||||
|
)
|
||||||
|
second.set_payload(str(encrypted_data))
|
||||||
else:
|
else:
|
||||||
LOG.d("encrypt using pgpy")
|
LOG.d("encrypt using pgpy")
|
||||||
encrypted_data = pgp_utils.encrypt_file_with_pgpy(
|
encrypted_data = pgp_utils.encrypt_file_with_pgpy(
|
||||||
|
|
Loading…
Reference in a new issue