From ff160ec40180608e223153ca60bb41cc42fbb85c Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Sat, 12 Oct 2019 00:12:22 +0200 Subject: [PATCH] Try to future-proof cryptography module while remaining extremely backwards compatible since most distributions don't even have the old one (sighs) --- mastodon/Mastodon.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 2a9833b..a3903df 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -24,6 +24,7 @@ import hashlib IMPL_HAS_CRYPTO = True try: + import cryptography from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import ec except: @@ -2587,7 +2588,10 @@ class Mastodon: push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend()) push_key_priv = push_key_pair.private_numbers().private_value - push_key_pub = push_key_pair.public_key().public_numbers().encode_point() + if bigger_version(cryptography.__version__, "2.5.0") == cryptography.__version__: + push_key_pub = push_key_pair.public_key().public_numbers().public_bytes() + else: + push_key_pub = push_key_pair.public_key().public_numbers().encode_point() push_shared_secret = os.urandom(16) priv_dict = {