Skip to content

Commit 3f81f1f

Browse files
committed
v2.0.0 MAJOR - Added crypto.KeyManager plus more
There have been many, many changes since version 1.0, so I've decided it's about time that we finally bump our major version to version 2.0.0 While this release isn't really a *breaking change* from 1.5.0, there have been so many breaking changes introduced in the 1.x.x series, as well as major new features such as a cache abstraction layer and a cryptography module, it's worth having a clean semver slate with 2.0.0 **Docs** - Added documentation for `byteify` and `stringify` - Added documentation for the `crypto` module - Added documentation for the `setuppy` module - Updated the custom sphinx CSS to allow for a sensible 5th nesting level in the navigation - Adjusted the sphinx templates for `autosummary/class.rst` and `autosummary/module.rst` - Insert toctree directive automatically into generated files, so sub-components automatically have their RST stubs for navigation generated, instead of having to manually modify the generate files afterwards. - `:toctree:` is automatically added for module functions+classes - `:toctree:` is automatically added for class methods+attributes - The headings "Methods" and "Attributes" are automatically added for classes, for display in the navigation bar. - Added `sphinx_rtd_theme` as an import and in the extension list in `conf.py` (the README says to do this, so maybe it will prevent issues in the future?) **Packaging** - Added `extras_require` to setup.py, allowing "extras" to be specified when installing privex-helpers, instead of having to specify optional dependencies directly in your requirements.txt - Excluded the `tests` module from the package **Unit Tests** - Created `TestKeyManager` class inside of `tests/test_crypto.py` which tests the new asymmetric key system - Tests generation of RSA, ECDSA and Ed25519 keys by checking the public/private key length, as well as looking for strings in their output format - Tests loading of RSA, ECDSA, and Ed25519 keys - Tests loading invalid keys correctly raises an exception (otherwise how do we know that the previous loading attempts weren't just being ignored?) - Tests signing and verifying messages for RSA, ECDSA and Ed25519 keys - Tests encryption and decryption for RSA keys (other algorithms don't support encryption/decryption) **Code** - `crypto` module is now a folder python module - Moved EncryptHelper into crypto/EncryptHelper.py - Created crypto/base.py with helper functions such as `is_base64` and `auto_b64decode` - Created crypto/KeyManager.py - Generates Asymmetric keys in RSA, ECDSA and Ed25519 format - Serialize public/private keys into various formats, default: PEM+PKCS8 for private, OpenSSH for public - Load public/private keys in most formats, with auto detection - Ability to load a key from a file - Automatically interpolate public key when loading a private key - Ability to output generated keys to private and public file - Signing messages with RSA, ECDSA, and Ed25519 - Verifying messages with RSA, ECDSA, and Ed25519 - Encrypting messages/data with RSA - Decrypting messages/data with RSA - Lots of PyDoc blocks, clearly documenting how everything works - New `setuppy` module with various packaging related helpers, such as parsing requirements files and handling importing other requirements files - Added `InvalidFormat` exception, used by the crypto module - `common` module - New `byteify` function - convert a value into bytes if it isn't already bytes - New `stringify` function - decode bytes into a string, if it isn't already a string
1 parent 7473840 commit 3f81f1f

75 files changed

Lines changed: 1597 additions & 217 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77
python:
88
- "3.6"
99
- "3.7"
10+
- "3.8"
1011
- "3.7-dev"
1112
- "3.8-dev"
1213
- "nightly"

