Skip to content

Commit

Permalink
Merge pull request #15 from tekktrik/main
Browse files Browse the repository at this point in the history
Update documentation and formatting
  • Loading branch information
tannewt committed Jun 22, 2022
2 parents 17acf34 + 9a3676c commit 999eeab
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions adafruit_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

"""
`adafruit_jwt`
================================================================================
==============
JSON Web Token Authentication
Expand All @@ -27,6 +27,7 @@
https://github.com/adafruit/Adafruit_CircuitPython_RSA
"""

try:
from typing import Tuple, Union, Optional
from circuitpython_typing import ReadableBuffer
Expand All @@ -36,7 +37,6 @@
import io
import json
from adafruit_rsa import PrivateKey, sign

from adafruit_binascii import b2a_base64, a2b_base64


Expand All @@ -48,14 +48,15 @@ class JWT:
"""JSON Web Token helper for CircuitPython. Warning: JWTs are
credentials, which can grant access to resources. Be careful
where you paste them!
:param str algo: Encryption algorithm used for claims. Can be None.
:param str algo: Encryption algorithm used for claims. Can be None.
"""

@staticmethod
def validate(jwt: str) -> Tuple[str, dict]:
"""Validates a provided JWT. Does not support validating
nested signing. Returns JOSE Header and claim set.
:param str jwt: JSON Web Token.
:returns: The message's decoded JOSE header and claims.
:rtype: tuple
Expand Down Expand Up @@ -90,6 +91,7 @@ def generate(
headers: Optional[dict] = None,
) -> str:
"""Generates and returns a new JSON Web Token.
:param dict claims: JWT claims set
:param str private_key_data: Decoded RSA private key data.
:param str algo: algorithm to be used. One of None, RS256, RS384 or RS512.
Expand Down Expand Up @@ -155,6 +157,7 @@ def urlsafe_b64encode(payload: ReadableBuffer) -> str:
"""Encode bytes-like object using the URL- and filesystem-safe alphabet,
which substitutes - instead of + and _ instead of / in
the standard Base64 alphabet, and return the encoded bytes.
:param bytes payload: bytes-like object.
"""
return STRING_TOOLS.translate(
Expand All @@ -165,6 +168,7 @@ def urlsafe_b64encode(payload: ReadableBuffer) -> str:
def urlsafe_b64decode(payload: Union[ReadableBuffer, str]) -> str:
"""Decode bytes-like object or ASCII string using the URL
and filesystem-safe alphabet
:param bytes payload: bytes-like object or ASCII string
"""
return a2b_base64(STRING_TOOLS._bytes_from_decode_data(payload)).decode("utf-8")
Expand Down Expand Up @@ -194,6 +198,7 @@ def _bytes_from_decode_data(str_data: Union[ReadableBuffer, str]) -> bytes:
def translate(s: str, table: dict) -> str:
"""Return a copy of the string in which each character
has been mapped through the given translation table.
:param string s: String to-be-character-table.
:param dict table: Translation table.
"""
Expand Down

0 comments on commit 999eeab

Please sign in to comment.