devlacruz-hashlib 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,250 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.4.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
10
+
11
+ [[package]]
12
+ name = "block-buffer"
13
+ version = "0.10.4"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
16
+ dependencies = [
17
+ "generic-array",
18
+ ]
19
+
20
+ [[package]]
21
+ name = "cfg-if"
22
+ version = "1.0.0"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
25
+
26
+ [[package]]
27
+ name = "cpufeatures"
28
+ version = "0.2.17"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
31
+ dependencies = [
32
+ "libc",
33
+ ]
34
+
35
+ [[package]]
36
+ name = "crypto-common"
37
+ version = "0.1.6"
38
+ source = "registry+https://github.com/rust-lang/crates.io-index"
39
+ checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
40
+ dependencies = [
41
+ "generic-array",
42
+ "typenum",
43
+ ]
44
+
45
+ [[package]]
46
+ name = "devlacruz_hashlib"
47
+ version = "0.1.0"
48
+ dependencies = [
49
+ "hex",
50
+ "pyo3",
51
+ "sha2",
52
+ ]
53
+
54
+ [[package]]
55
+ name = "digest"
56
+ version = "0.10.7"
57
+ source = "registry+https://github.com/rust-lang/crates.io-index"
58
+ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
59
+ dependencies = [
60
+ "block-buffer",
61
+ "crypto-common",
62
+ ]
63
+
64
+ [[package]]
65
+ name = "generic-array"
66
+ version = "0.14.7"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
69
+ dependencies = [
70
+ "typenum",
71
+ "version_check",
72
+ ]
73
+
74
+ [[package]]
75
+ name = "heck"
76
+ version = "0.5.0"
77
+ source = "registry+https://github.com/rust-lang/crates.io-index"
78
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
79
+
80
+ [[package]]
81
+ name = "hex"
82
+ version = "0.4.3"
83
+ source = "registry+https://github.com/rust-lang/crates.io-index"
84
+ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
85
+
86
+ [[package]]
87
+ name = "indoc"
88
+ version = "2.0.6"
89
+ source = "registry+https://github.com/rust-lang/crates.io-index"
90
+ checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
91
+
92
+ [[package]]
93
+ name = "libc"
94
+ version = "0.2.172"
95
+ source = "registry+https://github.com/rust-lang/crates.io-index"
96
+ checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
97
+
98
+ [[package]]
99
+ name = "memoffset"
100
+ version = "0.9.1"
101
+ source = "registry+https://github.com/rust-lang/crates.io-index"
102
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
103
+ dependencies = [
104
+ "autocfg",
105
+ ]
106
+
107
+ [[package]]
108
+ name = "once_cell"
109
+ version = "1.21.3"
110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
111
+ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
112
+
113
+ [[package]]
114
+ name = "portable-atomic"
115
+ version = "1.11.0"
116
+ source = "registry+https://github.com/rust-lang/crates.io-index"
117
+ checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
118
+
119
+ [[package]]
120
+ name = "proc-macro2"
121
+ version = "1.0.95"
122
+ source = "registry+https://github.com/rust-lang/crates.io-index"
123
+ checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
124
+ dependencies = [
125
+ "unicode-ident",
126
+ ]
127
+
128
+ [[package]]
129
+ name = "pyo3"
130
+ version = "0.24.2"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+ checksum = "e5203598f366b11a02b13aa20cab591229ff0a89fd121a308a5df751d5fc9219"
133
+ dependencies = [
134
+ "cfg-if",
135
+ "indoc",
136
+ "libc",
137
+ "memoffset",
138
+ "once_cell",
139
+ "portable-atomic",
140
+ "pyo3-build-config",
141
+ "pyo3-ffi",
142
+ "pyo3-macros",
143
+ "unindent",
144
+ ]
145
+
146
+ [[package]]
147
+ name = "pyo3-build-config"
148
+ version = "0.24.2"
149
+ source = "registry+https://github.com/rust-lang/crates.io-index"
150
+ checksum = "99636d423fa2ca130fa5acde3059308006d46f98caac629418e53f7ebb1e9999"
151
+ dependencies = [
152
+ "once_cell",
153
+ "target-lexicon",
154
+ ]
155
+
156
+ [[package]]
157
+ name = "pyo3-ffi"
158
+ version = "0.24.2"
159
+ source = "registry+https://github.com/rust-lang/crates.io-index"
160
+ checksum = "78f9cf92ba9c409279bc3305b5409d90db2d2c22392d443a87df3a1adad59e33"
161
+ dependencies = [
162
+ "libc",
163
+ "pyo3-build-config",
164
+ ]
165
+
166
+ [[package]]
167
+ name = "pyo3-macros"
168
+ version = "0.24.2"
169
+ source = "registry+https://github.com/rust-lang/crates.io-index"
170
+ checksum = "0b999cb1a6ce21f9a6b147dcf1be9ffedf02e0043aec74dc390f3007047cecd9"
171
+ dependencies = [
172
+ "proc-macro2",
173
+ "pyo3-macros-backend",
174
+ "quote",
175
+ "syn",
176
+ ]
177
+
178
+ [[package]]
179
+ name = "pyo3-macros-backend"
180
+ version = "0.24.2"
181
+ source = "registry+https://github.com/rust-lang/crates.io-index"
182
+ checksum = "822ece1c7e1012745607d5cf0bcb2874769f0f7cb34c4cde03b9358eb9ef911a"
183
+ dependencies = [
184
+ "heck",
185
+ "proc-macro2",
186
+ "pyo3-build-config",
187
+ "quote",
188
+ "syn",
189
+ ]
190
+
191
+ [[package]]
192
+ name = "quote"
193
+ version = "1.0.40"
194
+ source = "registry+https://github.com/rust-lang/crates.io-index"
195
+ checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
196
+ dependencies = [
197
+ "proc-macro2",
198
+ ]
199
+
200
+ [[package]]
201
+ name = "sha2"
202
+ version = "0.10.8"
203
+ source = "registry+https://github.com/rust-lang/crates.io-index"
204
+ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
205
+ dependencies = [
206
+ "cfg-if",
207
+ "cpufeatures",
208
+ "digest",
209
+ ]
210
+
211
+ [[package]]
212
+ name = "syn"
213
+ version = "2.0.101"
214
+ source = "registry+https://github.com/rust-lang/crates.io-index"
215
+ checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
216
+ dependencies = [
217
+ "proc-macro2",
218
+ "quote",
219
+ "unicode-ident",
220
+ ]
221
+
222
+ [[package]]
223
+ name = "target-lexicon"
224
+ version = "0.13.2"
225
+ source = "registry+https://github.com/rust-lang/crates.io-index"
226
+ checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a"
227
+
228
+ [[package]]
229
+ name = "typenum"
230
+ version = "1.18.0"
231
+ source = "registry+https://github.com/rust-lang/crates.io-index"
232
+ checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
233
+
234
+ [[package]]
235
+ name = "unicode-ident"
236
+ version = "1.0.18"
237
+ source = "registry+https://github.com/rust-lang/crates.io-index"
238
+ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
239
+
240
+ [[package]]
241
+ name = "unindent"
242
+ version = "0.2.4"
243
+ source = "registry+https://github.com/rust-lang/crates.io-index"
244
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
245
+
246
+ [[package]]
247
+ name = "version_check"
248
+ version = "0.9.5"
249
+ source = "registry+https://github.com/rust-lang/crates.io-index"
250
+ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "devlacruz_hashlib"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ description = "Extensión de hashing acelerado con Rust y PyO3"
6
+ license = "MIT"
7
+ repository = "https://github.com/DevLaCruz/devlacruz_hashlib"
8
+
9
+ [lib]
10
+ name = "devlacruz_hashlib"
11
+ crate-type = ["cdylib"]
12
+
13
+ [dependencies]
14
+ pyo3 = { version = "0.24.2", features = ["extension-module"] }
15
+ sha2 = "0.10"
16
+ hex = "0.4"
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
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.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.4
2
+ Name: devlacruz_hashlib
3
+ Version: 0.1.0
4
+ Classifier: Programming Language :: Python :: 3
5
+ Classifier: Programming Language :: Python :: 3.7
6
+ Classifier: Programming Language :: Python :: 3.8
7
+ Classifier: Programming Language :: Python :: 3.9
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Rust
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Topic :: Security :: Cryptography
16
+ License-File: LICENSE
17
+ Summary: Extensión de hashing SHA-256 acelerado con Rust y PyO3
18
+ Author-email: Alejandro De La Cruz <devlacruz@axtosys.com>
19
+ License: MIT
20
+ Requires-Python: >=3.7, <4.0
21
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
22
+ Project-URL: Source Code, https://github.com/DevLaCruz/devlacruz_hashlib
23
+
24
+ # devlacruz_hashlib
25
+
26
+ High-performance library for SHA-256 hash functions implemented in Rust with PyO3.
27
+
28
+ [![PyPI version](https://img.shields.io/pypi/v/devlacruz_hashlib.svg)](https://pypi.org/project/devlacruz_hashlib/)
29
+ [![Python versions](https://img.shields.io/pypi/pyversions/devlacruz_hashlib.svg)](https://pypi.org/project/devlacruz_hashlib/)
30
+
31
+ ## Features
32
+
33
+ - Ultra-fast computation of SHA-256 hashes
34
+ - GIL release during intensive operations
35
+ - Compatible with Python 3.7+
36
+ - Support for hashing integers, strings, and bytes
37
+ - Performance superior to pure Python implementations
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install devlacruz_hashlib
43
+ ```text
44
+
45
+ ## Basic Usage
46
+
47
+ ```python
48
+ import devlacruz_hashlib
49
+
50
+ # Hash of an integer (basic version)
51
+ hash1 = devlacruz_hashlib.hash_id_simple(12345)
52
+ print(f"Simple hash of integer: {hash1}")
53
+
54
+ # Hash of an integer (GIL-releasing version)
55
+ hash2 = devlacruz_hashlib.hash_id(12345)
56
+ print(f"Hash of integer: {hash2}")
57
+
58
+ # Hash of a string
59
+ hash3 = devlacruz_hashlib.hash_string("Hello world")
60
+ print(f"Hash of string: {hash3}")
61
+
62
+ # Hash of bytes
63
+ hash4 = devlacruz_hashlib.hash_bytes(b"binary data")
64
+ print(f"Hash of bytes: {hash4}")
65
+ ```text
66
+
67
+ ## Performance
68
+
69
+ This library provides a SHA-256 hash implementation significantly faster than pure Python solutions. Particularly useful for:
70
+
71
+ - Processing large volumes of data
72
+ - Computing hashes in intensive loops
73
+ - Applications where performance is critical
74
+
75
+ ### Performance Comparison
76
+
77
+ ```python
78
+ import time
79
+ import hashlib
80
+ import devlacruz_hashlib
81
+
82
+ # Test data
83
+ data = b"x" * 1000000 # ~1MB of data
84
+
85
+ # Time with Python's hashlib
86
+ start = time.time()
87
+ for _ in range(100):
88
+ hashlib.sha256(data).hexdigest()
89
+ py_time = time.time() - start
90
+ print(f"Python hashlib: {py_time:.3f} seconds")
91
+
92
+ # Time with devlacruz_hashlib
93
+ start = time.time()
94
+ for _ in range(100):
95
+ devlacruz_hashlib.hash_bytes(data)
96
+ rust_time = time.time() - start
97
+ print(f"devlacruz_hashlib: {rust_time:.3f} seconds")
98
+
99
+ print(f"Performance improvement: {py_time/rust_time:.1f}x faster")
100
+ ```text
101
+
102
+ ## Full API
103
+
104
+ ### `hash_id_simple(x: int) → str`
105
+
106
+ Calculates the SHA-256 hash of an integer. This version does not release Python's GIL.
107
+
108
+ ### `hash_id(x: int) → str`
109
+
110
+ Calculates the SHA-256 hash of an integer while releasing the GIL. Recommended for parallel processing.
111
+
112
+ ### `hash_string(s: str) → str`
113
+
114
+ Calculates the SHA-256 hash of a text string. Releases the GIL during processing.
115
+
116
+ ### `hash_bytes(data: bytes) → str`
117
+
118
+ Calculates the SHA-256 hash of a bytes object. Releases the GIL during processing.
119
+
120
+ ## Technical Considerations
121
+
122
+ - The module releases the GIL (Global Interpreter Lock) during intensive hash operations, enabling true parallelism in multi-threaded applications.
123
+ - The Rust implementation provides memory and type safety without performance overhead.
124
+ - Compatible with all major platforms: Linux, Windows, and macOS.
125
+
126
+ ## When to Use devlacruz_hashlib vs Standard hashlib
127
+
128
+ Use devlacruz_hashlib when:
129
+ - Maximum performance is needed for SHA-256 hash operations
130
+ - Working with large volumes of data
131
+ - Performing hash operations in critical loops
132
+ - Utilizing multi-threaded processing where releasing the GIL is advantageous
133
+
134
+ Use standard `hashlib` when:
135
+ - Other algorithms besides SHA-256 are needed
136
+ - Simplicity and maintainability are more important than performance
137
+ - Avoiding additional dependencies is preferred
138
+
139
+ ## Contributions
140
+
141
+ Contributions are welcome. To contribute:
142
+
143
+ 1. Fork the repository
144
+ 2. Create a branch for your feature (`git checkout -b new-feature`)
145
+ 3. Make your changes and commit (`git commit -am 'Add new feature'`)
146
+ 4. Push your changes (`git push origin new-feature`)
147
+ 5. Create a Pull Request
148
+
149
+ ## License
150
+
151
+ MIT License - See the LICENSE file for more details.
152
+
153
+ ## Author
154
+
155
+ Alejandro De La Cruz (devlacruz@axtosys.com)
156
+
@@ -0,0 +1,132 @@
1
+ # devlacruz_hashlib
2
+
3
+ High-performance library for SHA-256 hash functions implemented in Rust with PyO3.
4
+
5
+ [![PyPI version](https://img.shields.io/pypi/v/devlacruz_hashlib.svg)](https://pypi.org/project/devlacruz_hashlib/)
6
+ [![Python versions](https://img.shields.io/pypi/pyversions/devlacruz_hashlib.svg)](https://pypi.org/project/devlacruz_hashlib/)
7
+
8
+ ## Features
9
+
10
+ - Ultra-fast computation of SHA-256 hashes
11
+ - GIL release during intensive operations
12
+ - Compatible with Python 3.7+
13
+ - Support for hashing integers, strings, and bytes
14
+ - Performance superior to pure Python implementations
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pip install devlacruz_hashlib
20
+ ```text
21
+
22
+ ## Basic Usage
23
+
24
+ ```python
25
+ import devlacruz_hashlib
26
+
27
+ # Hash of an integer (basic version)
28
+ hash1 = devlacruz_hashlib.hash_id_simple(12345)
29
+ print(f"Simple hash of integer: {hash1}")
30
+
31
+ # Hash of an integer (GIL-releasing version)
32
+ hash2 = devlacruz_hashlib.hash_id(12345)
33
+ print(f"Hash of integer: {hash2}")
34
+
35
+ # Hash of a string
36
+ hash3 = devlacruz_hashlib.hash_string("Hello world")
37
+ print(f"Hash of string: {hash3}")
38
+
39
+ # Hash of bytes
40
+ hash4 = devlacruz_hashlib.hash_bytes(b"binary data")
41
+ print(f"Hash of bytes: {hash4}")
42
+ ```text
43
+
44
+ ## Performance
45
+
46
+ This library provides a SHA-256 hash implementation significantly faster than pure Python solutions. Particularly useful for:
47
+
48
+ - Processing large volumes of data
49
+ - Computing hashes in intensive loops
50
+ - Applications where performance is critical
51
+
52
+ ### Performance Comparison
53
+
54
+ ```python
55
+ import time
56
+ import hashlib
57
+ import devlacruz_hashlib
58
+
59
+ # Test data
60
+ data = b"x" * 1000000 # ~1MB of data
61
+
62
+ # Time with Python's hashlib
63
+ start = time.time()
64
+ for _ in range(100):
65
+ hashlib.sha256(data).hexdigest()
66
+ py_time = time.time() - start
67
+ print(f"Python hashlib: {py_time:.3f} seconds")
68
+
69
+ # Time with devlacruz_hashlib
70
+ start = time.time()
71
+ for _ in range(100):
72
+ devlacruz_hashlib.hash_bytes(data)
73
+ rust_time = time.time() - start
74
+ print(f"devlacruz_hashlib: {rust_time:.3f} seconds")
75
+
76
+ print(f"Performance improvement: {py_time/rust_time:.1f}x faster")
77
+ ```text
78
+
79
+ ## Full API
80
+
81
+ ### `hash_id_simple(x: int) → str`
82
+
83
+ Calculates the SHA-256 hash of an integer. This version does not release Python's GIL.
84
+
85
+ ### `hash_id(x: int) → str`
86
+
87
+ Calculates the SHA-256 hash of an integer while releasing the GIL. Recommended for parallel processing.
88
+
89
+ ### `hash_string(s: str) → str`
90
+
91
+ Calculates the SHA-256 hash of a text string. Releases the GIL during processing.
92
+
93
+ ### `hash_bytes(data: bytes) → str`
94
+
95
+ Calculates the SHA-256 hash of a bytes object. Releases the GIL during processing.
96
+
97
+ ## Technical Considerations
98
+
99
+ - The module releases the GIL (Global Interpreter Lock) during intensive hash operations, enabling true parallelism in multi-threaded applications.
100
+ - The Rust implementation provides memory and type safety without performance overhead.
101
+ - Compatible with all major platforms: Linux, Windows, and macOS.
102
+
103
+ ## When to Use devlacruz_hashlib vs Standard hashlib
104
+
105
+ Use devlacruz_hashlib when:
106
+ - Maximum performance is needed for SHA-256 hash operations
107
+ - Working with large volumes of data
108
+ - Performing hash operations in critical loops
109
+ - Utilizing multi-threaded processing where releasing the GIL is advantageous
110
+
111
+ Use standard `hashlib` when:
112
+ - Other algorithms besides SHA-256 are needed
113
+ - Simplicity and maintainability are more important than performance
114
+ - Avoiding additional dependencies is preferred
115
+
116
+ ## Contributions
117
+
118
+ Contributions are welcome. To contribute:
119
+
120
+ 1. Fork the repository
121
+ 2. Create a branch for your feature (`git checkout -b new-feature`)
122
+ 3. Make your changes and commit (`git commit -am 'Add new feature'`)
123
+ 4. Push your changes (`git push origin new-feature`)
124
+ 5. Create a Pull Request
125
+
126
+ ## License
127
+
128
+ MIT License - See the LICENSE file for more details.
129
+
130
+ ## Author
131
+
132
+ Alejandro De La Cruz (devlacruz@axtosys.com)
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.0"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "devlacruz_hashlib"
7
+ version = "0.1.0"
8
+ description = "Extensión de hashing SHA-256 acelerado con Rust y PyO3"
9
+ authors = [{ name = "Alejandro De La Cruz", email = "devlacruz@axtosys.com" }]
10
+ license = "MIT"
11
+ requires-python = ">=3.7,<4.0"
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "Programming Language :: Python :: 3.7",
15
+ "Programming Language :: Python :: 3.8",
16
+ "Programming Language :: Python :: 3.9",
17
+ "Programming Language :: Python :: 3.10",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Programming Language :: Rust",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Operating System :: OS Independent",
24
+ "Topic :: Security :: Cryptography",
25
+ ]
26
+ readme = "README.md"
27
+
28
+ [tool.maturin]
29
+ bindings = "pyo3"
30
+ strip = true
@@ -0,0 +1,56 @@
1
+ use hex;
2
+ use pyo3::prelude::*;
3
+ use sha2::{Digest, Sha256};
4
+
5
+ /// Hash SHA-256 de un entero sin liberar el GIL
6
+ #[pyfunction]
7
+ fn hash_id_simple(x: u32) -> String {
8
+ let mut hasher = Sha256::new();
9
+ hasher.update(x.to_be_bytes());
10
+ hex::encode(hasher.finalize())
11
+ }
12
+
13
+ /// Hash SHA-256 de un entero, liberando el GIL durante el cálculo
14
+ #[pyfunction]
15
+ fn hash_id(py: Python<'_>, x: u32) -> PyResult<String> {
16
+ // convertimos a bytes antes de soltar el GIL
17
+ let bytes = x.to_be_bytes();
18
+ py.allow_threads(move || {
19
+ let mut hasher = Sha256::new();
20
+ hasher.update(bytes);
21
+ Ok(hex::encode(hasher.finalize()))
22
+ })
23
+ }
24
+
25
+ /// Hash SHA-256 de una cadena UTF-8, liberando el GIL
26
+ #[pyfunction]
27
+ fn hash_string(py: Python<'_>, s: &str) -> PyResult<String> {
28
+ let data = s.as_bytes().to_vec();
29
+ py.allow_threads(move || {
30
+ let mut hasher = Sha256::new();
31
+ hasher.update(&data);
32
+ Ok(hex::encode(hasher.finalize()))
33
+ })
34
+ }
35
+
36
+ /// Hash SHA-256 de cualquier buffer de bytes (`bytes` de Python), liberando el GIL
37
+ #[pyfunction]
38
+ fn hash_bytes(py: Python<'_>, data: &[u8]) -> PyResult<String> {
39
+ // data ya es &[u8], podemos soltar el GIL directamente
40
+ let data_vec = data.to_vec(); // Clone data for thread safety
41
+ py.allow_threads(move || {
42
+ let mut hasher = Sha256::new();
43
+ hasher.update(&data_vec);
44
+ Ok(hex::encode(hasher.finalize()))
45
+ })
46
+ }
47
+
48
+ /// Inicialización del módulo Python
49
+ #[pymodule]
50
+ fn myhashlib(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
51
+ m.add_function(wrap_pyfunction!(hash_id_simple, m)?)?;
52
+ m.add_function(wrap_pyfunction!(hash_id, m)?)?;
53
+ m.add_function(wrap_pyfunction!(hash_string, m)?)?;
54
+ m.add_function(wrap_pyfunction!(hash_bytes, m)?)?;
55
+ Ok(())
56
+ }