blake3-rb 1.5.3 → 1.5.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77b0fb01f8b1ded46a5a83b60aaf0ccba5c8821403f70f5d5e50da750eff9113
4
- data.tar.gz: 740322a742612194a0ca8bcc982f1fee5ca38dbfc18454a34b890238bb8445a3
3
+ metadata.gz: 79bfa02f801439d4336e9cc5d1c6f66b3fea5ee900fa327c98a76006289610cb
4
+ data.tar.gz: a84aff893fc9fb311103464071c2628fe398feb370f8afb2092c8a72663fd473
5
5
  SHA512:
6
- metadata.gz: ec33035fe66f3cfa9550d620247433667ee85b1dab9c80b8181651b4c5a86f25615e188a019ab1a2dcbd600f179d452a5ccf0a0ad44767d55b65e34b978af816
7
- data.tar.gz: 3b92bef5c85411077da1bd2eefbddfa92d20f2d6ea8e5be51e15106cae4e223ebc561e58a720cd8af95ac27799c558a5332209c06bfd1c11f771383614c2bd0e
6
+ metadata.gz: f55aad4696d2c13f956472e3193c68501fef7f1a698d86757bb251d533c6a44d2799d24842053e49ddab0f2ca01462d34583daf8fd9a61513a0341ac0bfde95c
7
+ data.tar.gz: 06ffcdbc95270b3ae7b3b7a9ff242cd5cb9388aef94d8e7fcfc669d24e357d2913b09f1566eb24785c55e39044fa971c342eb97dfee343f16bc8161e13434e06
data/Cargo.lock CHANGED
@@ -4,9 +4,9 @@ version = 3
4
4
 
5
5
  [[package]]
6
6
  name = "aho-corasick"
7
- version = "1.1.2"
7
+ version = "1.1.3"
8
8
  source = "registry+https://github.com/rust-lang/crates.io-index"
9
- checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
9
+ checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
10
10
  dependencies = [
11
11
  "memchr",
12
12
  ]
@@ -25,16 +25,16 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
25
25
 
26
26
  [[package]]
27
27
  name = "bindgen"
28
- version = "0.66.1"
28
+ version = "0.69.4"
29
29
  source = "registry+https://github.com/rust-lang/crates.io-index"
