aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2019-05-31 14:12:04 +0200
committerLorenz Diener <[email protected]>2019-05-31 14:12:04 +0200
commite692fac905c6639b5cd9a440d44dccb3b6b843ec (patch)
treeec82c78c7cec502c574d6c6a8190e3333168b2de /mastodon/Mastodon.py
parent739d22e642938ae61b4ec83c4b566714d2f7d498 (diff)
downloadmastodon.py-e692fac905c6639b5cd9a440d44dccb3b6b843ec.tar.gz
Make some dependencies optional
Diffstat (limited to 'mastodon/Mastodon.py')
-rw-r--r--mastodon/Mastodon.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 7b6c801..37ca999 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -20,9 +20,20 @@ import threading
20import sys 20import sys
21import six 21import six
22from decorator import decorate 22from decorator import decorate
23from cryptography.hazmat.backends import default_backend 23
24from cryptography.hazmat.primitives.asymmetric import ec 24IMPL_HAS_CRYPTO = True
25import http_ece 25try:
26 from cryptography.hazmat.backends import default_backend
27 from cryptography.hazmat.primitives.asymmetric import ec
28except:
29 IMPL_HAS_CRYPTO = False
30
31IMPL_HAS_ECE = True
32try:
33 import http_ece
34except:
35 IMPL_HAS_ECE = False
36
26import base64 37import base64
27import json 38import json
28import blurhash 39import blurhash
@@ -2306,6 +2317,9 @@ class Mastodon:
2306 Returns two dicts: One with the private key and shared secret and another with the 2317 Returns two dicts: One with the private key and shared secret and another with the
2307 public key and shared secret. 2318 public key and shared secret.
2308 """ 2319 """
2320 if not IMPL_HAS_CRYPTO:
2321 raise NotImplementedError('To use the crypto tools, please install the webpush feature dependencies.')
2322
2309 push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend()) 2323 push_key_pair = ec.generate_private_key(ec.SECP256R1(), default_backend())
2310 push_key_priv = push_key_pair.private_numbers().private_value 2324 push_key_priv = push_key_pair.private_numbers().private_value
2311 push_key_pub = push_key_pair.public_key().public_numbers().encode_point() 2325 push_key_pub = push_key_pair.public_key().public_numbers().encode_point()
@@ -2331,6 +2345,9 @@ class Mastodon:
2331 2345
2332 Returns the decoded webpush as a `push notification dict`_. 2346 Returns the decoded webpush as a `push notification dict`_.
2333 """ 2347 """
2348 if (not IMPL_HAS_ECE) or (not IMPL_HAS_CRYPTO):
2349 raise NotImplementedError('To use the crypto tools, please install the webpush feature dependencies.')
2350
2334 salt = self.__decode_webpush_b64(encryption_header.split("salt=")[1].strip()) 2351 salt = self.__decode_webpush_b64(encryption_header.split("salt=")[1].strip())
2335 dhparams = self.__decode_webpush_b64(crypto_key_header.split("dh=")[1].split(";")[0].strip()) 2352 dhparams = self.__decode_webpush_b64(crypto_key_header.split("dh=")[1].split(";")[0].strip())
2336 p256ecdsa = self.__decode_webpush_b64(crypto_key_header.split("p256ecdsa=")[1].strip()) 2353 p256ecdsa = self.__decode_webpush_b64(crypto_key_header.split("p256ecdsa=")[1].strip())
Powered by cgit v1.2.3 (git 2.41.0)