Skip to content

Update documentation and formatting #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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