obsigil 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.
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .pytest_cache/
4
+ .venv/
5
+ venv/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ .coverage
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2025 Bojan Đuričković
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bojan Đuričković
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.
obsigil-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,182 @@
1
+ Metadata-Version: 2.4
2
+ Name: obsigil
3
+ Version: 0.1.0
4
+ Summary: Pure-Python implementation of the obsigil mandate-token format (AES-SIV / AES-GCM-SIV)
5
+ Project-URL: Homepage, https://obsigil.org
6
+ Project-URL: Repository, https://gitlab.com/obsigil/obsigil-py
7
+ Author: Bojan Đuričković
8
+ License-Expression: MIT OR Apache-2.0
9
+ License-File: LICENSE-APACHE
10
+ License-File: LICENSE-MIT
11
+ Keywords: aes-gcm-siv,aes-siv,credential,jwt,mandate,obsigil,token
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Security :: Cryptography
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: cbor2>=5.4
25
+ Requires-Dist: cryptography>=42.0
26
+ Provides-Extra: test
27
+ Requires-Dist: pytest>=7; extra == 'test'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # obsigil
31
+
32
+ Homepage: <https://obsigil.org>
33
+
34
+ Pure-Python implementation of **obsigil**, a mandate-token format and
35
+ shared-secret **JWT alternative**: a token split into a public,
36
+ advisory **manifest** and a secret-sealed, authoritative **mandate**.
37
+ Each half is an authenticated, deterministically-sealed ciphertext —
38
+ AES-SIV (RFC 5297) or AES-GCM-SIV (RFC 8452) — in compact text.
39
+
40
+ Each half's fields are a single **canonical CBOR map** (RFC 8949 §4.2):
41
+ reserved fields take negative integer keys (`tid`, `exp`, `aud`, `sub`,
42
+ `iss`), application data takes non-negative integer or text-string keys.
43
+ obsigil owns the canonical encoding, so the same fields under the same
44
+ key seal to byte-identical tokens with no shared serializer.
45
+
46
+ Verification is symmetric: the verifier holds the same key that mints,
47
+ so obsigil fits shared-secret (HS256-style) JWT and JWE use cases, not
48
+ public-key verification.
49
+
50
+ The AEAD primitives come from
51
+ [`cryptography`](https://cryptography.io) (OpenSSL-backed, audited) and
52
+ CBOR decoding from [`cbor2`](https://pypi.org/project/cbor2/); the
53
+ canonical CBOR encoder and the obsigil logic are small, readable Python.
54
+ No compiled extension to build — it installs as a universal wheel and
55
+ you can read the whole format end to end.
56
+
57
+ ```python
58
+ import obsigil
59
+ from obsigil import Obsigil
60
+
61
+ key = obsigil.generate_key() # 64 CSPRNG bytes
62
+
63
+ token = Obsigil.mint(
64
+ clauses={"role": "admin"}, # opaque application data
65
+ mandate_key=key,
66
+ exp=4_000_000_000,
67
+ aud=["api"],
68
+ sub="u42",
69
+ manifest={"iss": "auth.example"}, # optional public half
70
+ )
71
+
72
+ # Front end (advisory — manifest is non-authoritative, §16.7):
73
+ front = Obsigil(token.token())
74
+ claims = front.claims() # dict | None
75
+ header = front.authorization_header() # "Bearer .0…" — send this
76
+
77
+ # Backend (authoritative):
78
+ mandate = Obsigil(token.token(), keys=key, audience="api", now=1)
79
+ role = mandate.clause("role") # raises ObsigilError if invalid
80
+ when = mandate.exp()
81
+ ```
82
+
83
+ ## API
84
+
85
+ A single **`Obsigil`** type views a token in three roles (API
86
+ conformance, §12):
87
+
88
+ - **`Obsigil.mint(*, clauses, mandate_key, exp, tid=None, aud=None,
89
+ sub=None, iss=None, alg="0", encoding="b64", manifest=None)`** — the
90
+ issuer: seal a mandate (and an optional keyless manifest) and return
91
+ the view. `tid` is generated (a fresh UUIDv7) unless supplied; a
92
+ supplied one must be a well-formed UUIDv7. Defaults are AES-SIV
93
+ (`alg="0"`) and base64 (`encoding`; also `"hex"`). Application
94
+ `clauses` use non-negative integer or text keys; reserved fields are
95
+ set via their keyword arguments.
96
+ - **`Obsigil(token, *, keys=None, audience=None, leeway=0, now=None,
97
+ max_decoded_len=65536, on_reject=None)`** — keyless for the front end,
98
+ or with `keys` for the backend. `keys` may be one key or several
99
+ (key selection by trial decryption, §16.5); `leeway` is clamped to a
100
+ fixed maximum (Limits and robustness, §16.10).
101
+
102
+ Each half is reachable at three fidelities (the three fidelities of
103
+ API conformance, §12.2):
104
+
105
+ | | manifest | mandate |
106
+ |---|---|---|
107
+ | wire string | `manifest()` | `mandate()` |
108
+ | plaintext (CBOR octets) | `manifest_plaintext()` | `mandate_plaintext()` |
109
+ | parsed | `claims()` | `clauses()` |
110
+
111
+ - **`clauses()`** authenticates *and* enforces policy (`exp`, `aud`,
112
+ `tid`, types), returning a dict or raising one opaque `ObsigilError`.
113
+ Reserved clauses are surfaced under their names (`tid` as text);
114
+ application fields keep their wire keys. Accessors: `exp()`, `tid()`,
115
+ `issued_at()`, `sub()`, `iss()`, `aud()`, `clause(key)`.
116
+ - **`clauses_unchecked()`** authenticates and decodes the canonical
117
+ CBOR but skips the value checks; **`mandate_plaintext()`**
118
+ authenticates only and returns the raw CBOR octets. Both are
119
+ backend-internal — keep them non-bearer-facing (authentication vs
120
+ policy layers, §16.3).
121
+ - **`claims()`** opens the keyless manifest for display — advisory,
122
+ returns a dict or `None`, never raises (the manifest is
123
+ non-authoritative, §16.7).
124
+ - **`mandate()`** / **`manifest()`** — each half as a standalone token;
125
+ **`authorization_header(scheme="Bearer")`** gives the manifest-absent
126
+ `.0mandate` form to forward to the backend (Audiences, §9).
127
+
128
+ The free functions **`mint`**, **`clauses`**, **`claims`**,
129
+ **`mandate`**, **`manifest`**, **`clauses_unchecked`**,
130
+ **`mandate_plaintext`**, **`manifest_plaintext`**, and
131
+ **`authorization_header`** wrap the same core, plus **`generate_key`**,
132
+ **`generate_uuid7`**, **`is_uuid7`**, **`is_uuid7_bytes`**,
133
+ **`uuid7_time`**, **`MANIFEST_KEY`**, **`ObsigilError`**, **`Reason`**.
134
+ The granular `Reason` is delivered to `on_reject` for **internal logging
135
+ only** — never to the bearer (the uniform-failure rule, §16.6).
136
+
137
+ ## Install
138
+
139
+ ```sh
140
+ pip install obsigil
141
+ ```
142
+
143
+ Requires Python ≥ 3.9. AES-GCM-SIV (algorithm code `1`) needs OpenSSL
144
+ 3.2+, which modern `cryptography` wheels bundle; AES-SIV (code `0`, the
145
+ mandatory default) has no such floor.
146
+
147
+ ## Conformance
148
+
149
+ obsigil implements canonical CBOR (RFC 8949 §4.2) and the validation
150
+ rules of Reserved fields §8 and Limits and robustness §16.10. The
151
+ bundled test suite covers round-trip,
152
+ the verification ladder, and the negative cases (non-canonical CBOR,
153
+ duplicate keys, wrong-typed reserved fields, expiry, audience, size and
154
+ leeway bounds):
155
+
156
+ ```sh
157
+ pip install -e .[test]
158
+ pytest
159
+ ```
160
+
161
+ Cross-language byte-for-byte known-answer vectors are tracked
162
+ separately in the `obsigil-test-vectors` suite, kept in step with the
163
+ canonical-CBOR format.
164
+
165
+ ## License
166
+
167
+ Licensed under either of
168
+
169
+ - Apache License, Version 2.0
170
+ ([LICENSE-APACHE](LICENSE-APACHE) or
171
+ <https://www.apache.org/licenses/LICENSE-2.0>)
172
+ - MIT license ([LICENSE-MIT](LICENSE-MIT) or
173
+ <https://opensource.org/licenses/MIT>)
174
+
175
+ at your option.
176
+
177
+ ### Contribution
178
+
179
+ Unless you explicitly state otherwise, any contribution
180
+ intentionally submitted for inclusion in the work by you, as
181
+ defined in the Apache-2.0 license, shall be dual licensed as
182
+ above, without any additional terms or conditions.
@@ -0,0 +1,153 @@
1
+ # obsigil
2
+
3
+ Homepage: <https://obsigil.org>
4
+
5
+ Pure-Python implementation of **obsigil**, a mandate-token format and
6
+ shared-secret **JWT alternative**: a token split into a public,
7
+ advisory **manifest** and a secret-sealed, authoritative **mandate**.
8
+ Each half is an authenticated, deterministically-sealed ciphertext —
9
+ AES-SIV (RFC 5297) or AES-GCM-SIV (RFC 8452) — in compact text.
10
+
11
+ Each half's fields are a single **canonical CBOR map** (RFC 8949 §4.2):
12
+ reserved fields take negative integer keys (`tid`, `exp`, `aud`, `sub`,
13
+ `iss`), application data takes non-negative integer or text-string keys.
14
+ obsigil owns the canonical encoding, so the same fields under the same
15
+ key seal to byte-identical tokens with no shared serializer.
16
+
17
+ Verification is symmetric: the verifier holds the same key that mints,
18
+ so obsigil fits shared-secret (HS256-style) JWT and JWE use cases, not
19
+ public-key verification.
20
+
21
+ The AEAD primitives come from
22
+ [`cryptography`](https://cryptography.io) (OpenSSL-backed, audited) and
23
+ CBOR decoding from [`cbor2`](https://pypi.org/project/cbor2/); the
24
+ canonical CBOR encoder and the obsigil logic are small, readable Python.
25
+ No compiled extension to build — it installs as a universal wheel and
26
+ you can read the whole format end to end.
27
+
28
+ ```python
29
+ import obsigil
30
+ from obsigil import Obsigil
31
+
32
+ key = obsigil.generate_key() # 64 CSPRNG bytes
33
+
34
+ token = Obsigil.mint(
35
+ clauses={"role": "admin"}, # opaque application data
36
+ mandate_key=key,
37
+ exp=4_000_000_000,
38
+ aud=["api"],
39
+ sub="u42",
40
+ manifest={"iss": "auth.example"}, # optional public half
41
+ )
42
+
43
+ # Front end (advisory — manifest is non-authoritative, §16.7):
44
+ front = Obsigil(token.token())
45
+ claims = front.claims() # dict | None
46
+ header = front.authorization_header() # "Bearer .0…" — send this
47
+
48
+ # Backend (authoritative):
49
+ mandate = Obsigil(token.token(), keys=key, audience="api", now=1)
50
+ role = mandate.clause("role") # raises ObsigilError if invalid
51
+ when = mandate.exp()
52
+ ```
53
+
54
+ ## API
55
+
56
+ A single **`Obsigil`** type views a token in three roles (API
57
+ conformance, §12):
58
+
59
+ - **`Obsigil.mint(*, clauses, mandate_key, exp, tid=None, aud=None,
60
+ sub=None, iss=None, alg="0", encoding="b64", manifest=None)`** — the
61
+ issuer: seal a mandate (and an optional keyless manifest) and return
62
+ the view. `tid` is generated (a fresh UUIDv7) unless supplied; a
63
+ supplied one must be a well-formed UUIDv7. Defaults are AES-SIV
64
+ (`alg="0"`) and base64 (`encoding`; also `"hex"`). Application
65
+ `clauses` use non-negative integer or text keys; reserved fields are
66
+ set via their keyword arguments.
67
+ - **`Obsigil(token, *, keys=None, audience=None, leeway=0, now=None,
68
+ max_decoded_len=65536, on_reject=None)`** — keyless for the front end,
69
+ or with `keys` for the backend. `keys` may be one key or several
70
+ (key selection by trial decryption, §16.5); `leeway` is clamped to a
71
+ fixed maximum (Limits and robustness, §16.10).
72
+
73
+ Each half is reachable at three fidelities (the three fidelities of
74
+ API conformance, §12.2):
75
+
76
+ | | manifest | mandate |
77
+ |---|---|---|
78
+ | wire string | `manifest()` | `mandate()` |
79
+ | plaintext (CBOR octets) | `manifest_plaintext()` | `mandate_plaintext()` |
80
+ | parsed | `claims()` | `clauses()` |
81
+
82
+ - **`clauses()`** authenticates *and* enforces policy (`exp`, `aud`,
83
+ `tid`, types), returning a dict or raising one opaque `ObsigilError`.
84
+ Reserved clauses are surfaced under their names (`tid` as text);
85
+ application fields keep their wire keys. Accessors: `exp()`, `tid()`,
86
+ `issued_at()`, `sub()`, `iss()`, `aud()`, `clause(key)`.
87
+ - **`clauses_unchecked()`** authenticates and decodes the canonical
88
+ CBOR but skips the value checks; **`mandate_plaintext()`**
89
+ authenticates only and returns the raw CBOR octets. Both are
90
+ backend-internal — keep them non-bearer-facing (authentication vs
91
+ policy layers, §16.3).
92
+ - **`claims()`** opens the keyless manifest for display — advisory,
93
+ returns a dict or `None`, never raises (the manifest is
94
+ non-authoritative, §16.7).
95
+ - **`mandate()`** / **`manifest()`** — each half as a standalone token;
96
+ **`authorization_header(scheme="Bearer")`** gives the manifest-absent
97
+ `.0mandate` form to forward to the backend (Audiences, §9).
98
+
99
+ The free functions **`mint`**, **`clauses`**, **`claims`**,
100
+ **`mandate`**, **`manifest`**, **`clauses_unchecked`**,
101
+ **`mandate_plaintext`**, **`manifest_plaintext`**, and
102
+ **`authorization_header`** wrap the same core, plus **`generate_key`**,
103
+ **`generate_uuid7`**, **`is_uuid7`**, **`is_uuid7_bytes`**,
104
+ **`uuid7_time`**, **`MANIFEST_KEY`**, **`ObsigilError`**, **`Reason`**.
105
+ The granular `Reason` is delivered to `on_reject` for **internal logging
106
+ only** — never to the bearer (the uniform-failure rule, §16.6).
107
+
108
+ ## Install
109
+
110
+ ```sh
111
+ pip install obsigil
112
+ ```
113
+
114
+ Requires Python ≥ 3.9. AES-GCM-SIV (algorithm code `1`) needs OpenSSL
115
+ 3.2+, which modern `cryptography` wheels bundle; AES-SIV (code `0`, the
116
+ mandatory default) has no such floor.
117
+
118
+ ## Conformance
119
+
120
+ obsigil implements canonical CBOR (RFC 8949 §4.2) and the validation
121
+ rules of Reserved fields §8 and Limits and robustness §16.10. The
122
+ bundled test suite covers round-trip,
123
+ the verification ladder, and the negative cases (non-canonical CBOR,
124
+ duplicate keys, wrong-typed reserved fields, expiry, audience, size and
125
+ leeway bounds):
126
+
127
+ ```sh
128
+ pip install -e .[test]
129
+ pytest
130
+ ```
131
+
132
+ Cross-language byte-for-byte known-answer vectors are tracked
133
+ separately in the `obsigil-test-vectors` suite, kept in step with the
134
+ canonical-CBOR format.
135
+
136
+ ## License
137
+
138
+ Licensed under either of
139
+
140
+ - Apache License, Version 2.0
141
+ ([LICENSE-APACHE](LICENSE-APACHE) or
142
+ <https://www.apache.org/licenses/LICENSE-2.0>)
143
+ - MIT license ([LICENSE-MIT](LICENSE-MIT) or
144
+ <https://opensource.org/licenses/MIT>)
145
+
146
+ at your option.
147
+
148
+ ### Contribution
149
+
150
+ Unless you explicitly state otherwise, any contribution
151
+ intentionally submitted for inclusion in the work by you, as
152
+ defined in the Apache-2.0 license, shall be dual licensed as
153
+ above, without any additional terms or conditions.
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "obsigil"
7
+ version = "0.1.0"
8
+ description = "Pure-Python implementation of the obsigil mandate-token format (AES-SIV / AES-GCM-SIV)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT OR Apache-2.0"
12
+ license-files = ["LICENSE-MIT", "LICENSE-APACHE"]
13
+ authors = [{ name = "Bojan Đuričković" }]
14
+ keywords = ["obsigil", "mandate", "token", "aes-siv", "aes-gcm-siv", "jwt", "credential"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Topic :: Security :: Cryptography",
26
+ "Typing :: Typed",
27
+ ]
28
+ dependencies = [
29
+ "cryptography>=42.0",
30
+ "cbor2>=5.4",
31
+ ]
32
+ [project.urls]
33
+ Homepage = "https://obsigil.org"
34
+ Repository = "https://gitlab.com/obsigil/obsigil-py"
35
+
36
+ [project.optional-dependencies]
37
+ test = ["pytest>=7"]
38
+
39
+ [tool.hatch.build.targets.wheel]
40
+ packages = ["src/obsigil"]
41
+
42
+ [tool.hatch.build.targets.sdist]
43
+ # Ship only the package, tests, README, and licenses — not dev cruft
44
+ # (.claude/, .iloc-cache.json, caches). pyproject.toml is always included.
45
+ only-include = ["src", "tests", "README.md", "LICENSE-MIT", "LICENSE-APACHE"]
@@ -0,0 +1,65 @@
1
+ """obsigil — a mandate-token format and shared-secret JWT alternative.
2
+
3
+ A token split into a public **manifest** and an encrypted **mandate**, each an
4
+ authenticated, deterministically-sealed ciphertext (AES-SIV / AES-GCM-SIV) in
5
+ compact text. Each half's fields are a canonical CBOR map (RFC 8949 §4.2);
6
+ reserved fields take negative integer keys, application data non-negative
7
+ integer or text keys. Verification is symmetric — the same mandate key both
8
+ mints and verifies — so obsigil fits shared-secret (HS256-style) JWT/JWE use
9
+ cases, not public-key verification.
10
+
11
+ This package is the pure-Python reference implementation, built on
12
+ ``cryptography`` for the AEAD primitives and ``cbor2`` for CBOR decoding (the
13
+ canonical encoder is obsigil's own).
14
+
15
+ import obsigil
16
+
17
+ key = obsigil.generate_key()
18
+ tok = obsigil.Obsigil.mint(
19
+ clauses={"role": "admin"},
20
+ mandate_key=key,
21
+ exp=4_000_000_000,
22
+ aud=["api"],
23
+ manifest={"iss": "auth.example"},
24
+ )
25
+ obsigil.Obsigil(tok.token()).claims() # advisory, front end
26
+ obsigil.Obsigil(tok.token(), keys=key, audience="api",
27
+ now=1).clauses() # authoritative, backend
28
+
29
+ The free functions ``mint`` / ``clauses`` / ``claims`` / ``mandate`` /
30
+ ``manifest`` wrap the same core.
31
+ """
32
+
33
+ from __future__ import annotations
34
+
35
+ from ._constants import MANIFEST_KEY
36
+ from .core import Obsigil, clauses_unchecked, mandate_plaintext
37
+ from .errors import ObsigilError, Reason
38
+ from .keys import generate_key
39
+ from .manifest import authorization_header, claims, mandate, manifest, manifest_plaintext
40
+ from .mint import mint
41
+ from .uuid7 import generate_uuid7, is_uuid7, is_uuid7_bytes, uuid7_time
42
+ from .verify import clauses
43
+
44
+ __version__ = "0.1.0"
45
+
46
+ __all__ = [
47
+ "MANIFEST_KEY",
48
+ "Obsigil",
49
+ "ObsigilError",
50
+ "Reason",
51
+ "authorization_header",
52
+ "claims",
53
+ "clauses",
54
+ "clauses_unchecked",
55
+ "generate_key",
56
+ "generate_uuid7",
57
+ "is_uuid7",
58
+ "is_uuid7_bytes",
59
+ "mandate",
60
+ "mandate_plaintext",
61
+ "manifest",
62
+ "manifest_plaintext",
63
+ "mint",
64
+ "uuid7_time",
65
+ ]