pysigned 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pysigned-0.1.0/LICENSE +21 -0
- pysigned-0.1.0/PKG-INFO +164 -0
- pysigned-0.1.0/README.md +139 -0
- pysigned-0.1.0/THIRD-PARTY-LICENSES +407 -0
- pysigned-0.1.0/pyproject.toml +66 -0
- pysigned-0.1.0/src/pysigned/__init__.py +23 -0
- pysigned-0.1.0/src/pysigned/backends.py +133 -0
- pysigned-0.1.0/src/pysigned/keys.py +150 -0
- pysigned-0.1.0/src/pysigned/py.typed +0 -0
- pysigned-0.1.0/src/pysigned/signature.py +141 -0
pysigned-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Meg Hicks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pysigned-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pysigned
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sign and verify URLs with an expiry, using HMAC or Ed25519
|
|
5
|
+
Author: Meg Hicks
|
|
6
|
+
Author-email: Meg Hicks <meg.d.hicks@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: THIRD-PARTY-LICENSES
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
19
|
+
Classifier: Topic :: Security :: Cryptography
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Dist: cryptography>=40 ; extra == 'ed25519'
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Provides-Extra: ed25519
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# pysigned
|
|
27
|
+
|
|
28
|
+
Sign and verify URLs with an expiry. `pysigned` appends a tamper-proof
|
|
29
|
+
signature (`sig`) and an expiry (`exp`) to a URL's query string, so you can hand
|
|
30
|
+
out time-limited links — download links, password resets, webhook callbacks —
|
|
31
|
+
that can't be altered without invalidating the signature.
|
|
32
|
+
|
|
33
|
+
📖 **[Documentation](https://meg-codes.github.io/pysigned/)**
|
|
34
|
+
|
|
35
|
+
- **Two backends.** HMAC (symmetric) by default, or Ed25519 (asymmetric) when
|
|
36
|
+
the signer and verifier shouldn't share a secret.
|
|
37
|
+
- **Key rotation.** Configure several keys; signing uses one, verification
|
|
38
|
+
accepts any of them, so you can roll keys without breaking links in flight.
|
|
39
|
+
- **Canonical signing.** The query string is normalised before signing, so the
|
|
40
|
+
signature survives re-encoding and reordering of unrelated parameters.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
Requires Python 3.13+.
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
uv add pysigned
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
pip install pysigned
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The HMAC backend uses only the standard library. The Ed25519 backend depends on
|
|
55
|
+
[`cryptography`](https://pypi.org/project/cryptography/), which is an optional
|
|
56
|
+
extra — install it when you need asymmetric signing:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
uv add 'pysigned[ed25519]'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
pip install 'pysigned[ed25519]'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
### HMAC (symmetric)
|
|
69
|
+
|
|
70
|
+
The same secret signs and verifies. Use this when a single trusted service does
|
|
71
|
+
both. Keys must be at least 64 bytes (the SHA-512 digest size).
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import secrets
|
|
75
|
+
from pysigned import URLAuth
|
|
76
|
+
|
|
77
|
+
# A raw 64-byte secret is wrapped in an HMAC keyset automatically.
|
|
78
|
+
signer = URLAuth([secrets.token_bytes(64)], ttl=60)
|
|
79
|
+
|
|
80
|
+
signed = signer.sign("https://example.com/report?id=42&fmt=pdf")
|
|
81
|
+
# https://example.com/report?id=42&fmt=pdf&sig=...&exp=...
|
|
82
|
+
|
|
83
|
+
signer.verify(signed) # True
|
|
84
|
+
signer.verify(signed.replace("id=42", "id=99")) # False — tampered
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`ttl` is the number of seconds a signature stays valid (default: 10 minutes).
|
|
88
|
+
Once `exp` passes, `verify` returns `False`.
|
|
89
|
+
|
|
90
|
+
### Key rotation
|
|
91
|
+
|
|
92
|
+
Pass `(key_bytes, id)` tuples to give keys stable ids. The most recently added
|
|
93
|
+
key signs by default; every configured key is accepted on verify, so signatures
|
|
94
|
+
made with a rotated-out key keep working until they expire.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import secrets
|
|
98
|
+
from pysigned import HMACKeySet, URLAuth
|
|
99
|
+
|
|
100
|
+
keys = HMACKeySet([
|
|
101
|
+
(secrets.token_bytes(64), "k-2024"), # old key, still trusted for verify
|
|
102
|
+
(secrets.token_bytes(64), "k-2025"), # newest -> used for signing
|
|
103
|
+
])
|
|
104
|
+
signer = URLAuth(keys, ttl=60)
|
|
105
|
+
|
|
106
|
+
# Sign with a specific key instead of the default:
|
|
107
|
+
signer = URLAuth(keys, signing_key_id="k-2024")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Ed25519 (asymmetric)
|
|
111
|
+
|
|
112
|
+
A private key signs; a public key only verifies. Use this when you sign in one
|
|
113
|
+
place and verify somewhere less trusted — the verifier can't forge new
|
|
114
|
+
signatures.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from pysigned import Ed25519KeySet, Ed25519PrivateKey, Ed25519PublicKey, URLAuth
|
|
118
|
+
|
|
119
|
+
# Signing side holds the private key.
|
|
120
|
+
private = Ed25519PrivateKey.generate("ed-2025")
|
|
121
|
+
signer = URLAuth(Ed25519KeySet([private]), ttl=60)
|
|
122
|
+
signed = signer.sign("https://example.com/download?file=archive.zip")
|
|
123
|
+
|
|
124
|
+
# Verifying side only needs the public key. It shares the private key's id.
|
|
125
|
+
public = Ed25519PublicKey.from_public_bytes(private.public_bytes(), private.id)
|
|
126
|
+
verifier = URLAuth(Ed25519KeySet([public]))
|
|
127
|
+
|
|
128
|
+
verifier.verify(signed) # True
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Ignoring query parameters
|
|
132
|
+
|
|
133
|
+
Parameters you don't want to be part of the signature (for example a tracking
|
|
134
|
+
token added downstream) can be excluded:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
signer = URLAuth(keys, ignore_query_params=["utm_source"])
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Clock skew
|
|
141
|
+
|
|
142
|
+
Allow a grace period past expiry to tolerate clock differences between signer
|
|
143
|
+
and verifier:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
signer.verify(signed, skew=30) # accept up to 30s past exp
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Examples
|
|
150
|
+
|
|
151
|
+
A runnable demo of both backends lives in [examples/sign_urls.py](examples/sign_urls.py):
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
uv run python examples/sign_urls.py # requires ed25519 support
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## How it works
|
|
158
|
+
|
|
159
|
+
`URLAuth.sign` builds a canonical byte string from the URL's scheme, host, path,
|
|
160
|
+
and query (with `sig`/`exp` and any ignored params removed), appends the expiry,
|
|
161
|
+
and signs it with the configured backend. Components are joined with newlines —
|
|
162
|
+
a byte that can't appear in a URL component — so field boundaries can never be
|
|
163
|
+
confused. `verify` rebuilds the same message and checks the signature against
|
|
164
|
+
every configured key in constant time.
|
pysigned-0.1.0/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# pysigned
|
|
2
|
+
|
|
3
|
+
Sign and verify URLs with an expiry. `pysigned` appends a tamper-proof
|
|
4
|
+
signature (`sig`) and an expiry (`exp`) to a URL's query string, so you can hand
|
|
5
|
+
out time-limited links — download links, password resets, webhook callbacks —
|
|
6
|
+
that can't be altered without invalidating the signature.
|
|
7
|
+
|
|
8
|
+
📖 **[Documentation](https://meg-codes.github.io/pysigned/)**
|
|
9
|
+
|
|
10
|
+
- **Two backends.** HMAC (symmetric) by default, or Ed25519 (asymmetric) when
|
|
11
|
+
the signer and verifier shouldn't share a secret.
|
|
12
|
+
- **Key rotation.** Configure several keys; signing uses one, verification
|
|
13
|
+
accepts any of them, so you can roll keys without breaking links in flight.
|
|
14
|
+
- **Canonical signing.** The query string is normalised before signing, so the
|
|
15
|
+
signature survives re-encoding and reordering of unrelated parameters.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Requires Python 3.13+.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
uv add pysigned
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
pip install pysigned
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The HMAC backend uses only the standard library. The Ed25519 backend depends on
|
|
30
|
+
[`cryptography`](https://pypi.org/project/cryptography/), which is an optional
|
|
31
|
+
extra — install it when you need asymmetric signing:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
uv add 'pysigned[ed25519]'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
pip install 'pysigned[ed25519]'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### HMAC (symmetric)
|
|
44
|
+
|
|
45
|
+
The same secret signs and verifies. Use this when a single trusted service does
|
|
46
|
+
both. Keys must be at least 64 bytes (the SHA-512 digest size).
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import secrets
|
|
50
|
+
from pysigned import URLAuth
|
|
51
|
+
|
|
52
|
+
# A raw 64-byte secret is wrapped in an HMAC keyset automatically.
|
|
53
|
+
signer = URLAuth([secrets.token_bytes(64)], ttl=60)
|
|
54
|
+
|
|
55
|
+
signed = signer.sign("https://example.com/report?id=42&fmt=pdf")
|
|
56
|
+
# https://example.com/report?id=42&fmt=pdf&sig=...&exp=...
|
|
57
|
+
|
|
58
|
+
signer.verify(signed) # True
|
|
59
|
+
signer.verify(signed.replace("id=42", "id=99")) # False — tampered
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`ttl` is the number of seconds a signature stays valid (default: 10 minutes).
|
|
63
|
+
Once `exp` passes, `verify` returns `False`.
|
|
64
|
+
|
|
65
|
+
### Key rotation
|
|
66
|
+
|
|
67
|
+
Pass `(key_bytes, id)` tuples to give keys stable ids. The most recently added
|
|
68
|
+
key signs by default; every configured key is accepted on verify, so signatures
|
|
69
|
+
made with a rotated-out key keep working until they expire.
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import secrets
|
|
73
|
+
from pysigned import HMACKeySet, URLAuth
|
|
74
|
+
|
|
75
|
+
keys = HMACKeySet([
|
|
76
|
+
(secrets.token_bytes(64), "k-2024"), # old key, still trusted for verify
|
|
77
|
+
(secrets.token_bytes(64), "k-2025"), # newest -> used for signing
|
|
78
|
+
])
|
|
79
|
+
signer = URLAuth(keys, ttl=60)
|
|
80
|
+
|
|
81
|
+
# Sign with a specific key instead of the default:
|
|
82
|
+
signer = URLAuth(keys, signing_key_id="k-2024")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Ed25519 (asymmetric)
|
|
86
|
+
|
|
87
|
+
A private key signs; a public key only verifies. Use this when you sign in one
|
|
88
|
+
place and verify somewhere less trusted — the verifier can't forge new
|
|
89
|
+
signatures.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from pysigned import Ed25519KeySet, Ed25519PrivateKey, Ed25519PublicKey, URLAuth
|
|
93
|
+
|
|
94
|
+
# Signing side holds the private key.
|
|
95
|
+
private = Ed25519PrivateKey.generate("ed-2025")
|
|
96
|
+
signer = URLAuth(Ed25519KeySet([private]), ttl=60)
|
|
97
|
+
signed = signer.sign("https://example.com/download?file=archive.zip")
|
|
98
|
+
|
|
99
|
+
# Verifying side only needs the public key. It shares the private key's id.
|
|
100
|
+
public = Ed25519PublicKey.from_public_bytes(private.public_bytes(), private.id)
|
|
101
|
+
verifier = URLAuth(Ed25519KeySet([public]))
|
|
102
|
+
|
|
103
|
+
verifier.verify(signed) # True
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Ignoring query parameters
|
|
107
|
+
|
|
108
|
+
Parameters you don't want to be part of the signature (for example a tracking
|
|
109
|
+
token added downstream) can be excluded:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
signer = URLAuth(keys, ignore_query_params=["utm_source"])
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Clock skew
|
|
116
|
+
|
|
117
|
+
Allow a grace period past expiry to tolerate clock differences between signer
|
|
118
|
+
and verifier:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
signer.verify(signed, skew=30) # accept up to 30s past exp
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Examples
|
|
125
|
+
|
|
126
|
+
A runnable demo of both backends lives in [examples/sign_urls.py](examples/sign_urls.py):
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
uv run python examples/sign_urls.py # requires ed25519 support
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## How it works
|
|
133
|
+
|
|
134
|
+
`URLAuth.sign` builds a canonical byte string from the URL's scheme, host, path,
|
|
135
|
+
and query (with `sig`/`exp` and any ignored params removed), appends the expiry,
|
|
136
|
+
and signs it with the configured backend. Components are joined with newlines —
|
|
137
|
+
a byte that can't appear in a URL component — so field boundaries can never be
|
|
138
|
+
confused. `verify` rebuilds the same message and checks the signature against
|
|
139
|
+
every configured key in constant time.
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
Pygments
|
|
2
|
+
2.20.0
|
|
3
|
+
BSD-2-Clause
|
|
4
|
+
Copyright (c) 2006-2022 by the respective authors (see AUTHORS file).
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions are
|
|
9
|
+
met:
|
|
10
|
+
|
|
11
|
+
* Redistributions of source code must retain the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer.
|
|
13
|
+
|
|
14
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer in the
|
|
16
|
+
documentation and/or other materials provided with the distribution.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
19
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
20
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
21
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
22
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
23
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
24
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
25
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
26
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
anyio
|
|
32
|
+
4.14.0
|
|
33
|
+
MIT
|
|
34
|
+
The MIT License (MIT)
|
|
35
|
+
|
|
36
|
+
Copyright (c) 2018 Alex Grönholm
|
|
37
|
+
|
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
39
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
40
|
+
the Software without restriction, including without limitation the rights to
|
|
41
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
42
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
43
|
+
subject to the following conditions:
|
|
44
|
+
|
|
45
|
+
The above copyright notice and this permission notice shall be included in all
|
|
46
|
+
copies or substantial portions of the Software.
|
|
47
|
+
|
|
48
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
49
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
50
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
51
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
52
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
53
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
cffi
|
|
57
|
+
2.0.0
|
|
58
|
+
MIT
|
|
59
|
+
|
|
60
|
+
Except when otherwise stated (look for LICENSE files in directories or
|
|
61
|
+
information at the beginning of each file) all software and
|
|
62
|
+
documentation is licensed as follows:
|
|
63
|
+
|
|
64
|
+
MIT No Attribution
|
|
65
|
+
|
|
66
|
+
Permission is hereby granted, free of charge, to any person
|
|
67
|
+
obtaining a copy of this software and associated documentation
|
|
68
|
+
files (the "Software"), to deal in the Software without
|
|
69
|
+
restriction, including without limitation the rights to use,
|
|
70
|
+
copy, modify, merge, publish, distribute, sublicense, and/or
|
|
71
|
+
sell copies of the Software, and to permit persons to whom the
|
|
72
|
+
Software is furnished to do so.
|
|
73
|
+
|
|
74
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
75
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
76
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
77
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
78
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
79
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
80
|
+
DEALINGS IN THE SOFTWARE.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
coverage
|
|
85
|
+
7.14.1
|
|
86
|
+
Apache-2.0
|
|
87
|
+
|
|
88
|
+
Apache License
|
|
89
|
+
Version 2.0, January 2004
|
|
90
|
+
http://www.apache.org/licenses/
|
|
91
|
+
|
|
92
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
93
|
+
|
|
94
|
+
1. Definitions.
|
|
95
|
+
|
|
96
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
97
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
98
|
+
|
|
99
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
100
|
+
the copyright owner that is granting the License.
|
|
101
|
+
|
|
102
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
103
|
+
other entities that control, are controlled by, or are under common
|
|
104
|
+
control with that entity. For the purposes of this definition,
|
|
105
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
106
|
+
direction or management of such entity, whether by contract or
|
|
107
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
108
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
109
|
+
|
|
110
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
111
|
+
exercising permissions granted by this License.
|
|
112
|
+
|
|
113
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
114
|
+
including but not limited to software source code, documentation
|
|
115
|
+
source, and configuration files.
|
|
116
|
+
|
|
117
|
+
"Object" form shall mean any form resulting from mechanical
|
|
118
|
+
transformation or translation of a Source form, including but
|
|
119
|
+
not limited to compiled object code, generated documentation,
|
|
120
|
+
and conversions to other media types.
|
|
121
|
+
|
|
122
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
123
|
+
Object form, made available under the License, as indicated by a
|
|
124
|
+
copyright notice that is included in or attached to the work
|
|
125
|
+
(an example is provided in the Appendix below).
|
|
126
|
+
|
|
127
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
128
|
+
form, that is based on (or derived from) the Work and for which the
|
|
129
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
130
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
131
|
+
of this License, Derivative Works shall not include works that remain
|
|
132
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
133
|
+
the Work and Derivative Works thereof.
|
|
134
|
+
|
|
135
|
+
"Contribution" shall mean any work of authorship, including
|
|
136
|
+
the original version of the Work and any modifications or additions
|
|
137
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
138
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
139
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
140
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
141
|
+
means any form of electronic, verbal, or written communication sent
|
|
142
|
+
to the Licensor or its representatives, including but not limited to
|
|
143
|
+
communication on electronic mailing lists, source code control systems,
|
|
144
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
145
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
146
|
+
excluding communication that is conspicuously marked or otherwise
|
|
147
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
148
|
+
|
|
149
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
150
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
151
|
+
subsequently incorporated within the Work.
|
|
152
|
+
|
|
153
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
154
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
155
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
156
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
157
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
158
|
+
Work and such Derivative Works in Source or Object form.
|
|
159
|
+
|
|
160
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
161
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
162
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
163
|
+
(except as stated in this section) patent license to make, have made,
|
|
164
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
165
|
+
where such license applies only to those patent claims licensable
|
|
166
|
+
by such Contributor that are necessarily infringed by their
|
|
167
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
168
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
169
|
+
institute patent litigation against any entity (including a
|
|
170
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
171
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
172
|
+
or contributory patent infringement, then any patent licenses
|
|
173
|
+
granted to You under this License for that Work shall terminate
|
|
174
|
+
as of the date such litigation is filed.
|
|
175
|
+
|
|
176
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
177
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
178
|
+
modifications, and in Source or Object form, provided that You
|
|
179
|
+
meet the following conditions:
|
|
180
|
+
|
|
181
|
+
(a) You must give any other recipients of the Work or
|
|
182
|
+
Derivative Works a copy of this License; and
|
|
183
|
+
|
|
184
|
+
(b) You must cause any modified files to carry prominent notices
|
|
185
|
+
stating that You changed the files; and
|
|
186
|
+
|
|
187
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
188
|
+
that You distribute, all copyright, patent, trademark, and
|
|
189
|
+
attribution notices from the Source form of the Work,
|
|
190
|
+
excluding those notices that do not pertain to any part of
|
|
191
|
+
the Derivative Works; and
|
|
192
|
+
|
|
193
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
194
|
+
distribution, then any Derivative Works that You distribute must
|
|
195
|
+
include a readable copy of the attribution notices contained
|
|
196
|
+
within such NOTICE file, excluding those notices that do not
|
|
197
|
+
pertain to any part of the Derivative Works, in at least one
|
|
198
|
+
of the following places: within a NOTICE text file distributed
|
|
199
|
+
as part of the Derivative Works; within the Source form or
|
|
200
|
+
documentation, if provided along with the Derivative Works; or,
|
|
201
|
+
within a display generated by the Derivative Works, if and
|
|
202
|
+
wherever such third-party notices normally appear. The contents
|
|
203
|
+
of the NOTICE file are for informational purposes only and
|
|
204
|
+
do not modify the License. You may add Your own attribution
|
|
205
|
+
notices within Derivative Works that You distribute, alongside
|
|
206
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
207
|
+
that such additional attribution notices cannot be construed
|
|
208
|
+
as modifying the License.
|
|
209
|
+
|
|
210
|
+
You may add Your own copyright statement to Your modifications and
|
|
211
|
+
may provide additional or different license terms and conditions
|
|
212
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
213
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
214
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
215
|
+
the conditions stated in this License.
|
|
216
|
+
|
|
217
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
218
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
219
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
220
|
+
this License, without any additional terms or conditions.
|
|
221
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
222
|
+
the terms of any separate license agreement you may have executed
|
|
223
|
+
with Licensor regarding such Contributions.
|
|
224
|
+
|
|
225
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
226
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
227
|
+
except as required for reasonable and customary use in describing the
|
|
228
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
229
|
+
|
|
230
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
231
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
232
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
233
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
234
|
+
implied, including, without limitation, any warranties or conditions
|
|
235
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
236
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
237
|
+
appropriateness of using or redistributing the Work and assume any
|
|
238
|
+
risks associated with Your exercise of permissions under this License.
|
|
239
|
+
|
|
240
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
241
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
242
|
+
unless required by applicable law (such as deliberate and grossly
|
|
243
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
244
|
+
liable to You for damages, including any direct, indirect, special,
|
|
245
|
+
incidental, or consequential damages of any character arising as a
|
|
246
|
+
result of this License or out of the use or inability to use the
|
|
247
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
248
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
249
|
+
other commercial damages or losses), even if such Contributor
|
|
250
|
+
has been advised of the possibility of such damages.
|
|
251
|
+
|
|
252
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
253
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
254
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
255
|
+
or other liability obligations and/or rights consistent with this
|
|
256
|
+
License. However, in accepting such obligations, You may act only
|
|
257
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
258
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
259
|
+
defend, and hold each Contributor harmless for any liability
|
|
260
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
261
|
+
of your accepting any such warranty or additional liability.
|
|
262
|
+
|
|
263
|
+
END OF TERMS AND CONDITIONS
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
cryptography
|
|
267
|
+
49.0.0
|
|
268
|
+
Apache-2.0 OR BSD-3-Clause
|
|
269
|
+
This software is made available under the terms of *either* of the licenses
|
|
270
|
+
found in LICENSE.APACHE or LICENSE.BSD. Contributions to cryptography are made
|
|
271
|
+
under the terms of *both* these licenses.
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
idna
|
|
275
|
+
3.18
|
|
276
|
+
BSD-3-Clause
|
|
277
|
+
BSD 3-Clause License
|
|
278
|
+
|
|
279
|
+
Copyright (c) 2013-2026, Kim Davies and contributors.
|
|
280
|
+
All rights reserved.
|
|
281
|
+
|
|
282
|
+
Redistribution and use in source and binary forms, with or without
|
|
283
|
+
modification, are permitted provided that the following conditions are
|
|
284
|
+
met:
|
|
285
|
+
|
|
286
|
+
1. Redistributions of source code must retain the above copyright
|
|
287
|
+
notice, this list of conditions and the following disclaimer.
|
|
288
|
+
|
|
289
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
290
|
+
notice, this list of conditions and the following disclaimer in the
|
|
291
|
+
documentation and/or other materials provided with the distribution.
|
|
292
|
+
|
|
293
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
294
|
+
contributors may be used to endorse or promote products derived from
|
|
295
|
+
this software without specific prior written permission.
|
|
296
|
+
|
|
297
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
298
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
299
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
300
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
301
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
302
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
303
|
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
304
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
305
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
306
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
307
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
iniconfig
|
|
311
|
+
2.3.0
|
|
312
|
+
MIT
|
|
313
|
+
The MIT License (MIT)
|
|
314
|
+
|
|
315
|
+
Copyright (c) 2010 - 2023 Holger Krekel and others
|
|
316
|
+
|
|
317
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
318
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
319
|
+
the Software without restriction, including without limitation the rights to
|
|
320
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
321
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
322
|
+
so, subject to the following conditions:
|
|
323
|
+
|
|
324
|
+
The above copyright notice and this permission notice shall be included in all
|
|
325
|
+
copies or substantial portions of the Software.
|
|
326
|
+
|
|
327
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
328
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
329
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
330
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
331
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
332
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
333
|
+
SOFTWARE.
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
packaging
|
|
337
|
+
26.2
|
|
338
|
+
Apache-2.0 OR BSD-2-Clause
|
|
339
|
+
This software is made available under the terms of *either* of the licenses
|
|
340
|
+
found in LICENSE.APACHE or LICENSE.BSD. Contributions to this software is made
|
|
341
|
+
under the terms of *both* these licenses.
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
pluggy
|
|
345
|
+
1.6.0
|
|
346
|
+
MIT License
|
|
347
|
+
The MIT License (MIT)
|
|
348
|
+
|
|
349
|
+
Copyright (c) 2015 holger krekel (rather uses bitbucket/hpk42)
|
|
350
|
+
|
|
351
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
352
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
353
|
+
in the Software without restriction, including without limitation the rights
|
|
354
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
355
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
356
|
+
furnished to do so, subject to the following conditions:
|
|
357
|
+
|
|
358
|
+
The above copyright notice and this permission notice shall be included in all
|
|
359
|
+
copies or substantial portions of the Software.
|
|
360
|
+
|
|
361
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
362
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
363
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
364
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
365
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
366
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
367
|
+
SOFTWARE.
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
pycparser
|
|
371
|
+
3.0
|
|
372
|
+
BSD-3-Clause
|
|
373
|
+
pycparser -- A C parser in Python
|
|
374
|
+
|
|
375
|
+
Copyright (c) 2008-2022, Eli Bendersky
|
|
376
|
+
All rights reserved.
|
|
377
|
+
|
|
378
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
379
|
+
are permitted provided that the following conditions are met:
|
|
380
|
+
|
|
381
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
382
|
+
list of conditions and the following disclaimer.
|
|
383
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
384
|
+
this list of conditions and the following disclaimer in the documentation
|
|
385
|
+
and/or other materials provided with the distribution.
|
|
386
|
+
* Neither the name of the copyright holder nor the names of its contributors may
|
|
387
|
+
be used to endorse or promote products derived from this software without
|
|
388
|
+
specific prior written permission.
|
|
389
|
+
|
|
390
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
391
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
392
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
393
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
394
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
395
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
396
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
397
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
398
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
399
|
+
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
pysigned
|
|
403
|
+
0.1.0
|
|
404
|
+
MIT
|
|
405
|
+
UNKNOWN
|
|
406
|
+
|
|
407
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pysigned"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Sign and verify URLs with an expiry, using HMAC or Ed25519"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Meg Hicks", email = "meg.d.hicks@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE", "THIRD-PARTY-LICENSES"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
22
|
+
"Topic :: Security :: Cryptography",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = []
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
# Ed25519 signing/verifying. The HMAC backend needs nothing beyond the stdlib.
|
|
29
|
+
ed25519 = [
|
|
30
|
+
"cryptography>=40",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["uv_build>=0.9.18,<0.10.0"]
|
|
35
|
+
build-backend = "uv_build"
|
|
36
|
+
|
|
37
|
+
[dependency-groups]
|
|
38
|
+
dev = [
|
|
39
|
+
"pysigned[ed25519]",
|
|
40
|
+
"pip-licenses>=5.5.5",
|
|
41
|
+
"pytest>=9.1.0",
|
|
42
|
+
"pytest-cov>=7.1.0",
|
|
43
|
+
"mkdocs-material>=9.5.0",
|
|
44
|
+
"mkdocstrings[python]>=0.27.0",
|
|
45
|
+
"ruff>=0.15.17",
|
|
46
|
+
"ty>=0.0.49",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
testpaths = ["tests"]
|
|
52
|
+
addopts = "--cov=pysigned --cov-report=term-missing"
|
|
53
|
+
|
|
54
|
+
[tool.ty.src]
|
|
55
|
+
include = ["src"]
|
|
56
|
+
|
|
57
|
+
[tool.pip-licenses]
|
|
58
|
+
ignore-packages = [
|
|
59
|
+
"pip-licenses",
|
|
60
|
+
"pytest",
|
|
61
|
+
"pytest-cov",
|
|
62
|
+
"mkdocs-material",
|
|
63
|
+
"mkdocstrings[python]",
|
|
64
|
+
"ruff",
|
|
65
|
+
"ty"
|
|
66
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from .backends import (
|
|
2
|
+
Ed25519Backend,
|
|
3
|
+
Ed25519KeySet,
|
|
4
|
+
HMACKeySet,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
from .keys import (
|
|
8
|
+
Ed25519PrivateKey,
|
|
9
|
+
Ed25519PublicKey,
|
|
10
|
+
HMACKey,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from .signature import URLAuth
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"Ed25519Backend",
|
|
17
|
+
"Ed25519KeySet",
|
|
18
|
+
"Ed25519PrivateKey",
|
|
19
|
+
"Ed25519PublicKey",
|
|
20
|
+
"HMACKey",
|
|
21
|
+
"HMACKeySet",
|
|
22
|
+
"URLAuth",
|
|
23
|
+
]
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import hmac
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from collections.abc import Iterable, Mapping
|
|
4
|
+
from types import MappingProxyType
|
|
5
|
+
from typing import Generic, TypeVar
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
from .keys import (
|
|
9
|
+
DIGEST,
|
|
10
|
+
Ed25519PrivateKey,
|
|
11
|
+
Ed25519PublicKey,
|
|
12
|
+
HMACKey,
|
|
13
|
+
Key,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
K = TypeVar("K", bound=Key)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Backend(ABC, Generic[K]):
|
|
21
|
+
"""Algorithm-specific key parsing and signing/verifying.
|
|
22
|
+
|
|
23
|
+
A backend turns user-supplied key values into :class:`~pysigned.keys.Key`
|
|
24
|
+
instances and knows how to sign a message and verify a signature with one.
|
|
25
|
+
Everything algorithm-agnostic (URL canonicalisation, expiry, key rotation)
|
|
26
|
+
lives in :class:`~pysigned.signature.URLAuth`.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
@abstractmethod
|
|
30
|
+
def parse_key(self, value) -> K: ...
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def sign(self, key: K, message: bytes) -> str: ...
|
|
34
|
+
|
|
35
|
+
@abstractmethod
|
|
36
|
+
def verify(self, key: K, message: bytes, signature: str) -> bool: ...
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
HMACKeySetValue = tuple[bytes, str] | bytes | HMACKey
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class HMACBackend(Backend[HMACKey]):
|
|
43
|
+
def __init__(self, digest: str = DIGEST):
|
|
44
|
+
self.digest = digest
|
|
45
|
+
|
|
46
|
+
def parse_key(self, value: HMACKeySetValue) -> HMACKey:
|
|
47
|
+
match value:
|
|
48
|
+
case bytes():
|
|
49
|
+
return HMACKey(value)
|
|
50
|
+
case HMACKey():
|
|
51
|
+
return value
|
|
52
|
+
case (_bytes, _id):
|
|
53
|
+
if not isinstance(_bytes, bytes):
|
|
54
|
+
raise ValueError("Keys in tuples must be bytes")
|
|
55
|
+
if not isinstance(_id, str):
|
|
56
|
+
raise ValueError("Key ids must be strings.")
|
|
57
|
+
return HMACKey(_bytes, _id)
|
|
58
|
+
case _:
|
|
59
|
+
raise ValueError(f"Invalid key value: {value}")
|
|
60
|
+
|
|
61
|
+
def sign(self, key: HMACKey, message: bytes) -> str:
|
|
62
|
+
return hmac.new(bytes(key), message, self.digest).hexdigest()
|
|
63
|
+
|
|
64
|
+
def verify(self, key: HMACKey, message: bytes, signature: str) -> bool:
|
|
65
|
+
expected = self.sign(key, message)
|
|
66
|
+
# Constant-time comparison to avoid timing attacks.
|
|
67
|
+
return hmac.compare_digest(expected, signature)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class Ed25519Backend(Backend[Key]):
|
|
71
|
+
def parse_key(self, value) -> Key:
|
|
72
|
+
if isinstance(value, (Ed25519PrivateKey, Ed25519PublicKey)):
|
|
73
|
+
return value
|
|
74
|
+
raise ValueError(
|
|
75
|
+
"Ed25519 keys must be wrapped as Ed25519PrivateKey or "
|
|
76
|
+
"Ed25519PublicKey; raw bytes are ambiguous (private vs public)."
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def sign(self, key: Key, message: bytes) -> str:
|
|
80
|
+
if not isinstance(key, Ed25519PrivateKey):
|
|
81
|
+
raise TypeError(
|
|
82
|
+
"signing requires an Ed25519PrivateKey; "
|
|
83
|
+
f"got {type(key).__name__} (public keys cannot sign)"
|
|
84
|
+
)
|
|
85
|
+
return key._crypto_key().sign(message).hex()
|
|
86
|
+
|
|
87
|
+
def verify(self, key: Key, message: bytes, signature: str) -> bool:
|
|
88
|
+
if isinstance(key, Ed25519PrivateKey):
|
|
89
|
+
public = key._crypto_key().public_key()
|
|
90
|
+
elif isinstance(key, Ed25519PublicKey):
|
|
91
|
+
public = key._crypto_key()
|
|
92
|
+
else:
|
|
93
|
+
return False
|
|
94
|
+
|
|
95
|
+
from cryptography.exceptions import InvalidSignature
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
public.verify(bytes.fromhex(signature), message)
|
|
99
|
+
except (InvalidSignature, ValueError):
|
|
100
|
+
return False
|
|
101
|
+
return True
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class KeySet:
|
|
105
|
+
"""An id-keyed, read-only collection of keys parsed by a backend."""
|
|
106
|
+
|
|
107
|
+
def __init__(self, keys: Iterable, backend: Backend):
|
|
108
|
+
self.backend = backend
|
|
109
|
+
self._keys: Mapping[str, Key] = MappingProxyType(
|
|
110
|
+
{k.id: k for k in map(backend.parse_key, keys)}
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def __getitem__(self, key: str):
|
|
114
|
+
return self._keys[key]
|
|
115
|
+
|
|
116
|
+
def __iter__(self):
|
|
117
|
+
return iter(self._keys.values())
|
|
118
|
+
|
|
119
|
+
def __reversed__(self):
|
|
120
|
+
return reversed(list(self._keys.values()))
|
|
121
|
+
|
|
122
|
+
def __len__(self):
|
|
123
|
+
return len(self._keys)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class HMACKeySet(KeySet):
|
|
127
|
+
def __init__(self, keys: Iterable, backend: HMACBackend | None = None):
|
|
128
|
+
super().__init__(keys, backend or HMACBackend())
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class Ed25519KeySet(KeySet):
|
|
132
|
+
def __init__(self, keys: Iterable, backend: Ed25519Backend | None = None):
|
|
133
|
+
super().__init__(keys, backend or Ed25519Backend())
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from cryptography.hazmat.primitives.asymmetric import ed25519 as _ed25519
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _load_ed25519():
|
|
10
|
+
"""Import cryptography's ed25519 module, with a helpful error if it's missing.
|
|
11
|
+
|
|
12
|
+
``cryptography`` is an optional dependency; only the Ed25519 key types pull
|
|
13
|
+
it in, and only when their signing/verifying machinery is actually used.
|
|
14
|
+
"""
|
|
15
|
+
try:
|
|
16
|
+
from cryptography.hazmat.primitives.asymmetric import ed25519
|
|
17
|
+
except ModuleNotFoundError as exc:
|
|
18
|
+
raise ModuleNotFoundError(
|
|
19
|
+
"Ed25519 support requires the optional 'cryptography' dependency. "
|
|
20
|
+
"Install it with: pip install 'pysigned[ed25519]'"
|
|
21
|
+
) from exc
|
|
22
|
+
return ed25519
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
DIGEST = "sha512"
|
|
26
|
+
# HMAC keys must be at least the digest's output size (NIST SP 800-107).
|
|
27
|
+
MIN_KEY_BYTES = hashlib.new(DIGEST).digest_size
|
|
28
|
+
# Ed25519 seeds and public keys are both fixed at 32 bytes (RFC 8032).
|
|
29
|
+
ED25519_KEY_BYTES = 32
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass(frozen=True, eq=False, repr=False)
|
|
33
|
+
class Key:
|
|
34
|
+
"""A signing/verifying key: raw bytes plus a stable id.
|
|
35
|
+
|
|
36
|
+
Subclasses supply two hooks: ``_validate`` (raise on bad key material) and
|
|
37
|
+
``_id_bytes`` (the bytes the ``id`` fingerprint is hashed from).
|
|
38
|
+
|
|
39
|
+
``_id_bytes`` is **not** "the public part" of the key. It is only what the
|
|
40
|
+
fingerprint is computed over. A symmetric HMAC key has no public counterpart,
|
|
41
|
+
so its ``_id_bytes`` is the *secret* key itself -- safe to hash into an id only
|
|
42
|
+
because SHA-256 is one-way, and safe to show in ``repr`` only because ``repr``
|
|
43
|
+
truncates. An asymmetric Ed25519 key uses its genuinely public bytes.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
key: bytes
|
|
47
|
+
id: str = ""
|
|
48
|
+
|
|
49
|
+
def __post_init__(self):
|
|
50
|
+
self._validate()
|
|
51
|
+
# Own an immutable copy so a mutable bytearray argument can't change
|
|
52
|
+
# underneath the frozen instance.
|
|
53
|
+
object.__setattr__(self, "key", bytes(self.key))
|
|
54
|
+
if not self.id:
|
|
55
|
+
object.__setattr__(self, "id", hashlib.sha512(self._id_bytes()).hexdigest())
|
|
56
|
+
|
|
57
|
+
def _validate(self) -> None:
|
|
58
|
+
raise NotImplementedError
|
|
59
|
+
|
|
60
|
+
def _id_bytes(self) -> bytes:
|
|
61
|
+
raise NotImplementedError
|
|
62
|
+
|
|
63
|
+
def __hash__(self):
|
|
64
|
+
return hash(self.key)
|
|
65
|
+
|
|
66
|
+
def __eq__(self, other: object) -> bool:
|
|
67
|
+
if isinstance(other, Key):
|
|
68
|
+
other = other.key
|
|
69
|
+
return self.key == other
|
|
70
|
+
|
|
71
|
+
def __bytes__(self):
|
|
72
|
+
return self.key
|
|
73
|
+
|
|
74
|
+
def __repr__(self):
|
|
75
|
+
return f"<{type(self).__name__} id={self.id}, bytes={self._id_bytes().hex()[:5]}...>"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class HMACKey(Key):
|
|
79
|
+
"""A symmetric HMAC key."""
|
|
80
|
+
|
|
81
|
+
def _validate(self) -> None:
|
|
82
|
+
if len(self.key) < MIN_KEY_BYTES:
|
|
83
|
+
raise ValueError(
|
|
84
|
+
f"key is {len(self.key)} bytes; "
|
|
85
|
+
f"{DIGEST} requires keys of at least {MIN_KEY_BYTES} bytes"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def _id_bytes(self) -> bytes:
|
|
89
|
+
return self.key
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class Ed25519PrivateKey(Key):
|
|
93
|
+
"""An Ed25519 private key. ``key`` holds the 32-byte raw seed.
|
|
94
|
+
|
|
95
|
+
Can both sign and verify. Its ``id`` is fingerprinted from the derived public
|
|
96
|
+
key, so it matches the id of the corresponding :class:`Ed25519PublicKey`, and
|
|
97
|
+
neither the id nor the repr ever expose the seed.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
@classmethod
|
|
101
|
+
def generate(cls, id: str = "") -> "Ed25519PrivateKey":
|
|
102
|
+
raw = _load_ed25519().Ed25519PrivateKey.generate().private_bytes_raw()
|
|
103
|
+
return cls(raw, id)
|
|
104
|
+
|
|
105
|
+
@classmethod
|
|
106
|
+
def from_private_bytes(cls, seed: bytes, id: str = "") -> "Ed25519PrivateKey":
|
|
107
|
+
return cls(seed, id)
|
|
108
|
+
|
|
109
|
+
def _validate(self) -> None:
|
|
110
|
+
if len(self.key) != ED25519_KEY_BYTES:
|
|
111
|
+
raise ValueError(
|
|
112
|
+
f"Ed25519 private seed must be {ED25519_KEY_BYTES} bytes, "
|
|
113
|
+
f"got {len(self.key)}"
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
def _crypto_key(self) -> "_ed25519.Ed25519PrivateKey":
|
|
117
|
+
return _load_ed25519().Ed25519PrivateKey.from_private_bytes(self.key)
|
|
118
|
+
|
|
119
|
+
def public_bytes(self) -> bytes:
|
|
120
|
+
return self._crypto_key().public_key().public_bytes_raw()
|
|
121
|
+
|
|
122
|
+
def public_key(self) -> "Ed25519PublicKey":
|
|
123
|
+
"""The verify-side key, sharing this key's id."""
|
|
124
|
+
return Ed25519PublicKey(self.public_bytes(), self.id)
|
|
125
|
+
|
|
126
|
+
def _id_bytes(self) -> bytes:
|
|
127
|
+
return self.public_bytes()
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class Ed25519PublicKey(Key):
|
|
131
|
+
"""An Ed25519 public key. ``key`` holds the 32-byte raw public key. Verify only."""
|
|
132
|
+
|
|
133
|
+
@classmethod
|
|
134
|
+
def from_public_bytes(cls, public: bytes, id: str = "") -> "Ed25519PublicKey":
|
|
135
|
+
return cls(public, id)
|
|
136
|
+
|
|
137
|
+
def _validate(self) -> None:
|
|
138
|
+
if len(self.key) != ED25519_KEY_BYTES:
|
|
139
|
+
raise ValueError(
|
|
140
|
+
f"Ed25519 public key must be {ED25519_KEY_BYTES} bytes, "
|
|
141
|
+
f"got {len(self.key)}"
|
|
142
|
+
)
|
|
143
|
+
# Reject points that aren't valid public keys.
|
|
144
|
+
_load_ed25519().Ed25519PublicKey.from_public_bytes(self.key)
|
|
145
|
+
|
|
146
|
+
def _crypto_key(self) -> "_ed25519.Ed25519PublicKey":
|
|
147
|
+
return _load_ed25519().Ed25519PublicKey.from_public_bytes(self.key)
|
|
148
|
+
|
|
149
|
+
def _id_bytes(self) -> bytes:
|
|
150
|
+
return self.key
|
|
File without changes
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from time import time
|
|
3
|
+
from urllib.parse import (
|
|
4
|
+
parse_qsl,
|
|
5
|
+
urlencode,
|
|
6
|
+
urlparse,
|
|
7
|
+
ParseResult,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
from .backends import (
|
|
11
|
+
Backend,
|
|
12
|
+
Ed25519Backend,
|
|
13
|
+
Ed25519KeySet,
|
|
14
|
+
HMACBackend,
|
|
15
|
+
HMACKeySet,
|
|
16
|
+
KeySet,
|
|
17
|
+
)
|
|
18
|
+
from .keys import (
|
|
19
|
+
DIGEST,
|
|
20
|
+
MIN_KEY_BYTES,
|
|
21
|
+
Ed25519PrivateKey,
|
|
22
|
+
Ed25519PublicKey,
|
|
23
|
+
HMACKey,
|
|
24
|
+
Key,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Re-exported for backwards compatibility; importers historically reach for
|
|
28
|
+
# these via ``pysigned.signature``.
|
|
29
|
+
__all__ = [
|
|
30
|
+
"DIGEST",
|
|
31
|
+
"MIN_KEY_BYTES",
|
|
32
|
+
"Backend",
|
|
33
|
+
"Ed25519Backend",
|
|
34
|
+
"Ed25519KeySet",
|
|
35
|
+
"Ed25519PrivateKey",
|
|
36
|
+
"Ed25519PublicKey",
|
|
37
|
+
"HMACBackend",
|
|
38
|
+
"HMACKey",
|
|
39
|
+
"HMACKeySet",
|
|
40
|
+
"Key",
|
|
41
|
+
"KeySet",
|
|
42
|
+
"URLAuth",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class URLAuth:
|
|
47
|
+
"""Sign and verify URLs over the URL and an expiry, via a pluggable backend.
|
|
48
|
+
|
|
49
|
+
A signer is configured with a set of ``keys``. Several keys may be supplied
|
|
50
|
+
so that keys can be rotated without invalidating signatures that are still
|
|
51
|
+
in flight: signing uses one key, but :meth:`verify` accepts any of them.
|
|
52
|
+
|
|
53
|
+
The cryptography is delegated to the keyset's backend (HMAC by default; pass
|
|
54
|
+
an :class:`~pysigned.backends.Ed25519KeySet` for Ed25519). Everything else --
|
|
55
|
+
query canonicalisation, expiry, rotation -- is backend-agnostic.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
keys: A :class:`~pysigned.backends.KeySet`, or raw values that are
|
|
59
|
+
wrapped in an HMAC keyset for backwards compatibility.
|
|
60
|
+
signing_key_id: Id of the key to sign with. Defaults to the most
|
|
61
|
+
recently added key.
|
|
62
|
+
ttl: Seconds a signature stays valid (default 10 minutes).
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
def __init__(
|
|
66
|
+
self,
|
|
67
|
+
keys: KeySet | Iterable,
|
|
68
|
+
*,
|
|
69
|
+
signing_key_id: str = "",
|
|
70
|
+
ignore_query_params: Iterable[str] | None = None,
|
|
71
|
+
ttl: int = 60 * 10,
|
|
72
|
+
) -> None:
|
|
73
|
+
self.keys = keys if isinstance(keys, KeySet) else HMACKeySet(keys)
|
|
74
|
+
self.backend = self.keys.backend
|
|
75
|
+
self.signing_key_id = signing_key_id or next(reversed(self.keys)).id
|
|
76
|
+
# Params excluded from the signed message: our own sig/exp plus any the
|
|
77
|
+
# caller wants ignored. Materialised once so a one-shot iterable works.
|
|
78
|
+
self._excluded = frozenset(("sig", "exp", *(ignore_query_params or ())))
|
|
79
|
+
self.ttl = ttl
|
|
80
|
+
|
|
81
|
+
def sign(self, url: str) -> str:
|
|
82
|
+
"""Sign a URL, returning it with ``sig`` and ``exp`` query params added.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
url: The URL being signed as a string.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
The signed URL as a string.
|
|
89
|
+
"""
|
|
90
|
+
parsed = urlparse(url)
|
|
91
|
+
exp = int(time()) + self.ttl
|
|
92
|
+
signing_key = self.keys[self.signing_key_id]
|
|
93
|
+
signature = self.backend.sign(signing_key, self._message(parsed, exp))
|
|
94
|
+
query = parse_qsl(parsed.query) + [("sig", signature), ("exp", str(exp))]
|
|
95
|
+
return parsed._replace(query=urlencode(query)).geturl()
|
|
96
|
+
|
|
97
|
+
def verify(self, url: str, *, skew: int = 0) -> bool:
|
|
98
|
+
"""Verify a signature produced by :meth:`sign`.
|
|
99
|
+
|
|
100
|
+
Every configured key is checked, so signatures made with a rotated-out
|
|
101
|
+
key still verify.
|
|
102
|
+
"""
|
|
103
|
+
parsed = urlparse(url)
|
|
104
|
+
params = dict(parse_qsl(parsed.query))
|
|
105
|
+
|
|
106
|
+
sig = params.get("sig")
|
|
107
|
+
try:
|
|
108
|
+
exp = int(params.get("exp", ""))
|
|
109
|
+
except ValueError:
|
|
110
|
+
return False
|
|
111
|
+
|
|
112
|
+
if not sig or not exp:
|
|
113
|
+
return False
|
|
114
|
+
if exp + skew <= int(time()):
|
|
115
|
+
return False
|
|
116
|
+
|
|
117
|
+
message = self._message(parsed, exp)
|
|
118
|
+
for key in self.keys:
|
|
119
|
+
if self.backend.verify(key, message, sig):
|
|
120
|
+
return True
|
|
121
|
+
return False
|
|
122
|
+
|
|
123
|
+
def _message(self, parsed: ParseResult, exp: int) -> bytes:
|
|
124
|
+
"""Build a stable, unambiguous byte string from the inputs.
|
|
125
|
+
|
|
126
|
+
The query is normalised (sig/exp dropped, then re-encoded) so that
|
|
127
|
+
sign() and verify() agree regardless of the incoming encoding.
|
|
128
|
+
Components are joined with a newline (a byte that cannot appear in a URL
|
|
129
|
+
component) so that different field boundaries can never collide.
|
|
130
|
+
"""
|
|
131
|
+
pairs = [(k, v) for k, v in parse_qsl(parsed.query) if k not in self._excluded]
|
|
132
|
+
canonical = parsed._replace(query=urlencode(pairs))
|
|
133
|
+
parts = (
|
|
134
|
+
str(exp),
|
|
135
|
+
canonical.scheme,
|
|
136
|
+
canonical.netloc,
|
|
137
|
+
canonical.path,
|
|
138
|
+
canonical.params,
|
|
139
|
+
canonical.query,
|
|
140
|
+
)
|
|
141
|
+
return "\n".join(parts).encode("utf-8")
|