README.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ packaged, and so we've amalgamated them into this PyPi package, `privex-helpers`
3232
+===================================================+
3333
```
3434

35+
# Table of Contents (Github README)
36+
37+
1. [Install](#Install)
38+
1.1 [Via PyPi (pip)](#download-and-install-from-pypi)
39+
1.2 [Manually via Git](#alternative-manual-install-from-git)
40+
2. [Documentation](#documentation)
41+
3. [License](#License)
42+
4. [Example Uses](#example-uses)
43+
5. [Minimal Dependencies / Using package extras](#minimal-dependencies)
44+
6. [Unit Tests](#unit-tests)
45+
7. [Contributing](#contributing)
46+
47+
3548
# Install
3649

3750
### Download and install from PyPi
@@ -177,7 +190,7 @@ ip_is_v6('2a07:e00::1') # True
177190

178191
# Minimal dependencies
179192

180-
Most of our helper code is independant, and does not result in any extra dependencies being installed.
193+
Most of our helper code is independent, and does not result in any extra dependencies being installed.
181194

182195
Some of our helpers are dependant on external libraries or frameworks, such as Django or Flask. To avoid
183196
large Python packages such as Django being installed needlessly, we programatically enable/disable some
@@ -187,17 +200,68 @@ This package only requires (and automatically installs if needed) a single depen
187200
[privex-loghelper](https://github.com/Privex/python-loghelper) package, which itself is lightweight
188201
and dependency free.
189202

203+
As of version 1.6.0 - Privex Helpers now supports **Setuptools Extras**, allowing you
204+
to specify extra dependencies related to privex-helpers in your requirements.txt, or when running
205+
**pip3 install**.
206+
207+
```
208+
# full: Install all extra dependencies if they aren't already installed
209+
# NOTE: Excludes the `django` extras, because Django + sub-deps weighs ~30-50mb - plus you'd normally only
210+
# be using the `django` module in a Django project, where you'd have the deps installed anyway...
211+
#
212+
# crypto: Install dependencies related to the `crypto` module
213+
# cache: Install dependencies related to the `cache` module
214+
# django: Install dependencies related to the `django` module
215+
# net: Install dependencies related to the `net` module
190216
191-
Optional requirements (just `pip3 install` them depending on the helpers you require):
217+
# Example: Install privex-helpers AND all optional dependencies (excluding django), for full functionality
218+
pip3 install 'privex-helpers[full]'
219+
220+
# Example: Install privex-helpers with only the crypto and cache module dependencies
221+
pip3 install 'privex-helpers[cache,crypto]'
222+
223+
# Example: Install just privex-helpers and REQUIRED dependencies (i.e. critical to basic functionality)
224+
pip3 install privex-helpers
225+
```
226+
227+
228+
Alternatively, just `pip3 install` extra packages depending on the helpers you require:
192229

193230
```
194231
# For all Django-specific helpers in privex.helpers.django
195232
Django
196233
# For certain DNS dependant helpers in privex.helpers.net
197234
dnspython>=1.16.0
198-
# For helpers such as the r_cache decorator which is dependent on Redis
235+
# For using Redis with the privex.helpers.cache module
199236
redis>=3.3.8
237+
# For using the privex.helpers.crypto module
238+
cryptography>=2.8
239+
```
240+
241+
# Unit Tests
242+
243+
As of late October 2019, we have over 70 individual unit tests in the `tests/` folder, which are split into several
244+
`test_xxxx` files, with each file holding tests for a specific module or smaller area of code. This library
245+
consistently maintains on average 70-80% test coverage, helping to show this package is highly tested to ensure
246+
reliable and robust code.
247+
248+
We use [Travis CI](https://travis-ci.com/Privex/python-helpers) for continuous integration, which runs the test
249+
suite every time a new commit, tag, or branch is pushed to this Github repo.
250+
251+
We also use [CodeCov](https://codecov.io/gh/Privex/python-helpers) which integrates with our Travis CI setup, and
252+
provides test coverage statistics, so ourselves and contributors can visually see how much of the code is covered
253+
by our unit tests
254+
255+
TL;Dr; Run the tests:
256+
200257
```
258+
pip3 install -r docs/requirements.txt
259+
pytest -v
260+
```
261+
262+
For more information about using the unit tests, see the
263+
[How to use the unit tests](https://python-helpers.readthedocs.io/en/latest/helpers/tests.html) section of
264+
the documentation.
201265

202266
# Contributing
203267

docs/source/_static/css/custom.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22

33
.wy-nav-content {
44
max-width: 1200px !important;
5-
}
5+
}
6+
7+
li.toctree-l4 li.toctree-l5 > a {
8+
display: none
9+
}
10+
11+
li.toctree-l5.current > a {
12+
display: block
13+
}
14+
15+
.wy-menu-vertical li.toctree-l4.current li.toctree-l5 > a {
16+
display: block;
17+
background: #bdbdbd;
18+
padding: .4045em 6em;
19+
}

docs/source/_templates/autosummary/class.rst

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,34 @@
44

55
.. autoclass:: {{ objname }}
66

7-
{% block methods %}
8-
.. automethod:: __init__
9-
10-
{% if methods %}
11-
.. rubric:: Methods
12-
13-
.. autosummary::
14-
{% for item in methods %}
15-
~{{ name }}.{{ item }}
16-
{%- endfor %}
17-
{% endif %}
18-
{% endblock %}
19-
20-
{% block attributes %}
21-
{% if attributes %}
22-
.. rubric:: Attributes
23-
24-
.. autosummary::
25-
{% for item in attributes %}
26-
~{{ name }}.{{ item }}
27-
{%- endfor %}
28-
{% endif %}
29-
{% endblock %}
7+
{% block methods %}
8+
.. automethod:: __init__
9+
10+
{% if methods %}
11+
Methods
12+
^^^^^^^
13+
14+
.. rubric:: Methods
15+
16+
.. autosummary::
17+
:toctree: {{ name | lower }}
18+
{% for item in methods %}
19+
~{{ name }}.{{ item }}
20+
{%- endfor %}
21+
{% endif %}
22+
{% endblock %}
23+
24+
{% block attributes %}
25+
{% if attributes %}
26+
Attributes
27+
^^^^^^^^^^
28+
29+
.. rubric:: Attributes
30+
31+
.. autosummary::
32+
:toctree: {{ name | lower }}
33+
{% for item in attributes %}
34+
~{{ name }}.{{ item }}
35+
{%- endfor %}
36+
{% endif %}
37+
{% endblock %}

docs/source/_templates/autosummary/module.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
.. rubric:: Functions
88

99
.. autosummary::
10+
:toctree: {{ name }}
1011
{% for item in functions %}
1112
{{ item }}
1213
{%- endfor %}
@@ -18,6 +19,7 @@
1819
.. rubric:: Classes
1920

2021
.. autosummary::
22+
:toctree: {{ name }}
2123
{% for item in classes %}
2224
{{ item }}
2325
{%- endfor %}

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import os
1818
import sys
19+
import sphinx_rtd_theme
1920

2021
# Add base directory of the project to the path
2122
sys.path.insert(0, os.path.abspath('../..'))
@@ -38,6 +39,7 @@
3839
'sphinx.ext.intersphinx',
3940
'sphinx.ext.ifconfig',
4041
'sphinx.ext.viewcode',
42+
'sphinx_rtd_theme',
4143
]
4244

4345
autosummary_generate = True
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
byteify
2+
=======
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autofunction:: byteify
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
stringify
2+
=========
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autofunction:: stringify
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
auto\_b64decode
2+
===============
3+
4+
.. currentmodule:: privex.helpers.crypto.base
5+
6+
.. autofunction:: auto_b64decode
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
is\_base64
2+
==========
3+
4+
.. currentmodule:: privex.helpers.crypto.base
5+
6+
.. autofunction:: is_base64

0 commit comments

Comments
 (0)