diff options
-rw-r--r-- | docs/index.rst | 3 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 23 | ||||
-rw-r--r-- | setup.py | 23 |
3 files changed, 41 insertions, 8 deletions
diff --git a/docs/index.rst b/docs/index.rst index 52bac0f..45d8202 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -1135,6 +1135,9 @@ displayed. | |||
1135 | 1135 | ||
1136 | Mastodon allows an application to have one webpush subscription per user at a time. | 1136 | Mastodon allows an application to have one webpush subscription per user at a time. |
1137 | 1137 | ||
1138 | All crypto utilities require Mastodon.pys optional "webpush" feature dependencies | ||
1139 | (specifically, the "cryptography" and "http_ece" packages). | ||
1140 | |||
1138 | .. automethod:: Mastodon.push_subscription | 1141 | .. automethod:: Mastodon.push_subscription |
1139 | .. automethod:: Mastodon.push_subscription_set | 1142 | .. automethod:: Mastodon.push_subscription_set |
1140 | .. automethod:: Mastodon.push_subscription_update | 1143 | .. automethod:: Mastodon.push_subscription_update |
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 | |||
20 | import sys | 20 | import sys |
21 | import six | 21 | import six |
22 | from decorator import decorate | 22 | from decorator import decorate |
23 | from cryptography.hazmat.backends import default_backend | 23 | |
24 | from cryptography.hazmat.primitives.asymmetric import ec | 24 | IMPL_HAS_CRYPTO = True |
25 | import http_ece | 25 | try: |
26 | from cryptography.hazmat.backends import default_backend | ||
27 | from cryptography.hazmat.primitives.asymmetric import ec | ||
28 | except: | ||
29 | IMPL_HAS_CRYPTO = False | ||
30 | |||
31 | IMPL_HAS_ECE = True | ||
32 | try: | ||
33 | import http_ece | ||
34 | except: | ||
35 | IMPL_HAS_ECE = False | ||
36 | |||
26 | import base64 | 37 | import base64 |
27 | import json | 38 | import json |
28 | import blurhash | 39 | import 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()) |
@@ -1,12 +1,27 @@ | |||
1 | from setuptools import setup | 1 | from setuptools import setup |
2 | 2 | ||
3 | test_deps = ['pytest', 'pytest-runner', 'pytest-cov', 'vcrpy', 'pytest-vcr', 'pytest-mock', 'requests-mock'] | 3 | test_deps = [ |
4 | 'pytest', | ||
5 | 'pytest-runner', | ||
6 | 'pytest-cov', | ||
7 | 'vcrpy', | ||
8 | 'pytest-vcr', | ||
9 | 'pytest-mock', | ||
10 | 'requests-mock' | ||
11 | ] | ||
12 | |||
13 | webpush_deps = [ | ||
14 | 'http_ece>=1.0.5', | ||
15 | 'cryptography>=1.6.0', | ||
16 | ] | ||
17 | |||
4 | extras = { | 18 | extras = { |
5 | "test": test_deps | 19 | "test": test_deps, |
20 | "webpush": webpush_deps, | ||
6 | } | 21 | } |
7 | 22 | ||
8 | setup(name='Mastodon.py', | 23 | setup(name='Mastodon.py', |
9 | version='1.4.2', | 24 | version='1.4.3', |
10 | description='Python wrapper for the Mastodon API', | 25 | description='Python wrapper for the Mastodon API', |
11 | packages=['mastodon'], | 26 | packages=['mastodon'], |
12 | install_requires=[ | 27 | install_requires=[ |
@@ -16,8 +31,6 @@ setup(name='Mastodon.py', | |||
16 | 'pytz', | 31 | 'pytz', |
17 | 'python-magic', | 32 | 'python-magic', |
18 | 'decorator>=4.0.0', | 33 | 'decorator>=4.0.0', |
19 | 'http_ece>=1.0.5', | ||
20 | 'cryptography>=1.6.0', | ||
21 | 'blurhash>=1.1.3', | 34 | 'blurhash>=1.1.3', |
22 | ], | 35 | ], |
23 | tests_require=test_deps, | 36 | tests_require=test_deps, |