30
- checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7"
30
+ checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
31
31
  dependencies = [
32
32
  "bitflags",
33
33
  "cexpr",
34
34
  "clang-sys",
35
+ "itertools",
35
36
  "lazy_static",
36
37
  "lazycell",
37
- "peeking_take_while",
38
38
  "proc-macro2",
39
39
  "quote",
40
40
  "regex",
@@ -45,15 +45,15 @@ dependencies = [
45
45
 
46
46
  [[package]]
47
47
  name = "bitflags"
48
- version = "2.4.1"
48
+ version = "2.5.0"
49
49
  source = "registry+https://github.com/rust-lang/crates.io-index"
50
- checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
50
+ checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
51
51
 
52
52
  [[package]]
53
53
  name = "blake3"
54
- version = "1.5.0"
54
+ version = "1.5.1"
55
55
  source = "registry+https://github.com/rust-lang/crates.io-index"
56
- checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87"
56
+ checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52"
57
57
  dependencies = [
58
58
  "arrayref",
59
59
  "arrayvec",
@@ -67,17 +67,18 @@ name = "blake3_ext"
67
67
  version = "0.1.0"
68
68
  dependencies = [
69
69
  "blake3",
70
+ "hex",
71
+ "rand",
70
72
  "rb-sys",
73
+ "rb-sys-env",
74
+ "rb-sys-test-helpers",
71
75
  ]
72
76
 
73
77
  [[package]]
74
78
  name = "cc"
75
- version = "1.0.83"
79
+ version = "1.0.97"
76
80
  source = "registry+https://github.com/rust-lang/crates.io-index"
77
- checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
78
- dependencies = [
79
- "libc",
80
- ]
81
+ checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4"
81
82
 
82
83
  [[package]]
83
84
  name = "cexpr"
@@ -96,9 +97,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
96
97
 
97
98
  [[package]]
98
99
  name = "clang-sys"
99
- version = "1.6.1"
100
+ version = "1.7.0"
100
101
  source = "registry+https://github.com/rust-lang/crates.io-index"
101
- checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
102
+ checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1"
102
103
  dependencies = [
103
104
  "glob",
104
105
  "libc",
@@ -111,12 +112,44 @@ version = "0.3.0"
111
112
  source = "registry+https://github.com/rust-lang/crates.io-index"
112
113
  checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
113
114
 
115
+ [[package]]
116
+ name = "either"
117
+ version = "1.11.0"
118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
119
+ checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"
120
+
121
+ [[package]]
122
+ name = "getrandom"
123
+ version = "0.2.15"
124
+ source = "registry+https://github.com/rust-lang/crates.io-index"
125
+ checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
126
+ dependencies = [
127
+ "cfg-if",
128
+ "libc",
129
+ "wasi",
130
+ ]
131
+
114
132
  [[package]]
115
133
  name = "glob"
116
134
  version = "0.3.1"
117
135
  source = "registry+https://github.com/rust-lang/crates.io-index"
118
136
  checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
119
137
 
138
+ [[package]]
139
+ name = "hex"
140
+ version = "0.4.3"
141
+ source = "registry+https://github.com/rust-lang/crates.io-index"
142
+ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
143
+
144
+ [[package]]
145
+ name = "itertools"
146
+ version = "0.12.1"
147
+ source = "registry+https://github.com/rust-lang/crates.io-index"
148
+ checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
149
+ dependencies = [
150
+ "either",
151
+ ]
152
+
120
153
  [[package]]
121
154
  name = "lazy_static"
122
155
  version = "1.4.0"
@@ -131,25 +164,25 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
131
164
 
132
165
  [[package]]
133
166
  name = "libc"
134
- version = "0.2.149"
167
+ version = "0.2.154"
135
168
  source = "registry+https://github.com/rust-lang/crates.io-index"
136
- checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
169
+ checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
137
170
 
138
171
  [[package]]
139
172
  name = "libloading"
140
- version = "0.7.4"
173
+ version = "0.8.3"
141
174
  source = "registry+https://github.com/rust-lang/crates.io-index"
142
- checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
175
+ checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
143
176
  dependencies = [
144
177
  "cfg-if",
145
- "winapi",
178
+ "windows-targets",
146
179
  ]
147
180
 
148
181
  [[package]]
149
182
  name = "memchr"
150
- version = "2.6.4"
183
+ version = "2.7.2"
151
184
  source = "registry+https://github.com/rust-lang/crates.io-index"
152
- checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
185
+ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
153
186
 
154
187
  [[package]]
155
188
  name = "minimal-lexical"
@@ -168,43 +201,73 @@ dependencies = [
168
201
  ]
169
202
 
170
203
  [[package]]
171
- name = "peeking_take_while"
172
- version = "0.1.2"
204
+ name = "ppv-lite86"
205
+ version = "0.2.17"
173
206
  source = "registry+https://github.com/rust-lang/crates.io-index"
174
- checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
207
+ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
175
208
 
176
209
  [[package]]
177
210
  name = "proc-macro2"
178
- version = "1.0.69"
211
+ version = "1.0.82"
179
212
  source = "registry+https://github.com/rust-lang/crates.io-index"
180
- checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
213
+ checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b"
181
214
  dependencies = [
182
215
  "unicode-ident",
183
216
  ]
184
217
 
185
218
  [[package]]
186
219
  name = "quote"
187
- version = "1.0.33"
220
+ version = "1.0.36"
188
221
  source = "registry+https://github.com/rust-lang/crates.io-index"
189
- checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
222
+ checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
190
223
  dependencies = [
191
224
  "proc-macro2",
192
225
  ]
193
226
 
227
+ [[package]]
228
+ name = "rand"
229
+ version = "0.8.5"
230
+ source = "registry+https://github.com/rust-lang/crates.io-index"
231
+ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
232
+ dependencies = [
233
+ "libc",
234
+ "rand_chacha",
235
+ "rand_core",
236
+ ]
237
+
238
+ [[package]]
239
+ name = "rand_chacha"
240
+ version = "0.3.1"
241
+ source = "registry+https://github.com/rust-lang/crates.io-index"
242
+ checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
243
+ dependencies = [
244
+ "ppv-lite86",
245
+ "rand_core",
246
+ ]
247
+
248
+ [[package]]
249
+ name = "rand_core"
250
+ version = "0.6.4"
251
+ source = "registry+https://github.com/rust-lang/crates.io-index"
252
+ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
253
+ dependencies = [
254
+ "getrandom",
255
+ ]
256
+
194
257
  [[package]]
195
258
  name = "rb-sys"
196
- version = "0.9.82"
259
+ version = "0.9.97"
197
260
  source = "registry+https://github.com/rust-lang/crates.io-index"
198
- checksum = "a3e6bf79bf4c711917cacfaf46dfab4314dbfdd89a8ee3ec4b98336cd23f1ebf"
261
+ checksum = "47d30bcad206b51f2f66121190ca678dce1fdf3a2eae0ac5d838d1818b19bdf5"
199
262
  dependencies = [
200
263
  "rb-sys-build",
201
264
  ]
202
265
 
203
266
  [[package]]
204
267
  name = "rb-sys-build"
205
- version = "0.9.82"
268
+ version = "0.9.97"
206
269
  source = "registry+https://github.com/rust-lang/crates.io-index"
207
- checksum = "5482a1ed4cde58dddaf162b6aebcb5c25645822547832b8be101f2acd40bcdd6"
270
+ checksum = "3cbd92f281615f3c2dcb9dcb0f0576624752afbf9a7f99173b37c4b55b62dd8a"
208
271
  dependencies = [
209
272
  "bindgen",
210
273
  "lazy_static",
@@ -215,11 +278,38 @@ dependencies = [
215
278
  "syn",
216
279
  ]
217
280
 
281
+ [[package]]
282
+ name = "rb-sys-env"
283
+ version = "0.1.2"
284
+ source = "registry+https://github.com/rust-lang/crates.io-index"
285
+ checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
286
+
287
+ [[package]]
288
+ name = "rb-sys-test-helpers"
289
+ version = "0.2.0"
290
+ source = "registry+https://github.com/rust-lang/crates.io-index"
291
+ checksum = "bbd592029353df7955a76ca0b1bf0d9ccc57feab96615f80d1fe756462864949"
292
+ dependencies = [
293
+ "rb-sys",
294
+ "rb-sys-env",
295
+ "rb-sys-test-helpers-macros",
296
+ ]
297
+
298
+ [[package]]
299
+ name = "rb-sys-test-helpers-macros"
300
+ version = "0.2.0"
301
+ source = "registry+https://github.com/rust-lang/crates.io-index"
302
+ checksum = "c21f156459adb755d58f73dbd783dc1de8b403635e637f7d1daec1c7a920c1f5"
303
+ dependencies = [
304
+ "quote",
305
+ "syn",
306
+ ]
307
+
218
308
  [[package]]
219
309
  name = "regex"
220
- version = "1.10.2"
310
+ version = "1.10.4"
221
311
  source = "registry+https://github.com/rust-lang/crates.io-index"
222
- checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
312
+ checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
223
313
  dependencies = [
224
314
  "aho-corasick",
225
315
  "memchr",
@@ -229,9 +319,9 @@ dependencies = [
229
319
 
230
320
  [[package]]
231
321
  name = "regex-automata"
232
- version = "0.4.3"
322
+ version = "0.4.6"
233
323
  source = "registry+https://github.com/rust-lang/crates.io-index"
234
- checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
324
+ checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
235
325
  dependencies = [
236
326
  "aho-corasick",
237
327
  "memchr",
@@ -240,9 +330,9 @@ dependencies = [
240
330
 
241
331
  [[package]]
242
332
  name = "regex-syntax"
243
- version = "0.8.2"
333
+ version = "0.8.3"
244
334
  source = "registry+https://github.com/rust-lang/crates.io-index"
245
- checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
335
+ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
246
336
 
247
337
  [[package]]
248
338
  name = "rustc-hash"
@@ -258,15 +348,15 @@ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
258
348
 
259
349
  [[package]]
260
350
  name = "shlex"
261
- version = "1.2.0"
351
+ version = "1.3.0"
262
352
  source = "registry+https://github.com/rust-lang/crates.io-index"
263
- checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
353
+ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
264
354
 
265
355
  [[package]]
266
356
  name = "syn"
267
- version = "2.0.38"
357
+ version = "2.0.64"
268
358
  source = "registry+https://github.com/rust-lang/crates.io-index"
269
- checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
359
+ checksum = "7ad3dee41f36859875573074334c200d1add8e4a87bb37113ebd31d926b7b11f"
270
360
  dependencies = [
271
361
  "proc-macro2",
272
362
  "quote",
@@ -280,23 +370,71 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
280
370
  checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
281
371
 
282
372
  [[package]]
283
- name = "winapi"
284
- version = "0.3.9"
373
+ name = "wasi"
374
+ version = "0.11.0+wasi-snapshot-preview1"
375
+ source = "registry+https://github.com/rust-lang/crates.io-index"
376
+ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
377
+
378
+ [[package]]
379
+ name = "windows-targets"
380
+ version = "0.52.5"
285
381
  source = "registry+https://github.com/rust-lang/crates.io-index"
286
- checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
382
+ checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
287
383
  dependencies = [
288
- "winapi-i686-pc-windows-gnu",
289
- "winapi-x86_64-pc-windows-gnu",
384
+ "windows_aarch64_gnullvm",
385
+ "windows_aarch64_msvc",
386
+ "windows_i686_gnu",
387
+ "windows_i686_gnullvm",
388
+ "windows_i686_msvc",
389
+ "windows_x86_64_gnu",
390
+ "windows_x86_64_gnullvm",
391
+ "windows_x86_64_msvc",
290
392
  ]
291
393
 
292
394
  [[package]]
293
- name = "winapi-i686-pc-windows-gnu"
294
- version = "0.4.0"
395
+ name = "windows_aarch64_gnullvm"
396
+ version = "0.52.5"
397
+ source = "registry+https://github.com/rust-lang/crates.io-index"
398
+ checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
399
+
400
+ [[package]]
401
+ name = "windows_aarch64_msvc"
402
+ version = "0.52.5"
403
+ source = "registry+https://github.com/rust-lang/crates.io-index"
404
+ checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
405
+
406
+ [[package]]
407
+ name = "windows_i686_gnu"
408
+ version = "0.52.5"
409
+ source = "registry+https://github.com/rust-lang/crates.io-index"
410
+ checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
411
+
412
+ [[package]]
413
+ name = "windows_i686_gnullvm"
414
+ version = "0.52.5"
415
+ source = "registry+https://github.com/rust-lang/crates.io-index"
416
+ checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
417
+
418
+ [[package]]
419
+ name = "windows_i686_msvc"
420
+ version = "0.52.5"
421
+ source = "registry+https://github.com/rust-lang/crates.io-index"
422
+ checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
423
+
424
+ [[package]]
425
+ name = "windows_x86_64_gnu"
426
+ version = "0.52.5"
427
+ source = "registry+https://github.com/rust-lang/crates.io-index"
428
+ checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
429
+
430
+ [[package]]
431
+ name = "windows_x86_64_gnullvm"
432
+ version = "0.52.5"
295
433
  source = "registry+https://github.com/rust-lang/crates.io-index"
296
- checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
434
+ checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
297
435
 
298
436
  [[package]]
299
- name = "winapi-x86_64-pc-windows-gnu"
300
- version = "0.4.0"
437
+ name = "windows_x86_64_msvc"
438
+ version = "0.52.5"
301
439
  source = "registry+https://github.com/rust-lang/crates.io-index"
302
- checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
440
+ checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
data/Cargo.toml CHANGED
@@ -10,3 +10,4 @@ resolver = "2"
10
10
  lto = true
11
11
  opt-level = 3
12
12
  codegen-units = 1
13
+ debug = true
@@ -10,5 +10,13 @@ publish = false
10
10
  crate-type = ["cdylib"]
11
11
 
12
12
  [dependencies]
13
- rb-sys = { version = "0.9.82", features = ["stable-api-compiled-fallback"] }
14
- blake3 = { version = "1.5.0" }
13
+ rb-sys = { version = "0.9", features = ["stable-api-compiled-fallback"] }
14
+ blake3 = { version = "1.5" }
15
+
16
+ [dev-dependencies]
17
+ hex = "0.4.3"
18
+ rand = "0.8.5"
19
+ rb-sys-test-helpers = "0.2.0"
20
+
21
+ [build-dependencies]
22
+ rb-sys-env = "0.1.2"
@@ -0,0 +1,4 @@
1
+ fn main() -> Result<(), Box<dyn std::error::Error>> {
2
+ rb_sys_env::activate()?;
3
+ Ok(())
4
+ }
@@ -5,57 +5,61 @@ use rb_sys::{
5
5
  rb_cObject, rb_const_get, rb_define_class_under, rb_intern, rb_ivar_set, rb_require, size_t,
6
6
  };
7
7
  use std::ffi::{c_int, c_uchar, c_void};
8
+ use std::mem::MaybeUninit;
8
9
  use std::os::raw::c_char;
9
10
 
10
11
  use bindings::{rb_digest_make_metadata, RbDigestMetadataT, RUBY_DIGEST_API_VERSION};
11
12
 
12
- const BLOCK_LEN: usize = 64;
13
- const DIGEST_LEN: usize = 32;
14
-
15
13
  #[repr(C)]
16
- #[derive(Debug)]
17
- struct Blake3Ctx {
18
- inner: Option<Hasher>,
14
+ #[derive(Debug, Default)]
15
+ struct Blake3 {
16
+ hasher: Hasher,
19
17
  }
20
18
 
21
- static DIGEST_METADATA: RbDigestMetadataT = RbDigestMetadataT {
22
- api_version: RUBY_DIGEST_API_VERSION,
23
- digest_len: DIGEST_LEN as _,
24
- block_len: BLOCK_LEN as _,
25
- ctx_size: std::mem::size_of::<Blake3Ctx>() as _,
26
- init_func: blake3_init,
27
- update_func: blake3_update,
28
- finish_func: blake3_finish,
29
- };
19
+ impl Blake3 {
20
+ const BLOCK_LEN: usize = 64;
21
+ const DIGEST_LEN: usize = 32;
30
22
 
31
- // Initialize the context, which has already been allocated by Ruby.
32
- extern "C" fn blake3_init(ctx: *mut c_void) -> c_int {
33
- let ctx = ctx as *mut Blake3Ctx;
34
- let ctx = unsafe { &mut *ctx };
35
- ctx.inner = Some(Hasher::new());
36
- 1
37
- }
23
+ fn digest_metadata() -> &'static RbDigestMetadataT {
24
+ static DIGEST_METADATA: RbDigestMetadataT = RbDigestMetadataT {
25
+ api_version: RUBY_DIGEST_API_VERSION,
26
+ digest_len: Blake3::DIGEST_LEN as _,
27
+ block_len: Blake3::BLOCK_LEN as _,
28
+ ctx_size: std::mem::size_of::<Blake3>() as _,
29
+ init_func: Blake3::init_in_place,
30
+ update_func: Blake3::update,
31
+ finish_func: Blake3::finish,
32
+ };
33
+ &DIGEST_METADATA
34
+ }
38
35
 
39
- // Update the context with the given data.
40
- extern "C" fn blake3_update(ctx: *mut c_void, data: *mut c_uchar, len: size_t) {
41
- let ctx = ctx as *mut Blake3Ctx;
42
- let ctx = unsafe { &mut *ctx };
43
- if let Some(inner) = ctx.inner.as_mut() {
36
+ // Initialize the context, which has already been allocated by Ruby.
37
+ extern "C" fn init_in_place(ctx: *mut c_void) -> c_int {
38
+ let ctx = ctx as *mut MaybeUninit<Blake3>;
39
+ let ctx = unsafe { &mut *ctx };
40
+ ctx.write(Blake3::default());
41
+ true as _
42
+ }
43
+
44
+ // Update the context with the given data.
45
+ extern "C" fn update(ctx: *mut c_void, data: *mut c_uchar, len: size_t) {
46
+ let ctx = ctx as *mut MaybeUninit<Blake3>;
47
+ let ctx = unsafe { &mut *ctx };
48
+ let ctx = unsafe { ctx.assume_init_mut() };
44
49
  let slice = unsafe { std::slice::from_raw_parts(data, len as _) };
45
- inner.update(slice);
50
+
51
+ ctx.hasher.update(slice);
46
52
  }
47
- }
48
53
 
49
- // Finalize the context and write the digest to the given pointer.
50
- extern "C" fn blake3_finish(ctx: *mut c_void, digest: *mut c_uchar) -> c_int {
51
- let ctx = ctx as *mut Blake3Ctx;
52
- let ctx = unsafe { &mut *ctx };
53
- if let Some(inner) = ctx.inner.as_mut() {
54
- let slice = unsafe { std::slice::from_raw_parts_mut(digest, DIGEST_LEN) };
55
- inner.finalize_xof().fill(slice);
56
- 1
57
- } else {
58
- 0
54
+ // Finalize the context and write the digest to the given pointer. The
55
+ // memory for the digest is managed by Ruby, so we don't need to free it.
56
+ extern "C" fn finish(ctx: *mut c_void, digest: *mut c_uchar) -> c_int {
57
+ let ctx = ctx as *mut MaybeUninit<Blake3>;
58
+ let ctx = unsafe { &mut *ctx };
59
+ let ctx = unsafe { ctx.assume_init_mut() };
60
+ let outbuf = unsafe { std::slice::from_raw_parts_mut(digest, Self::DIGEST_LEN) };
61
+ ctx.hasher.finalize_xof().fill(outbuf);
62
+ true as _
59
63
  }
60
64
  }
61
65
 
@@ -71,7 +75,101 @@ pub unsafe extern "C" fn Init_blake3_ext() {
71
75
  "Blake3\0".as_ptr() as *const c_char,
72
76
  digest_base,
73
77
  );
74
- let meta = rb_digest_make_metadata(&DIGEST_METADATA);
78
+ let meta = rb_digest_make_metadata(Blake3::digest_metadata());
75
79
  let metadata_id = rb_intern("metadata\0".as_ptr() as *const c_char);
76
80
  rb_ivar_set(klass, metadata_id, meta);
77
81
  }
82
+
83
+ #[cfg(test)]
84
+ mod tests {
85
+ use rb_sys::{
86
+ rb_cObject, rb_const_get, rb_enc_set_index, rb_funcallv_public, rb_intern, rb_str_new,
87
+ rb_utf8_encindex, RSTRING_LEN, RSTRING_PTR,
88
+ };
89
+ use rb_sys_test_helpers::{protect, ruby_test};
90
+
91
+ use crate::Init_blake3_ext;
92
+
93
+ #[ruby_test]
94
+ fn fuzz_parity_binary() {
95
+ setup();
96
+
97
+ for _ in 0..1024 {
98
+ let input_data = gen_random_bytes(4096);
99
+ let expected = compute_rust_digest(input_data.as_slice());
100
+ let actual = compute_ruby_digest(input_data.as_slice(), rb_utf8_encindex);
101
+
102
+ assert_eq!(expected, actual);
103
+ }
104
+ }
105
+
106
+ #[ruby_test]
107
+ fn fuzz_parity_utf8() {
108
+ setup();
109
+
110
+ for _ in 0..1024 {
111
+ let input_data = gen_random_string(512);
112
+ let expected = compute_rust_digest(&input_data);
113
+ let actual = compute_ruby_digest(&input_data, rb_utf8_encindex);
114
+
115
+ assert_eq!(expected, actual);
116
+ }
117
+ }
118
+
119
+ fn setup() {
120
+ static INIT: std::sync::Once = std::sync::Once::new();
121
+ INIT.call_once(|| {
122
+ protect(|| unsafe { Init_blake3_ext() })
123
+ .expect("Failed to initialize Blake3 extension");
124
+ });
125
+ }
126
+
127
+ fn gen_random_bytes(max_len: usize) -> Vec<u8> {
128
+ let size = rand::random::<usize>() % max_len;
129
+ (0..size).map(|_| rand::random::<u8>()).collect()
130
+ }
131
+
132
+ fn gen_random_string(max_len: usize) -> String {
133
+ let size = rand::random::<usize>() % max_len;
134
+ (0..size)
135
+ .map(|_| rand::random::<char>())
136
+ .collect::<String>()
137
+ }
138
+
139
+ fn compute_rust_digest<T: AsRef<[u8]>>(input: T) -> String {
140
+ let mut hasher = blake3::Hasher::new();
141
+ hasher.update(input.as_ref());
142
+ let mut result = [0u8; 32];
143
+ hasher.finalize_xof().fill(&mut result);
144
+ hex::encode(result)
145
+ }
146
+
147
+ fn compute_ruby_digest<T: AsRef<[u8]>>(
148
+ input: T,
149
+ encoding: unsafe extern "C" fn() -> i32,
150
+ ) -> String {
151
+ let input = input.as_ref();
152
+ let ruby_digest = protect(|| unsafe {
153
+ Init_blake3_ext();
154
+ let klass = rb_const_get(rb_cObject, rb_intern("Digest\0".as_ptr() as _));
155
+ let klass = rb_const_get(klass, rb_intern("Blake3\0".as_ptr() as _));
156
+ let string = rb_str_new(input.as_ptr() as _, input.len() as _);
157
+ rb_enc_set_index(string, encoding());
158
+ let mut args = [string];
159
+ rb_funcallv_public(
160
+ klass,
161
+ rb_intern("hexdigest\0".as_ptr() as _),
162
+ args.len() as _,
163
+ args.as_mut_ptr(),
164
+ )
165
+ })
166
+ .unwrap();
167
+
168
+ let rstring_ptr = unsafe { RSTRING_PTR(ruby_digest) };
169
+ let rstring_len = unsafe { RSTRING_LEN(ruby_digest) };
170
+
171
+ let bytes =
172
+ unsafe { std::slice::from_raw_parts(rstring_ptr as *const u8, rstring_len as _) };
173
+ std::str::from_utf8(bytes).unwrap().to_string()
174
+ }
175
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blake3-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-17 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys
@@ -36,6 +36,7 @@ files:
36
36
  - LICENSE.txt
37
37
  - README.md
38
38
  - ext/digest/blake3_ext/Cargo.toml
39
+ - ext/digest/blake3_ext/build.rs
39
40
  - ext/digest/blake3_ext/extconf.rb
40
41
  - ext/digest/blake3_ext/src/bindings.rs
41
42
  - ext/digest/blake3_ext/src/lib.rs
@@ -63,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  - !ruby/object:Gem::Version
64
65
  version: '0'
65
66
  requirements: []
66
- rubygems_version: 3.4.10
67
+ rubygems_version: 3.4.19
67
68
  signing_key:
68
69
  specification_version: 4
69
70
  summary: Blake3 hash function bindings for Ruby.