Skip to content

Commit cbb7541

Browse files
brentrubrentru
authored andcommitted
support SHA384/512 signatures with RS384/RS512 algorithms
1 parent f3be256 commit cbb7541

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

README.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Introduction
1313
:target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_JWT
1414
:alt: Build Status
1515

16-
JSON Web Token Authentication
16+
JSON Web Token (JWT) Authentication module for CircuitPython. JSON Web Tokens are an open, industry standard
17+
`RFC 7519 <https://tools.ietf.org/html/rfc7519>`_ method for representing claims securely between two parties. Module
18+
includes methods for JWT generation and verification.
1719

1820

1921
Dependencies
@@ -31,9 +33,6 @@ Installing from PyPI
3133
.. note:: This library is not available on PyPI yet. Install documentation is included
3234
as a standard element. Stay tuned for PyPI availability!
3335

34-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
35-
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
36-
3736
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
3837
PyPI <https://pypi.org/project/adafruit-circuitpython-jwt/>`_. To install for current user:
3938

adafruit_jwt.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,22 @@ def generate(claims, private_key_data=None, algo=None):
110110
# Compute the signature
111111
if algo == "none":
112112
jwt = "{}.{}".format(jose_header, claims)
113-
elif algo in ("RS256", "RS384", "RS512"):
113+
return jwt
114+
if algo == "RS256":
114115
signature = STRING_TOOLS.urlsafe_b64encode(
115116
sign(payload, priv_key, "SHA-256"))
116-
jwt = payload + "." + signature
117+
elif algo == "RS384":
118+
signature = STRING_TOOLS.urlsafe_b64encode(
119+
sign(payload, priv_key, "SHA-384"))
120+
elif algo == "RS512":
121+
signature = STRING_TOOLS.urlsafe_b64encode(
122+
sign(payload, priv_key, "SHA-512"))
117123
else:
118124
raise TypeError(
119125
"Adafruit_JWT is currently only compatible with algorithms within"
120126
"the Adafruit_RSA module."
121127
)
128+
jwt = payload + "." + signature
122129
return jwt
123130

124131

0 commit comments

Comments
 (0)