Skip to content

Commit

Permalink
Merge pull request #64 from IdentityPython/develop
Browse files Browse the repository at this point in the history
Prepare for release 1.2.0
  • Loading branch information
rohe authored Sep 2, 2020
2 parents bed091d + 505daa9 commit 3f24ac8
Show file tree
Hide file tree
Showing 30 changed files with 221 additions and 116 deletions.
7 changes: 0 additions & 7 deletions .coveragerc

This file was deleted.

3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ addons:
install:
- pip install codecov
- pip install tox tox-travis
- pip install isort black
script:
- codecov --version
- tox
- isort --check src tests
- black -l 100 --check src tests
after_success:
- codecov
notifications:
Expand Down
69 changes: 34 additions & 35 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,38 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.coverage',
'sphinx.ext.viewcode']
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'CryptoJWT'
copyright = '2018, Roland Hedberg'
author = 'Roland Hedberg'
project = "CryptoJWT"
copyright = "2018, Roland Hedberg"
author = "Roland Hedberg"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.4'
version = "0.4"
# The full version, including alpha/beta/rc tags.
release = '0.4'
release = "0.4"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -72,10 +74,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -86,7 +88,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'default'
html_theme = "default"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -97,25 +99,25 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
"**": [
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
]
}


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'CryptoJWTdoc'
htmlhelp_basename = "CryptoJWTdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -124,15 +126,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -142,19 +141,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'CryptoJWT.tex', 'CryptoJWT Documentation',
'Roland Hedberg', 'manual'),
(master_doc, "CryptoJWT.tex", "CryptoJWT Documentation", "Roland Hedberg", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'cryptojwt', 'CryptoJWT Documentation',
[author], 1)
]
man_pages = [(master_doc, "cryptojwt", "CryptoJWT Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -163,13 +158,17 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'CryptoJWT', 'CryptoJWT Documentation',
author, 'CryptoJWT', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"CryptoJWT",
"CryptoJWT Documentation",
author,
"CryptoJWT",
"One line description of project.",
"Miscellaneous",
),
]




# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# PEP 518: https://www.python.org/dev/peps/pep-0518/

[tool.black]
line-length = 100

[tool.isort]
force_single_line = true
known_first_party = "cryptojwt"
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
line_length = 100

[tool.coverage.run]
branch = true

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"raise NotImplementedError",
]
7 changes: 0 additions & 7 deletions setup.cfg

This file was deleted.

33 changes: 19 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@

from setuptools import setup

__author__ = 'Roland Hedberg'
__author__ = "Roland Hedberg"

with open('src/cryptojwt/__init__.py', 'r') as fd:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
fd.read(), re.MULTILINE).group(1)
with open("src/cryptojwt/__init__.py", "r") as fd:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1)

tests_requires = ['responses', 'pytest', 'isort>=5.0.2', 'black']
tests_requires = ["responses", "pytest", "isort>=5.0.2", "black"]

setup(
name="cryptojwt",
Expand All @@ -35,8 +34,14 @@
author="Roland Hedberg",
author_email="[email protected]",
license="Apache 2.0",
packages=["cryptojwt", "cryptojwt/jwe", "cryptojwt/jwk", "cryptojwt/jws", "cryptojwt/tools",
"cryptojwt/serialize"],
packages=[
"cryptojwt",
"cryptojwt/jwe",
"cryptojwt/jwk",
"cryptojwt/jws",
"cryptojwt/tools",
"cryptojwt/serialize",
],
package_dir={"": "src"},
classifiers=[
"Development Status :: 4 - Beta",
Expand All @@ -45,22 +50,22 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8"
"Programming Language :: Python :: 3.8",
],
install_requires=["cryptography", "requests"],
tests_require=['pytest'],
tests_require=["pytest"],
zip_safe=False,
extras_require={
'testing': tests_requires,
'docs': ['Sphinx', 'sphinx-autobuild', 'alabaster'],
'quality': ['isort>=5.0.2', 'black'],
"testing": tests_requires,
"docs": ["Sphinx", "sphinx-autobuild", "alabaster"],
"quality": ["isort>=5.0.2", "black"],
},
scripts=glob.glob('script/*.py'),
scripts=glob.glob("script/*.py"),
entry_points={
"console_scripts": [
"jwkgen = cryptojwt.tools.keygen:main",
"jwkconv = cryptojwt.tools.keyconv:main",
"jwtpeek = cryptojwt.tools.jwtpeek:main",
]
}
},
)
2 changes: 1 addition & 1 deletion src/cryptojwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
except ImportError:
pass

