move encoding to a constant and have same encoding for both encryption and decryption
This commit is contained in:
parent
dc7bebde92
commit
ff3fb5e431
1 changed files with 7 additions and 2 deletions
|
@ -38,6 +38,9 @@ import typing
|
|||
# see: https://gnupg.readthedocs.io/en/latest/
|
||||
import gnupg
|
||||
|
||||
# constants
|
||||
ENCODING='utf-8' # default is latin-1 which fails w some unicode chars
|
||||
|
||||
def is_message_encrypted(message: email.message.Message) -> bool:
|
||||
"""Determines whether or not an email message is encrypted.
|
||||
|
||||
|
@ -69,7 +72,7 @@ def encrypt(
|
|||
return message.as_string()
|
||||
|
||||
gpg = gnupg.GPG()
|
||||
# gpg.encoding = 'utf-8' # default is latin-1 which fails w some unicode chars
|
||||
gpg.encoding = ENCODING
|
||||
encrypted_content = gpg.encrypt(message.as_string(), recipients, armor=True)
|
||||
if not encrypted_content:
|
||||
raise ValueError(encrypted_content.status)
|
||||
|
@ -108,7 +111,9 @@ def encrypt(
|
|||
def decrypt(message: email.message.Message) -> str:
|
||||
"""Decrypt the given message
|
||||
Likely won't work on this server as I don't store private keys"""
|
||||
return str(gnupg.GPG().decrypt(message.as_string()))
|
||||
gpg = gnupg.GPG()
|
||||
gpg.encoding = ENCODING
|
||||
return str(gpg.decrypt(message.as_string()))
|
||||
|
||||
def main() -> None:
|
||||
"""Program entry"""
|
||||
|
|
Loading…
Reference in a new issue