Skip to content

Commit 03804e5

Browse files
committed
Merge branch 'main' of https://github.com/h5rdly/webtoken
2 parents 92f8d83 + b0ed97e commit 03804e5

3 files changed

Lines changed: 44 additions & 24 deletions

File tree

.github/workflows/release.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions:
1010
contents: read
1111

1212
jobs:
13-
# --- 1. Linux (Glibc - Ubuntu, Debian, CentOS, Fedora) ---
13+
## -- Linux + Glibc - Ubuntu, Debian, CentOS, Fedora
1414
linux:
1515
runs-on: ubuntu-latest
1616
strategy:
@@ -34,7 +34,7 @@ jobs:
3434
name: wheels-linux-${{ matrix.target }}
3535
path: dist
3636

37-
# --- 2. Linux (Musl - Alpine) ---
37+
## -- Linux + Musl - Alpine
3838
musllinux:
3939
runs-on: ubuntu-latest
4040
strategy:
@@ -58,7 +58,7 @@ jobs:
5858
name: wheels-musl-${{ matrix.target }}
5959
path: dist
6060

61-
# --- 3. Windows ---
61+
## -- Windows
6262
windows:
6363
runs-on: windows-latest
6464
steps:
@@ -84,7 +84,7 @@ jobs:
8484
name: wheels-windows
8585
path: dist
8686

87-
# --- 4. macOS (Intel + Apple Silicon) ---
87+
## -- macOS (Intel + Apple Silicon)
8888
macos:
8989
runs-on: macos-latest
9090
strategy:
@@ -107,7 +107,7 @@ jobs:
107107
name: wheels-macos-${{ matrix.target }}
108108
path: dist
109109

110-
# --- 5. The Source Distribution (The FreeBSD Fix) ---
110+
## -- Source Distribution - FreeBSD
111111
sdist:
112112
runs-on: ubuntu-latest
113113
steps:
@@ -123,7 +123,7 @@ jobs:
123123
name: wheels-sdist
124124
path: dist
125125

126-
# --- 6. Publish to PyPI ---
126+
## -- PyPI
127127
release:
128128
name: Release
129129
runs-on: ubuntu-latest
@@ -137,4 +137,4 @@ jobs:
137137
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
138138
with:
139139
command: upload
140-
args: --non-interactive --skip-existing wheels-*/*
140+
args: --non-interactive --skip-existing wheels-*/*

README.md

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Size
88

9-
The Rust `.so` file on linux is ~3.7Mb, no external dependencies.
9+
The `.so` size on linux is ~3.7Mb, no external dependencies.
1010

1111
## Speed
1212

@@ -29,17 +29,19 @@ ES512
2929
Enc: 1.9x | Dec: 1.5x
3030
```
3131

32-
See (and suggest!) more benchmarks under [benchmarks](https://github.com/h5rdly/toke/blob/main/benchmarks/)
32+
See and suggest more benchmarks under [benchmarks](https://github.com/h5rdly/toke/blob/main/benchmarks/).
3333

3434
## Installation
3535

3636
`pip install webtoken`
3737

38-
Developed on Linux / Python 3.13, currently can't attest to other platforms.
38+
- Developed on Linux / Python 3.13
39+
- Wheels available for Linux (+ Alpine) / Windows / MacOS
40+
- `sdist` for FreeBSD
3941

4042
## Usage
4143

42-
1. PyJWT Style (Drop-in Replacement)
44+
#### PyJWT Style (Drop-in Replacement)
4345

4446
```python
4547
import webtoken as jwt
@@ -53,9 +55,7 @@ print(decoded)
5355
# {'sub': '1234567890', 'name': 'John Doe', 'iat': 1516239022}
5456
```
5557

56-
2. webtoken style - in design
57-
58-
3. Asyncio variants
58+
#### Asyncio variants
5959

6060
```python
6161
import webtoken as wt
@@ -69,32 +69,52 @@ token = await wt.encode_async(payload, "secret", algorithm="HS256")
6969
decoded = await wt.decode_async(token, "secret", algorithms=["HS256"])
7070
print(decoded)
7171
# {'name': 'Bob'}
72+
```
73+
#### Crypto / base64 complementary utils
74+
75+
Since webtoken already has aws-lc-rs in its standalone module, it exposes several auxiliary utilities.
76+
77+
This, for example, allows running tests, such as the PyJWT ported test suites, without importing cryptography.
78+
79+
```python
80+
import webtoken as wt
81+
82+
83+
wt.base64url_encode('bob') # utf8 strings or bytes
84+
# b'Ym9i'
85+
86+
wt.base64url_decode(b'Ym9i').decode()
87+
# 'bob'
88+
89+
wt.random_bytes(7) # cryptographically secure random bytes
90+
# b'j>A\x0cj\xac\x7f'
91+
92+
priv, pub = wt.generate_key_pair('rs256')
93+
# pub = b'-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhki.......a2ODLeYTResxi\nnQIDAQAB\n-----END PUBLIC KEY-----\n'
94+
7295
```
7396

7497
## Compatibility
7598

76-
Effort is made to make toke as compatible as possible with [PyJWT](https://github.com/jpadilla/pyjwt). To that effect, changes are made to make the relevant tests from the extensive PyJWT [test suite](https://github.com/jpadilla/pyjwt/tree/master/tests) pass.
99+
Effort is made to make toke as compatible as possible with [PyJWT](https://github.com/jpadilla/pyjwt). For compatibility details, See the readme under [tests](https://github.com/h5rdly/webtoken/tree/main/tests).
77100

78101
## Crypto
79102

80-
Toke is backed by [jsonwebtoken](https://github.com/Keats/jsonwebtoken) and [aws-lc-rs](https://github.com/aws/aws-lc-rs).
103+
The crypto backend used by webtoken is [aws-lc-rs](https://github.com/aws/aws-lc-rs).
81104

82105

83106
### Supported algorithms
84107

85-
Via jsonwebtoken -
108+
PyJWT compat -
86109
- HS256
87110
- HS384
88111
- HS512
89112
- RS256
90113
- RS384
91-
- RS512
92-
93-
Via aws-lc-rs -
114+
- RS512-
94115
- ES512
116+
117+
Also -
95118
- ES256K
96119
- ML-DSA-65
97120

98-
## Fun Facts
99-
100-
- Using the Rust Crypto backend with jsonwebtoken made the binary around ~1Mb on linux. However, RSA decoding was slower than using PyJWT. Thus, we switched to aws-lc-rs.

tests/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Tests
22

3-
The major [PyJWT test suites](https://github.com/jpadilla/pyjwt/blob/master/tests/test_api_jwk.py) were ported -
3+
The major [PyJWT test suites](https://github.com/jpadilla/pyjwt/tree/master/tests) were ported -
44
- test_api_jwt.py
55
- test_api_jws.py
66
- test_api_jwk.py

0 commit comments

Comments
 (0)