diff options
author | Julian Brost <julian@0x4a42.net> | 2021-02-01 00:33:07 +0300 |
---|---|---|
committer | Julian Brost <julian@0x4a42.net> | 2021-02-01 00:33:07 +0300 |
commit | 0707e3e0d949fcf39b5e3b05d6ff204eb488e41b (patch) | |
tree | 61df797ee4b3b3050b85ee14718fe386c4fd5e23 | |
parent | 46321ba65434a67ed1d258c6d886ff57ec66207e (diff) |
Add compatibility for Python 3.9
Python 3.1 deprecated base64.encodestring() in favor of the newly introduced
base64.encodebytes() [0]. In Python 3.9, base64.encodestring() got removed [1].
[0] https://docs.python.org/3.1/library/base64.html#base64.encodestring
[1] https://docs.python.org/3/whatsnew/3.9.html#removed
-rw-r--r-- | dnsviz/crypto.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/dnsviz/crypto.py b/dnsviz/crypto.py index 0a5cc62..f44833d 100644 --- a/dnsviz/crypto.py +++ b/dnsviz/crypto.py @@ -83,6 +83,13 @@ if not isinstance(GOST_ENGINE_NAME, str): GOST_ENGINE_NAME = lb2s(GOST_ENGINE_NAME) GOST_DIGEST_NAME = lb2s(GOST_DIGEST_NAME) +try: + # available from python 3.1 + base64encodebytes = base64.encodebytes +except AttributeError: + # available until python 3.8 + base64encodebytes = base64.encodestring + EC_NOCOMPRESSION = b'\x04' @@ -275,7 +282,7 @@ def _dnskey_to_rsa(key): def _dnskey_to_gost(key): der = GOST_PREFIX + key - pem = b'-----BEGIN PUBLIC KEY-----\n'+base64.encodestring(der)+b'-----END PUBLIC KEY-----' + pem = b'-----BEGIN PUBLIC KEY-----\n'+base64encodebytes(der)+b'-----END PUBLIC KEY-----' return EVP.load_key_string_pubkey(pem) @@ -287,7 +294,7 @@ def _dnskey_to_ed(alg, key): else: raise ValueError('Algorithm not supported') - pem = b'-----BEGIN PUBLIC KEY-----\n'+base64.encodestring(der)+b'-----END PUBLIC KEY-----' + pem = b'-----BEGIN PUBLIC KEY-----\n'+base64encodebytes(der)+b'-----END PUBLIC KEY-----' return EVP.load_key_string_pubkey(pem) def _dnskey_to_ec(alg, key): |