railid-native 4.4.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,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: railid-native
3
+ Version: 4.4.0
4
+ Summary: Dependency-free Python bindings for RailID via the railid-capi C ABI
5
+ Author: Nekomakura
6
+ License: MIT
7
+ Project-URL: Repository, https://github.com/LunaLaboratory/Rail-ID
8
+ Project-URL: Issues, https://github.com/LunaLaboratory/Rail-ID/issues
9
+ Keywords: railid,identifier,uuid,tpm,ctypes
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
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: Programming Language :: Python :: Implementation :: CPython
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+
26
+ # railid-native (Python)
27
+
28
+ Dependency-free Python bindings for [RailID](https://github.com/LunaLaboratory/Rail-ID),
29
+ implemented with the standard library's `ctypes` module on top of the
30
+ `railid-capi` C ABI (ABI revision 4).
31
+
32
+ The distribution is named `railid-native`; the import package is `railid`.
33
+
34
+ ```python
35
+ import railid
36
+
37
+ print(railid.version(), railid.abi_version()) # e.g. 4.4.0 4
38
+ print(railid.generate("os-only")) # 32-char RailID v1
39
+ print(railid.generate_v4("os-only")) # 21-char RailID v4
40
+ ```
41
+
42
+ ## Requirements
43
+
44
+ - Python 3.9 or newer (CPython; other ctypes-capable implementations may work).
45
+ - A built `railid` shared library:
46
+ - Windows: `railid.dll`
47
+ - Linux: `librailid.so`
48
+ - macOS: `librailid.dylib`
49
+
50
+ Build the C ABI from the repository root:
51
+
52
+ ```bash
53
+ cargo build --manifest-path railid-capi/Cargo.toml --release
54
+ ```
55
+
56
+ Add `--features tpm` to include the TPM 2.0 hybrid backend. Linux TPM builds
57
+ need `pkg-config` and `libtss2-dev`; Windows TPM builds use TBS.
58
+
59
+ ## Installation
60
+
61
+ From a checkout (no PyPI release is produced):
62
+
63
+ ```bash
64
+ python -m pip install ./python
65
+ ```
66
+
67
+ For development use an editable install:
68
+
69
+ ```bash
70
+ python -m pip install -e ./python
71
+ ```
72
+
73
+ The wheel contains only this package and `py.typed` (the sdist also carries
74
+ the tests and packaging metadata); it does **not** bundle a native library.
75
+ Install or build the C ABI separately and point `RAILID_LIBRARY` at it.
76
+
77
+ ## Library discovery
78
+
79
+ The loader is lazy and uses the first library that loads successfully:
80
+
81
+ 1. `RAILID_LIBRARY`  Ea path to the shared library, or to a directory
82
+ containing it. If this variable is set, it is authoritative: a load
83
+ failure raises `LibraryError` instead of falling back.
84
+ 2. Platform names (`railid.dll`, `librailid.so`, `librailid.dylib`) in
85
+ `railid-capi/target/release` and `target/release` directories relative to
86
+ the package and repository roots, then the current directory.
87
+ 3. `ctypes.util.find_library("railid")`.
88
+
89
+ A library with an ABI revision other than 4 is rejected with `LibraryError`.
90
+ `railid.library_path()` reports the file that was loaded.
91
+
92
+ Examples:
93
+
94
+ ```bash
95
+ # Linux/macOS
96
+ export RAILID_LIBRARY="$PWD/railid-capi/target/release/librailid.so"
97
+
98
+ # Windows PowerShell
99
+ $env:RAILID_LIBRARY = "$PWD\railid-capi\target\release\railid.dll"
100
+ ```
101
+
102
+ ## API
103
+
104
+ | Function | Result |
105
+ | --- | --- |
106
+ | `abi_version() -> int` | C ABI revision (4). |
107
+ | `version() -> str` | Native crate version, e.g. `"4.4.0"`. |
108
+ | `generate(profile="tpm") -> str` | One 32-character v1 ID. |
109
+ | `generate_v4(profile="tpm") -> str` | One 21-character v4 ID (126 bits). |
110
+ | `generate_many_encoded(profile="tpm", count=0) -> bytes` | `count * 32` v1 IDs, contiguous, no separators. |
111
+ | `error_message(code) -> str` | The C ABI message for a status code. |
112
+ | `reset_after_fork() -> None` | Discard cached randomness/timestamps after `fork()`. |
113
+ | `library_path() -> str` | Path of the loaded shared library. |
114
+
115
+ Profiles are `"tpm"` (TPM 2.0 hybrid) and `"os-only"` (explicitly degraded OS
116
+ CSPRNG). `Profile.TPM`, `Profile.OS_ONLY`, `PROFILE_TPM`, and
117
+ `PROFILE_OS_ONLY` are provided, and plain strings may be used anywhere a
118
+ profile is accepted.
119
+
120
+ ```python
121
+ import railid
122
+
123
+ blob = railid.generate_many_encoded("os-only", 3)
124
+ assert len(blob) == 3 * railid.ENCODED_LEN
125
+ ids = [blob[i * 32:(i + 1) * 32].decode("ascii") for i in range(3)]
126
+ ```
127
+
128
+ `generate_many_encoded` returns raw bytes; the C ABI has no v4 batch or decode
129
+ entry point, so neither is invented here.
130
+
131
+ ## Errors
132
+
133
+ All native failures raise `RailidError`, a `RuntimeError` subclass with:
134
+
135
+ - `code`  Ethe negative C status code (`ErrorCode.TpmUnavailable`, etc.);
136
+ - `message`  Ethe library's `railid_error_message` text;
137
+ - `detail`  Eoptional wrapper context.
138
+
139
+ The TPM profile is fail-closed. If the library was built without `--features
140
+ tpm`, or no usable TPM 2.0 device exists, `generate("tpm")`,
141
+ `generate_v4("tpm")`, and `generate_many_encoded("tpm", n)` raise
142
+ `RailidError` with code `-4` (`ErrorCode.TpmUnavailable`). They never fall
143
+ back to OS randomness.
144
+
145
+ ```python
146
+ try:
147
+ value = railid.generate("tpm")
148
+ except railid.RailidError as error:
149
+ if error.code == railid.ErrorCode.TpmUnavailable:
150
+ print("no TPM; falling back explicitly")
151
+ value = railid.generate("os-only")
152
+ else:
153
+ raise
154
+ ```
155
+
156
+ Invalid profile strings raise `RailidError` with `ErrorCode.InvalidProfile`.
157
+ `generate_many_encoded` enforces the C ABI batch caps
158
+ (`MAX_TPM_BATCH_IDS = 1024`, `MAX_OS_ONLY_BATCH_IDS = 1_000_000`) before
159
+ allocating and raises `ErrorCode.CapacityOverflow` above them. Negative
160
+ counts raise `ValueError`; non-integer counts raise `TypeError`.
161
+
162
+ Outputs are validated: v1 must be exactly 32 characters, v4 exactly 21, and
163
+ every character must belong to the unpadded Base64URL alphabet
164
+ (`A-Z`, `a-z`, `0-9`, `-`, `_`). Unexpected length or characters raise
165
+ `RuntimeError` rather than returning corrupt data.
166
+
167
+ If the shared library cannot be found, `LibraryError` (a `RuntimeError`) is
168
+ raised with the paths that were tried.
169
+
170
+ ## Limitations
171
+
172
+ - No bundled native binaries and no PyPI publication; build `railid-capi`
173
+ yourself.
174
+ - The wrapper targets C ABI 4 and refuses other revisions.
175
+ - No v4 batch generation and no decode/parse functions (not exposed by the C
176
+ ABI).
177
+ - TPM availability depends on the native build (`--features tpm`), the OS
178
+ backend, and the machine. TPM failures are never masked.
179
+ - `ctypes` adds a small call overhead per ID; use the batch API for bulk
180
+ generation.
181
+ - Only OS randomness is available when the `tpm` feature is off, and that
182
+ profile is explicitly degraded.
183
+
184
+ ## Tests
185
+
186
+ ```bash
187
+ cargo build --manifest-path railid-capi/Cargo.toml --release
188
+ RAILID_LIBRARY="$PWD/railid-capi/target/release/librailid.so" \
189
+ pytest python/tests
190
+ ```
191
+
192
+ On Windows PowerShell:
193
+
194
+ ```powershell
195
+ $env:RAILID_LIBRARY = "$PWD\railid-capi\target\release\railid.dll"
196
+ pytest python/tests
197
+ ```
198
+
199
+ `pytest` is the only test dependency; the runtime package itself imports only
200
+ the Python standard library.
201
+
202
+ ## Repository packaging note
203
+
204
+ The root Rust package should exclude this directory so the Python sources are
205
+ not shipped in the crate archive:
206
+
207
+ ```toml
208
+ exclude = ["python/**"]
209
+ ```
@@ -0,0 +1,184 @@
1
+ # railid-native (Python)
2
+
3
+ Dependency-free Python bindings for [RailID](https://github.com/LunaLaboratory/Rail-ID),
4
+ implemented with the standard library's `ctypes` module on top of the
5
+ `railid-capi` C ABI (ABI revision 4).
6
+
7
+ The distribution is named `railid-native`; the import package is `railid`.
8
+
9
+ ```python
10
+ import railid
11
+
12
+ print(railid.version(), railid.abi_version()) # e.g. 4.4.0 4
13
+ print(railid.generate("os-only")) # 32-char RailID v1
14
+ print(railid.generate_v4("os-only")) # 21-char RailID v4
15
+ ```
16
+
17
+ ## Requirements
18
+
19
+ - Python 3.9 or newer (CPython; other ctypes-capable implementations may work).
20
+ - A built `railid` shared library:
21
+ - Windows: `railid.dll`
22
+ - Linux: `librailid.so`
23
+ - macOS: `librailid.dylib`
24
+
25
+ Build the C ABI from the repository root:
26
+
27
+ ```bash
28
+ cargo build --manifest-path railid-capi/Cargo.toml --release
29
+ ```
30
+
31
+ Add `--features tpm` to include the TPM 2.0 hybrid backend. Linux TPM builds
32
+ need `pkg-config` and `libtss2-dev`; Windows TPM builds use TBS.
33
+
34
+ ## Installation
35
+
36
+ From a checkout (no PyPI release is produced):
37
+
38
+ ```bash
39
+ python -m pip install ./python
40
+ ```
41
+
42
+ For development use an editable install:
43
+
44
+ ```bash
45
+ python -m pip install -e ./python
46
+ ```
47
+
48
+ The wheel contains only this package and `py.typed` (the sdist also carries
49
+ the tests and packaging metadata); it does **not** bundle a native library.
50
+ Install or build the C ABI separately and point `RAILID_LIBRARY` at it.
51
+
52
+ ## Library discovery
53
+
54
+ The loader is lazy and uses the first library that loads successfully:
55
+
56
+ 1. `RAILID_LIBRARY`  Ea path to the shared library, or to a directory
57
+ containing it. If this variable is set, it is authoritative: a load
58
+ failure raises `LibraryError` instead of falling back.
59
+ 2. Platform names (`railid.dll`, `librailid.so`, `librailid.dylib`) in
60
+ `railid-capi/target/release` and `target/release` directories relative to
61
+ the package and repository roots, then the current directory.
62
+ 3. `ctypes.util.find_library("railid")`.
63
+
64
+ A library with an ABI revision other than 4 is rejected with `LibraryError`.
65
+ `railid.library_path()` reports the file that was loaded.
66
+
67
+ Examples:
68
+
69
+ ```bash
70
+ # Linux/macOS
71
+ export RAILID_LIBRARY="$PWD/railid-capi/target/release/librailid.so"
72
+
73
+ # Windows PowerShell
74
+ $env:RAILID_LIBRARY = "$PWD\railid-capi\target\release\railid.dll"
75
+ ```
76
+
77
+ ## API
78
+
79
+ | Function | Result |
80
+ | --- | --- |
81
+ | `abi_version() -> int` | C ABI revision (4). |
82
+ | `version() -> str` | Native crate version, e.g. `"4.4.0"`. |
83
+ | `generate(profile="tpm") -> str` | One 32-character v1 ID. |
84
+ | `generate_v4(profile="tpm") -> str` | One 21-character v4 ID (126 bits). |
85
+ | `generate_many_encoded(profile="tpm", count=0) -> bytes` | `count * 32` v1 IDs, contiguous, no separators. |
86
+ | `error_message(code) -> str` | The C ABI message for a status code. |
87
+ | `reset_after_fork() -> None` | Discard cached randomness/timestamps after `fork()`. |
88
+ | `library_path() -> str` | Path of the loaded shared library. |
89
+
90
+ Profiles are `"tpm"` (TPM 2.0 hybrid) and `"os-only"` (explicitly degraded OS
91
+ CSPRNG). `Profile.TPM`, `Profile.OS_ONLY`, `PROFILE_TPM`, and
92
+ `PROFILE_OS_ONLY` are provided, and plain strings may be used anywhere a
93
+ profile is accepted.
94
+
95
+ ```python
96
+ import railid
97
+
98
+ blob = railid.generate_many_encoded("os-only", 3)
99
+ assert len(blob) == 3 * railid.ENCODED_LEN
100
+ ids = [blob[i * 32:(i + 1) * 32].decode("ascii") for i in range(3)]
101
+ ```
102
+
103
+ `generate_many_encoded` returns raw bytes; the C ABI has no v4 batch or decode
104
+ entry point, so neither is invented here.
105
+
106
+ ## Errors
107
+
108
+ All native failures raise `RailidError`, a `RuntimeError` subclass with:
109
+
110
+ - `code`  Ethe negative C status code (`ErrorCode.TpmUnavailable`, etc.);
111
+ - `message`  Ethe library's `railid_error_message` text;
112
+ - `detail`  Eoptional wrapper context.
113
+
114
+ The TPM profile is fail-closed. If the library was built without `--features
115
+ tpm`, or no usable TPM 2.0 device exists, `generate("tpm")`,
116
+ `generate_v4("tpm")`, and `generate_many_encoded("tpm", n)` raise
117
+ `RailidError` with code `-4` (`ErrorCode.TpmUnavailable`). They never fall
118
+ back to OS randomness.
119
+
120
+ ```python
121
+ try:
122
+ value = railid.generate("tpm")
123
+ except railid.RailidError as error:
124
+ if error.code == railid.ErrorCode.TpmUnavailable:
125
+ print("no TPM; falling back explicitly")
126
+ value = railid.generate("os-only")
127
+ else:
128
+ raise
129
+ ```
130
+
131
+ Invalid profile strings raise `RailidError` with `ErrorCode.InvalidProfile`.
132
+ `generate_many_encoded` enforces the C ABI batch caps
133
+ (`MAX_TPM_BATCH_IDS = 1024`, `MAX_OS_ONLY_BATCH_IDS = 1_000_000`) before
134
+ allocating and raises `ErrorCode.CapacityOverflow` above them. Negative
135
+ counts raise `ValueError`; non-integer counts raise `TypeError`.
136
+
137
+ Outputs are validated: v1 must be exactly 32 characters, v4 exactly 21, and
138
+ every character must belong to the unpadded Base64URL alphabet
139
+ (`A-Z`, `a-z`, `0-9`, `-`, `_`). Unexpected length or characters raise
140
+ `RuntimeError` rather than returning corrupt data.
141
+
142
+ If the shared library cannot be found, `LibraryError` (a `RuntimeError`) is
143
+ raised with the paths that were tried.
144
+
145
+ ## Limitations
146
+
147
+ - No bundled native binaries and no PyPI publication; build `railid-capi`
148
+ yourself.
149
+ - The wrapper targets C ABI 4 and refuses other revisions.
150
+ - No v4 batch generation and no decode/parse functions (not exposed by the C
151
+ ABI).
152
+ - TPM availability depends on the native build (`--features tpm`), the OS
153
+ backend, and the machine. TPM failures are never masked.
154
+ - `ctypes` adds a small call overhead per ID; use the batch API for bulk
155
+ generation.
156
+ - Only OS randomness is available when the `tpm` feature is off, and that
157
+ profile is explicitly degraded.
158
+
159
+ ## Tests
160
+
161
+ ```bash
162
+ cargo build --manifest-path railid-capi/Cargo.toml --release
163
+ RAILID_LIBRARY="$PWD/railid-capi/target/release/librailid.so" \
164
+ pytest python/tests
165
+ ```
166
+
167
+ On Windows PowerShell:
168
+
169
+ ```powershell
170
+ $env:RAILID_LIBRARY = "$PWD\railid-capi\target\release\railid.dll"
171
+ pytest python/tests
172
+ ```
173
+
174
+ `pytest` is the only test dependency; the runtime package itself imports only
175
+ the Python standard library.
176
+
177
+ ## Repository packaging note
178
+
179
+ The root Rust package should exclude this directory so the Python sources are
180
+ not shipped in the crate archive:
181
+
182
+ ```toml
183
+ exclude = ["python/**"]
184
+ ```
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "railid-native"
7
+ version = "4.4.0"
8
+ description = "Dependency-free Python bindings for RailID via the railid-capi C ABI"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Nekomakura" }]
13
+ keywords = ["railid", "identifier", "uuid", "tpm", "ctypes"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Programming Language :: Python :: Implementation :: CPython",
27
+ "Typing :: Typed",
28
+ ]
29
+ dependencies = []
30
+
31
+ [project.urls]
32
+ Repository = "https://github.com/LunaLaboratory/Rail-ID"
33
+ Issues = "https://github.com/LunaLaboratory/Rail-ID/issues"
34
+
35
+ [tool.setuptools]
36
+ packages = ["railid"]
37
+ include-package-data = true
38
+
39
+ [tool.setuptools.package-data]
40
+ railid = ["py.typed"]