__version__ = "1.1.0"
__version__ = "1.2.0"

logger = logging.getLogger(__name__)

Expand Down
9 changes: 8 additions & 1 deletion src/cryptojwt/jwe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
"ECDH-ES+A192KW",
"ECDH-ES+A256KW",
],
"enc": ["A128CBC-HS256", "A192CBC-HS384", "A256CBC-HS512", "A128GCM", "A192GCM", "A256GCM",],
"enc": [
"A128CBC-HS256",
"A192CBC-HS384",
"A256CBC-HS512",
"A128GCM",
"A192GCM",
"A256GCM",
],
}


Expand Down
3 changes: 1 addition & 2 deletions src/cryptojwt/jwe/aes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@


class AES_CBCEncrypter(Encrypter):
"""
"""
""""""

def __init__(self, key_len=32, key=None, msg_padding="PKCS7"):
Encrypter.__init__(self)
Expand Down
7 changes: 6 additions & 1 deletion src/cryptojwt/jwe/jwe_ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ def dec_setup(self, token, key=None, **kwargs):
raise Exception("Unknown key length for algorithm")

self.cek = ecdh_derive_key(
key, epubkey.pub_key, apu, apv, str(self.headers["enc"]).encode(), dk_len,
key,
epubkey.pub_key,
apu,
apv,
str(self.headers["enc"]).encode(),
dk_len,
)
elif self.headers["alg"] in [
"ECDH-ES+A128KW",
Expand Down
2 changes: 1 addition & 1 deletion src/cryptojwt/jwe/jwe_rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def encrypt(self, key, iv="", cek="", **kwargs):
return jwe.pack(parts=[jwe_enc_key, iv, ctxt, tag])

def decrypt(self, token, key, cek=None):
""" Decrypts a JWT
"""Decrypts a JWT
:param token: The JWT
:param key: A key to use for decrypting
Expand Down
4 changes: 2 additions & 2 deletions src/cryptojwt/jwe/jwekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def alg2keytype(self, alg):
return alg2keytype(alg)

def enc_setup(self, enc_alg, msg, auth_data=b"", key=None, iv=""):
""" Encrypt JWE content.
"""Encrypt JWE content.
:param enc_alg: The JWE "enc" value specifying the encryption algorithm
:param msg: The plain text message
Expand All @@ -62,7 +62,7 @@ def enc_setup(self, enc_alg, msg, auth_data=b"", key=None, iv=""):

@staticmethod
def _decrypt(enc, key, ctxt, iv, tag, auth_data=b""):
""" Decrypt JWE content.
"""Decrypt JWE content.
:param enc: The JWE "enc" value specifying the encryption algorithm
:param key: Key (CEK)
Expand Down
4 changes: 3 additions & 1 deletion src/cryptojwt/jwe/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def encrypt(self, msg, key, sign_padding="pkcs1_padding"):
return key.encrypt(
msg,
_padding(
mgf=padding.MGF1(algorithm=_chosen_hash()), algorithm=_chosen_hash(), label=None,
mgf=padding.MGF1(algorithm=_chosen_hash()),
algorithm=_chosen_hash(),
label=None,
),
)

Expand Down
4 changes: 3 additions & 1 deletion src/cryptojwt/jwk/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def key_from_jwk_dict(jwk_dict, private=None):
else:
# Ecdsa public key.
ec_pub_numbers = ec.EllipticCurvePublicNumbers(
base64url_to_long(_jwk_dict["x"]), base64url_to_long(_jwk_dict["y"]), curve,
base64url_to_long(_jwk_dict["x"]),
base64url_to_long(_jwk_dict["y"]),
curve,
)
_jwk_dict["pub_key"] = ec_pub_numbers.public_key(backends.default_backend())
return ECKey(**_jwk_dict)
Expand Down
Loading

0 comments on commit 3f24ac8

Please sign in to comment.