proofmode 0.14.0-x86_64-linux

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.
data/lib/proofmode.rb ADDED
@@ -0,0 +1,4565 @@
1
+ # This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+ # Trust me, you don't want to mess with it!
3
+
4
+ # Common helper code.
5
+ #
6
+ # Ideally this would live in a separate .rb file where it can be unittested etc
7
+ # in isolation, and perhaps even published as a re-useable package.
8
+ #
9
+ # However, it's important that the details of how this helper code works (e.g. the
10
+ # way that different builtin types are passed across the FFI) exactly match what's
11
+ # expected by the rust code on the other side of the interface. In practice right
12
+ # now that means coming from the exact some version of `uniffi` that was used to
13
+ # compile the rust component. The easiest way to ensure this is to bundle the Ruby
14
+ # helpers directly inline like we're doing here.
15
+
16
+ require 'ffi'
17
+ require 'set'
18
+ require 'monitor'
19
+
20
+ module Proofmode
21
+ def self.uniffi_in_range(i, type_name, min, max)
22
+ raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
23
+ i = i.to_int
24
+ raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
25
+ i
26
+ end
27
+
28
+ def self.uniffi_utf8(v)
29
+ raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
30
+ v = v.to_str.encode(Encoding::UTF_8)
31
+ raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
32
+ v
33
+ end
34
+
35
+ def self.uniffi_bytes(v)
36
+ raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
37
+ v.to_str
38
+ end
39
+
40
+ # Callback return codes
41
+ UNIFFI_CALLBACK_SUCCESS = 0
42
+ UNIFFI_CALLBACK_ERROR = 1
43
+ UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2
44
+
45
+ # Call a method on a callback interface object, catching and reporting errors
46
+ # to Rust via the call_status.
47
+ # If error_class is provided, known errors of that type are reported as UNIFFI_CALLBACK_ERROR;
48
+ # all other errors are reported as UNIFFI_CALLBACK_UNEXPECTED_ERROR.
49
+ def self.uniffi_trait_interface_call(call_status, make_call, write_return_value, error_class = nil, lower_error = nil)
50
+ begin
51
+ write_return_value.call make_call.call
52
+ rescue StandardError => e
53
+ buf = if !error_class.nil? && uniffi_is_error_type?(e, error_class)
54
+ call_status[:code] = UNIFFI_CALLBACK_ERROR
55
+ lower_error.call e
56
+ else
57
+ call_status[:code] = UNIFFI_CALLBACK_UNEXPECTED_ERROR
58
+ RustBuffer.alloc_from_string(e.inspect)
59
+ end
60
+
61
+ error_buf = call_status[:error_buf]
62
+ error_buf[:capacity] = buf[:capacity]
63
+ error_buf[:len] = buf[:len]
64
+ error_buf[:data] = buf[:data]
65
+ end
66
+ end
67
+
68
+ # Check if an exception is a variant of the given error type.
69
+ # Error types in Ruby are either modules (non-flat enums) or classes (flat enums),
70
+ # with variant classes as constant within them.
71
+ # error_class should be the Ruby Class or Module constant (e.g. MyError
72
+ # for local errors, ::OtherModule::SomeError for external errors).
73
+ def self.uniffi_is_error_type?(e, error_class)
74
+ # Object-as-error: error_class is a class itself (e.g. MyError < StandardError)
75
+ if error_class.is_a?(Class) && e.is_a?(error_class)
76
+ return true
77
+ end
78
+
79
+ # Enum error: error_class is a module with class constants for each variant
80
+ error_class.constants.any? do |c|
81
+ klass = error_class.const_get c
82
+ klass.is_a?(Class) && e.is_a?(klass)
83
+ end
84
+ end
85
+ # A handle map for converting Ruby objects to/from integer handles.
86
+ #
87
+ # When passing callback interface or trait interface objects to Ruby, we store
88
+ # the Ruby object in this map and pass the integer handle to Rust. When Rust
89
+ # calls back, we look up the Ruby object by its handle.
90
+ #
91
+ # Ruby-created handles are always odd (staring at 1, incrementing by 2).
92
+ # Rust-created handles are always even. This convention lets us distinguish
93
+ # the source in lift/lower without extra metadata.
94
+
95
+
96
+ class UniffiHandleMap
97
+ def initialize
98
+ @lock = Monitor.new
99
+ @map = {}
100
+ @counter = 1 # Start at 1 (odd), increment by 2
101
+ end
102
+
103
+ def insert(obj)
104
+ @lock.synchronize do
105
+ handle = @counter
106
+ @counter += 2
107
+ @map[handle] = obj
108
+ handle
109
+ end
110
+ end
111
+
112
+ def get(handle)
113
+ @lock.synchronize do
114
+ obj = @map[handle]
115
+ raise InternalError, "UniffiHandleMap.get: invalid handle #{handle}" if obj.nil?
116
+ obj
117
+ end
118
+ end
119
+
120
+ def clone_handle(handle)
121
+ @lock.synchronize do
122
+ obj = @map[handle]
123
+ raise InternalError, "UniffiHandleMap.clone_handle: invalid handle #{handle}" if obj.nil?
124
+ new_handle = @counter
125
+ @counter += 2
126
+ @map[new_handle] = obj
127
+ new_handle
128
+ end
129
+ end
130
+
131
+ def remove(handle)
132
+ @lock.synchronize do
133
+ obj = @map.delete(handle)
134
+ raise InternalError, "UniffiHandleMap.remove: invalid handle #{handle}" if obj.nil?
135
+ obj
136
+ end
137
+ end
138
+
139
+ # Used for testing/debugging purposes
140
+ def size
141
+ @lock.synchronize { @map.size }
142
+ end
143
+ end
144
+
145
+ private_constant :UniffiHandleMap
146
+ class RustBuffer < FFI::Struct
147
+ layout :capacity, :uint64,
148
+ :len, :uint64,
149
+ :data, :pointer
150
+
151
+ def self.alloc(size)
152
+ return ::Proofmode.rust_call(:ffi_proofmode_rustbuffer_alloc, size)
153
+ end
154
+
155
+ def self.reserve(rbuf, additional)
156
+ return ::Proofmode.rust_call(:ffi_proofmode_rustbuffer_reserve, rbuf, additional)
157
+ end
158
+
159
+ def free
160
+ ::Proofmode.rust_call(:ffi_proofmode_rustbuffer_free, self)
161
+ end
162
+
163
+ def capacity
164
+ self[:capacity]
165
+ end
166
+
167
+ def len
168
+ self[:len]
169
+ end
170
+
171
+ def len=(value)
172
+ self[:len] = value
173
+ end
174
+
175
+ def data
176
+ self[:data]
177
+ end
178
+
179
+ def to_s
180
+ "RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})"
181
+ end
182
+
183
+ # The allocated buffer will be automatically freed if an error occurs, ensuring that
184
+ # we don't accidentally leak it.
185
+ def self.allocWithBuilder
186
+ builder = RustBufferBuilder.new
187
+
188
+ begin
189
+ yield builder
190
+ rescue => e
191
+ builder.discard
192
+ raise e
193
+ end
194
+ end
195
+
196
+ # The RustBuffer will be freed once the context-manager exits, ensuring that we don't
197
+ # leak it even if an error occurs.
198
+ def consumeWithStream
199
+ stream = RustBufferStream.new self
200
+
201
+ yield stream
202
+
203
+ raise RuntimeError, 'junk data left in buffer after consuming' if stream.remaining != 0
204
+ ensure
205
+ free
206
+ end# The primitive String type.
207
+
208
+ def self.alloc_from_string(value)
209
+ RustBuffer.allocWithBuilder do |builder|
210
+ builder.write value.encode('utf-8')
211
+ return builder.finalize
212
+ end
213
+ end
214
+
215
+ def consume_into_string
216
+ consumeWithStream do |stream|
217
+ return stream.read(stream.remaining).force_encoding(Encoding::UTF_8)
218
+ end
219
+ end
220
+
221
+ # The primitive Bytes type.
222
+
223
+ def self.alloc_from_bytes(value)
224
+ RustBuffer.allocWithBuilder do |builder|
225
+ ::Proofmode::RustBufferBuilderMixin.write_bytes(builder, value)
226
+ return builder.finalize
227
+ end
228
+ end
229
+
230
+ def consume_into_bytes
231
+ consumeWithStream do |stream|
232
+ return ::Proofmode::RustBufferStreamMixin.read_bytes(stream)
233
+ end
234
+ end
235
+
236
+ # The Record type C2paCredentials.
237
+
238
+ def self.check_lower_TypeC2paCredentials(v)
239
+
240
+
241
+ end
242
+
243
+ def self.alloc_from_TypeC2paCredentials(v)
244
+ RustBuffer.allocWithBuilder do |builder|
245
+ ::Proofmode::RustBufferBuilderMixin.write_TypeC2paCredentials(builder, v)
246
+ return builder.finalize
247
+ end
248
+ end
249
+
250
+ def consume_into_TypeC2paCredentials
251
+ consumeWithStream do |stream|
252
+ return ::Proofmode::RustBufferStreamMixin.read_TypeC2paCredentials(stream)
253
+ end
254
+ end
255
+
256
+ # The Record type CellInfo.
257
+
258
+ def self.check_lower_TypeCellInfo(v)
259
+
260
+ RustBuffer.check_lower_Optionalstring(v.cell_id)
261
+ RustBuffer.check_lower_Optionalstring(v.lac)
262
+ end
263
+
264
+ def self.alloc_from_TypeCellInfo(v)
265
+ RustBuffer.allocWithBuilder do |builder|
266
+ ::Proofmode::RustBufferBuilderMixin.write_TypeCellInfo(builder, v)
267
+ return builder.finalize
268
+ end
269
+ end
270
+
271
+ def consume_into_TypeCellInfo
272
+ consumeWithStream do |stream|
273
+ return ::Proofmode::RustBufferStreamMixin.read_TypeCellInfo(stream)
274
+ end
275
+ end
276
+
277
+ # The Record type CheckOptions.
278
+
279
+ def self.check_lower_TypeCheckOptions(v)
280
+ RustBuffer.check_lower_Optionalstring(v.c2pa_trust_anchors)
281
+ RustBuffer.check_lower_Optionalstring(v.cawg_trust_anchors)
282
+ RustBuffer.check_lower_Optionalstring(v.cawg_allowed_list)
283
+ RustBuffer.check_lower_OptionalTypeMediaReturn(v.media)
284
+ RustBuffer.check_lower_Optionalu32(v.thumbnail_max_dim)
285
+ RustBuffer.check_lower_Optionalstring(v.gateway)
286
+ RustBuffer.check_lower_Optionalu64(v.max_input_bytes)
287
+ end
288
+
289
+ def self.alloc_from_TypeCheckOptions(v)
290
+ RustBuffer.allocWithBuilder do |builder|
291
+ ::Proofmode::RustBufferBuilderMixin.write_TypeCheckOptions(builder, v)
292
+ return builder.finalize
293
+ end
294
+ end
295
+
296
+ def consume_into_TypeCheckOptions
297
+ consumeWithStream do |stream|
298
+ return ::Proofmode::RustBufferStreamMixin.read_TypeCheckOptions(stream)
299
+ end
300
+ end
301
+
302
+ # The Record type DeviceData.
303
+
304
+ def self.check_lower_TypeDeviceData(v)
305
+
306
+
307
+
308
+ RustBuffer.check_lower_Optionalstring(v.device_id)
309
+ end
310
+
311
+ def self.alloc_from_TypeDeviceData(v)
312
+ RustBuffer.allocWithBuilder do |builder|
313
+ ::Proofmode::RustBufferBuilderMixin.write_TypeDeviceData(builder, v)
314
+ return builder.finalize
315
+ end
316
+ end
317
+
318
+ def consume_into_TypeDeviceData
319
+ consumeWithStream do |stream|
320
+ return ::Proofmode::RustBufferStreamMixin.read_TypeDeviceData(stream)
321
+ end
322
+ end
323
+
324
+ # The Record type FileIndex.
325
+
326
+ def self.check_lower_TypeFileIndex(v)
327
+
328
+
329
+ end
330
+
331
+ def self.alloc_from_TypeFileIndex(v)
332
+ RustBuffer.allocWithBuilder do |builder|
333
+ ::Proofmode::RustBufferBuilderMixin.write_TypeFileIndex(builder, v)
334
+ return builder.finalize
335
+ end
336
+ end
337
+
338
+ def consume_into_TypeFileIndex
339
+ consumeWithStream do |stream|
340
+ return ::Proofmode::RustBufferStreamMixin.read_TypeFileIndex(stream)
341
+ end
342
+ end
343
+
344
+ # The Record type FileProofOptions.
345
+
346
+ def self.check_lower_TypeFileProofOptions(v)
347
+ RustBuffer.check_lower_Optionalstring(v.passphrase)
348
+ RustBuffer.check_lower_Optionalstring(v.email)
349
+ RustBuffer.check_lower_Optionalstring(v.description)
350
+ RustBuffer.check_lower_Optionalstring(v.location)
351
+ RustBuffer.check_lower_Optionalstring(v.event_type)
352
+ RustBuffer.check_lower_Optionalstring(v.tags)
353
+ RustBuffer.check_lower_OptionalTypeDigitalSourceType(v.digital_source_type)
354
+ RustBuffer.check_lower_OptionalTypeC2paCredentials(v.c2pa_credentials)
355
+ end
356
+
357
+ def self.alloc_from_TypeFileProofOptions(v)
358
+ RustBuffer.allocWithBuilder do |builder|
359
+ ::Proofmode::RustBufferBuilderMixin.write_TypeFileProofOptions(builder, v)
360
+ return builder.finalize
361
+ end
362
+ end
363
+
364
+ def consume_into_TypeFileProofOptions
365
+ consumeWithStream do |stream|
366
+ return ::Proofmode::RustBufferStreamMixin.read_TypeFileProofOptions(stream)
367
+ end
368
+ end
369
+
370
+ # The Record type HttpResponse.
371
+
372
+ def self.check_lower_TypeHttpResponse(v)
373
+
374
+ RustBuffer.check_lower_Optionalstring(v.content_type)
375
+
376
+ end
377
+
378
+ def self.alloc_from_TypeHttpResponse(v)
379
+ RustBuffer.allocWithBuilder do |builder|
380
+ ::Proofmode::RustBufferBuilderMixin.write_TypeHttpResponse(builder, v)
381
+ return builder.finalize
382
+ end
383
+ end
384
+
385
+ def consume_into_TypeHttpResponse
386
+ consumeWithStream do |stream|
387
+ return ::Proofmode::RustBufferStreamMixin.read_TypeHttpResponse(stream)
388
+ end
389
+ end
390
+
391
+ # The Record type LocationData.
392
+
393
+ def self.check_lower_TypeLocationData(v)
394
+
395
+
396
+ RustBuffer.check_lower_Optionalf64(v.altitude)
397
+ RustBuffer.check_lower_Optionalf64(v.accuracy)
398
+ RustBuffer.check_lower_Optionalstring(v.provider)
399
+ end
400
+
401
+ def self.alloc_from_TypeLocationData(v)
402
+ RustBuffer.allocWithBuilder do |builder|
403
+ ::Proofmode::RustBufferBuilderMixin.write_TypeLocationData(builder, v)
404
+ return builder.finalize
405
+ end
406
+ end
407
+
408
+ def consume_into_TypeLocationData
409
+ consumeWithStream do |stream|
410
+ return ::Proofmode::RustBufferStreamMixin.read_TypeLocationData(stream)
411
+ end
412
+ end
413
+
414
+ # The Record type NetworkData.
415
+
416
+ def self.check_lower_TypeNetworkData(v)
417
+
418
+ RustBuffer.check_lower_Optionalstring(v.wifi_ssid)
419
+ RustBuffer.check_lower_OptionalTypeCellInfo(v.cell_info)
420
+ end
421
+
422
+ def self.alloc_from_TypeNetworkData(v)
423
+ RustBuffer.allocWithBuilder do |builder|
424
+ ::Proofmode::RustBufferBuilderMixin.write_TypeNetworkData(builder, v)
425
+ return builder.finalize
426
+ end
427
+ end
428
+
429
+ def consume_into_TypeNetworkData
430
+ consumeWithStream do |stream|
431
+ return ::Proofmode::RustBufferStreamMixin.read_TypeNetworkData(stream)
432
+ end
433
+ end
434
+
435
+ # The Record type ProgressEvent.
436
+
437
+ def self.check_lower_TypeProgressEvent(v)
438
+ RustBuffer.check_lower_TypePhase(v.phase)
439
+
440
+ RustBuffer.check_lower_Optionalstring(v.detail)
441
+ RustBuffer.check_lower_OptionalTypeFileIndex(v.file)
442
+ end
443
+
444
+ def self.alloc_from_TypeProgressEvent(v)
445
+ RustBuffer.allocWithBuilder do |builder|
446
+ ::Proofmode::RustBufferBuilderMixin.write_TypeProgressEvent(builder, v)
447
+ return builder.finalize
448
+ end
449
+ end
450
+
451
+ def consume_into_TypeProgressEvent
452
+ consumeWithStream do |stream|
453
+ return ::Proofmode::RustBufferStreamMixin.read_TypeProgressEvent(stream)
454
+ end
455
+ end
456
+
457
+ # The Record type ProofModeConfig.
458
+
459
+ def self.check_lower_TypeProofModeConfig(v)
460
+
461
+
462
+
463
+
464
+
465
+
466
+ RustBuffer.check_lower_OptionalTypeDigitalSourceType(v.digital_source_type)
467
+ RustBuffer.check_lower_OptionalTypeC2paCredentials(v.c2pa_credentials)
468
+ end
469
+
470
+ def self.alloc_from_TypeProofModeConfig(v)
471
+ RustBuffer.allocWithBuilder do |builder|
472
+ ::Proofmode::RustBufferBuilderMixin.write_TypeProofModeConfig(builder, v)
473
+ return builder.finalize
474
+ end
475
+ end
476
+
477
+ def consume_into_TypeProofModeConfig
478
+ consumeWithStream do |stream|
479
+ return ::Proofmode::RustBufferStreamMixin.read_TypeProofModeConfig(stream)
480
+ end
481
+ end
482
+
483
+ # The Enum type DigitalSourceType.
484
+
485
+ def self.check_lower_TypeDigitalSourceType(v)
486
+ end
487
+
488
+ def self.alloc_from_TypeDigitalSourceType(v)
489
+ RustBuffer.allocWithBuilder do |builder|
490
+ ::Proofmode::RustBufferBuilderMixin.write_TypeDigitalSourceType(builder, v)
491
+ return builder.finalize
492
+ end
493
+ end
494
+
495
+ def consume_into_TypeDigitalSourceType
496
+ consumeWithStream do |stream|
497
+ return ::Proofmode::RustBufferStreamMixin.read_TypeDigitalSourceType(stream)
498
+ end
499
+ end
500
+
501
+ # The Enum type MediaReturn.
502
+
503
+ def self.check_lower_TypeMediaReturn(v)
504
+ end
505
+
506
+ def self.alloc_from_TypeMediaReturn(v)
507
+ RustBuffer.allocWithBuilder do |builder|
508
+ ::Proofmode::RustBufferBuilderMixin.write_TypeMediaReturn(builder, v)
509
+ return builder.finalize
510
+ end
511
+ end
512
+
513
+ def consume_into_TypeMediaReturn
514
+ consumeWithStream do |stream|
515
+ return ::Proofmode::RustBufferStreamMixin.read_TypeMediaReturn(stream)
516
+ end
517
+ end
518
+
519
+ # The Enum type Phase.
520
+
521
+ def self.check_lower_TypePhase(v)
522
+ end
523
+
524
+ def self.alloc_from_TypePhase(v)
525
+ RustBuffer.allocWithBuilder do |builder|
526
+ ::Proofmode::RustBufferBuilderMixin.write_TypePhase(builder, v)
527
+ return builder.finalize
528
+ end
529
+ end
530
+
531
+ def consume_into_TypePhase
532
+ consumeWithStream do |stream|
533
+ return ::Proofmode::RustBufferStreamMixin.read_TypePhase(stream)
534
+ end
535
+ end
536
+
537
+ # The Enum type ProofModeError.
538
+
539
+ def self.check_lower_TypeProofModeError(v)
540
+ if v.io?
541
+
542
+ return
543
+ end
544
+ if v.generation?
545
+
546
+ return
547
+ end
548
+ if v.check?
549
+
550
+ return
551
+ end
552
+ end
553
+
554
+ def self.alloc_from_TypeProofModeError(v)
555
+ RustBuffer.allocWithBuilder do |builder|
556
+ ::Proofmode::RustBufferBuilderMixin.write_TypeProofModeError(builder, v)
557
+ return builder.finalize
558
+ end
559
+ end
560
+
561
+ def consume_into_TypeProofModeError
562
+ consumeWithStream do |stream|
563
+ return ::Proofmode::RustBufferStreamMixin.read_TypeProofModeError(stream)
564
+ end
565
+ end
566
+
567
+ # The Enum type ProofSignerError.
568
+
569
+ def self.check_lower_TypeProofSignerError(v)
570
+ if v.empty_passphrase?
571
+ return
572
+ end
573
+ if v.wrong_passphrase?
574
+
575
+ return
576
+ end
577
+ if v.email_needed?
578
+
579
+ return
580
+ end
581
+ if v.cannot_sign?
582
+
583
+ return
584
+ end
585
+ if v.cannot_create?
586
+
587
+ return
588
+ end
589
+ if v.invalid_key?
590
+
591
+ return
592
+ end
593
+ if v.io?
594
+
595
+ return
596
+ end
597
+ end
598
+
599
+ def self.alloc_from_TypeProofSignerError(v)
600
+ RustBuffer.allocWithBuilder do |builder|
601
+ ::Proofmode::RustBufferBuilderMixin.write_TypeProofSignerError(builder, v)
602
+ return builder.finalize
603
+ end
604
+ end
605
+
606
+ def consume_into_TypeProofSignerError
607
+ consumeWithStream do |stream|
608
+ return ::Proofmode::RustBufferStreamMixin.read_TypeProofSignerError(stream)
609
+ end
610
+ end
611
+
612
+ # The Optional<T> type for u32.
613
+
614
+ def self.check_lower_Optionalu32(v)
615
+ if !v.nil?
616
+
617
+ end
618
+ end
619
+
620
+ def self.alloc_from_Optionalu32(v)
621
+ RustBuffer.allocWithBuilder do |builder|
622
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalu32(builder, v)
623
+ return builder.finalize()
624
+ end
625
+ end
626
+
627
+ def consume_into_Optionalu32
628
+ consumeWithStream do |stream|
629
+ return ::Proofmode::RustBufferStreamMixin.read_Optionalu32(stream)
630
+ end
631
+ end
632
+
633
+ # The Optional<T> type for u64.
634
+
635
+ def self.check_lower_Optionalu64(v)
636
+ if !v.nil?
637
+
638
+ end
639
+ end
640
+
641
+ def self.alloc_from_Optionalu64(v)
642
+ RustBuffer.allocWithBuilder do |builder|
643
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalu64(builder, v)
644
+ return builder.finalize()
645
+ end
646
+ end
647
+
648
+ def consume_into_Optionalu64
649
+ consumeWithStream do |stream|
650
+ return ::Proofmode::RustBufferStreamMixin.read_Optionalu64(stream)
651
+ end
652
+ end
653
+
654
+ # The Optional<T> type for f64.
655
+
656
+ def self.check_lower_Optionalf64(v)
657
+ if !v.nil?
658
+
659
+ end
660
+ end
661
+
662
+ def self.alloc_from_Optionalf64(v)
663
+ RustBuffer.allocWithBuilder do |builder|
664
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalf64(builder, v)
665
+ return builder.finalize()
666
+ end
667
+ end
668
+
669
+ def consume_into_Optionalf64
670
+ consumeWithStream do |stream|
671
+ return ::Proofmode::RustBufferStreamMixin.read_Optionalf64(stream)
672
+ end
673
+ end
674
+
675
+ # The Optional<T> type for string.
676
+
677
+ def self.check_lower_Optionalstring(v)
678
+ if !v.nil?
679
+
680
+ end
681
+ end
682
+
683
+ def self.alloc_from_Optionalstring(v)
684
+ RustBuffer.allocWithBuilder do |builder|
685
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v)
686
+ return builder.finalize()
687
+ end
688
+ end
689
+
690
+ def consume_into_Optionalstring
691
+ consumeWithStream do |stream|
692
+ return ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream)
693
+ end
694
+ end
695
+
696
+ # The Optional<T> type for bytes.
697
+
698
+ def self.check_lower_Optionalbytes(v)
699
+ if !v.nil?
700
+
701
+ end
702
+ end
703
+
704
+ def self.alloc_from_Optionalbytes(v)
705
+ RustBuffer.allocWithBuilder do |builder|
706
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalbytes(builder, v)
707
+ return builder.finalize()
708
+ end
709
+ end
710
+
711
+ def consume_into_Optionalbytes
712
+ consumeWithStream do |stream|
713
+ return ::Proofmode::RustBufferStreamMixin.read_Optionalbytes(stream)
714
+ end
715
+ end
716
+
717
+ # The Optional<T> type for TypeProgressListener.
718
+
719
+ def self.check_lower_OptionalTypeProgressListener(v)
720
+ if !v.nil?
721
+ (ProgressListener.uniffi_check_lower v)
722
+ end
723
+ end
724
+
725
+ def self.alloc_from_OptionalTypeProgressListener(v)
726
+ RustBuffer.allocWithBuilder do |builder|
727
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeProgressListener(builder, v)
728
+ return builder.finalize()
729
+ end
730
+ end
731
+
732
+ def consume_into_OptionalTypeProgressListener
733
+ consumeWithStream do |stream|
734
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeProgressListener(stream)
735
+ end
736
+ end
737
+
738
+ # The Optional<T> type for TypeC2paCredentials.
739
+
740
+ def self.check_lower_OptionalTypeC2paCredentials(v)
741
+ if !v.nil?
742
+ RustBuffer.check_lower_TypeC2paCredentials(v)
743
+ end
744
+ end
745
+
746
+ def self.alloc_from_OptionalTypeC2paCredentials(v)
747
+ RustBuffer.allocWithBuilder do |builder|
748
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeC2paCredentials(builder, v)
749
+ return builder.finalize()
750
+ end
751
+ end
752
+
753
+ def consume_into_OptionalTypeC2paCredentials
754
+ consumeWithStream do |stream|
755
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeC2paCredentials(stream)
756
+ end
757
+ end
758
+
759
+ # The Optional<T> type for TypeCellInfo.
760
+
761
+ def self.check_lower_OptionalTypeCellInfo(v)
762
+ if !v.nil?
763
+ RustBuffer.check_lower_TypeCellInfo(v)
764
+ end
765
+ end
766
+
767
+ def self.alloc_from_OptionalTypeCellInfo(v)
768
+ RustBuffer.allocWithBuilder do |builder|
769
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeCellInfo(builder, v)
770
+ return builder.finalize()
771
+ end
772
+ end
773
+
774
+ def consume_into_OptionalTypeCellInfo
775
+ consumeWithStream do |stream|
776
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeCellInfo(stream)
777
+ end
778
+ end
779
+
780
+ # The Optional<T> type for TypeCheckOptions.
781
+
782
+ def self.check_lower_OptionalTypeCheckOptions(v)
783
+ if !v.nil?
784
+ RustBuffer.check_lower_TypeCheckOptions(v)
785
+ end
786
+ end
787
+
788
+ def self.alloc_from_OptionalTypeCheckOptions(v)
789
+ RustBuffer.allocWithBuilder do |builder|
790
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeCheckOptions(builder, v)
791
+ return builder.finalize()
792
+ end
793
+ end
794
+
795
+ def consume_into_OptionalTypeCheckOptions
796
+ consumeWithStream do |stream|
797
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeCheckOptions(stream)
798
+ end
799
+ end
800
+
801
+ # The Optional<T> type for TypeDeviceData.
802
+
803
+ def self.check_lower_OptionalTypeDeviceData(v)
804
+ if !v.nil?
805
+ RustBuffer.check_lower_TypeDeviceData(v)
806
+ end
807
+ end
808
+
809
+ def self.alloc_from_OptionalTypeDeviceData(v)
810
+ RustBuffer.allocWithBuilder do |builder|
811
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeDeviceData(builder, v)
812
+ return builder.finalize()
813
+ end
814
+ end
815
+
816
+ def consume_into_OptionalTypeDeviceData
817
+ consumeWithStream do |stream|
818
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeDeviceData(stream)
819
+ end
820
+ end
821
+
822
+ # The Optional<T> type for TypeFileIndex.
823
+
824
+ def self.check_lower_OptionalTypeFileIndex(v)
825
+ if !v.nil?
826
+ RustBuffer.check_lower_TypeFileIndex(v)
827
+ end
828
+ end
829
+
830
+ def self.alloc_from_OptionalTypeFileIndex(v)
831
+ RustBuffer.allocWithBuilder do |builder|
832
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeFileIndex(builder, v)
833
+ return builder.finalize()
834
+ end
835
+ end
836
+
837
+ def consume_into_OptionalTypeFileIndex
838
+ consumeWithStream do |stream|
839
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeFileIndex(stream)
840
+ end
841
+ end
842
+
843
+ # The Optional<T> type for TypeLocationData.
844
+
845
+ def self.check_lower_OptionalTypeLocationData(v)
846
+ if !v.nil?
847
+ RustBuffer.check_lower_TypeLocationData(v)
848
+ end
849
+ end
850
+
851
+ def self.alloc_from_OptionalTypeLocationData(v)
852
+ RustBuffer.allocWithBuilder do |builder|
853
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeLocationData(builder, v)
854
+ return builder.finalize()
855
+ end
856
+ end
857
+
858
+ def consume_into_OptionalTypeLocationData
859
+ consumeWithStream do |stream|
860
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeLocationData(stream)
861
+ end
862
+ end
863
+
864
+ # The Optional<T> type for TypeNetworkData.
865
+
866
+ def self.check_lower_OptionalTypeNetworkData(v)
867
+ if !v.nil?
868
+ RustBuffer.check_lower_TypeNetworkData(v)
869
+ end
870
+ end
871
+
872
+ def self.alloc_from_OptionalTypeNetworkData(v)
873
+ RustBuffer.allocWithBuilder do |builder|
874
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeNetworkData(builder, v)
875
+ return builder.finalize()
876
+ end
877
+ end
878
+
879
+ def consume_into_OptionalTypeNetworkData
880
+ consumeWithStream do |stream|
881
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeNetworkData(stream)
882
+ end
883
+ end
884
+
885
+ # The Optional<T> type for TypeDigitalSourceType.
886
+
887
+ def self.check_lower_OptionalTypeDigitalSourceType(v)
888
+ if !v.nil?
889
+ RustBuffer.check_lower_TypeDigitalSourceType(v)
890
+ end
891
+ end
892
+
893
+ def self.alloc_from_OptionalTypeDigitalSourceType(v)
894
+ RustBuffer.allocWithBuilder do |builder|
895
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeDigitalSourceType(builder, v)
896
+ return builder.finalize()
897
+ end
898
+ end
899
+
900
+ def consume_into_OptionalTypeDigitalSourceType
901
+ consumeWithStream do |stream|
902
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeDigitalSourceType(stream)
903
+ end
904
+ end
905
+
906
+ # The Optional<T> type for TypeMediaReturn.
907
+
908
+ def self.check_lower_OptionalTypeMediaReturn(v)
909
+ if !v.nil?
910
+ RustBuffer.check_lower_TypeMediaReturn(v)
911
+ end
912
+ end
913
+
914
+ def self.alloc_from_OptionalTypeMediaReturn(v)
915
+ RustBuffer.allocWithBuilder do |builder|
916
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeMediaReturn(builder, v)
917
+ return builder.finalize()
918
+ end
919
+ end
920
+
921
+ def consume_into_OptionalTypeMediaReturn
922
+ consumeWithStream do |stream|
923
+ return ::Proofmode::RustBufferStreamMixin.read_OptionalTypeMediaReturn(stream)
924
+ end
925
+ end
926
+
927
+ # The Sequence<T> type for string.
928
+
929
+ def self.check_lower_Sequencestring(v)
930
+ v.each do |item|
931
+
932
+ end
933
+ end
934
+
935
+ def self.alloc_from_Sequencestring(v)
936
+ RustBuffer.allocWithBuilder do |builder|
937
+ ::Proofmode::RustBufferBuilderMixin.write_Sequencestring(builder, v)
938
+ return builder.finalize()
939
+ end
940
+ end
941
+
942
+ def consume_into_Sequencestring
943
+ consumeWithStream do |stream|
944
+ return ::Proofmode::RustBufferStreamMixin.read_Sequencestring(stream)
945
+ end
946
+ end
947
+
948
+
949
+ # The Map<T> type for MapStringString.
950
+
951
+ def self.check_lower_MapStringString(v)
952
+ v.each do |k, v|
953
+
954
+
955
+ end
956
+ end
957
+
958
+ def self.alloc_from_MapStringString(v)
959
+ RustBuffer.allocWithBuilder do |builder|
960
+ ::Proofmode::RustBufferBuilderMixin.write_MapStringString(builder, v)
961
+ return builder.finalize
962
+ end
963
+ end
964
+
965
+ def consume_into_MapStringString
966
+ consumeWithStream do |stream|
967
+ return ::Proofmode::RustBufferStreamMixin.read_MapStringString(stream)
968
+ end
969
+ end
970
+ end
971
+
972
+ module UniFFILib
973
+ class ForeignBytes < FFI::Struct
974
+ layout :len, :int32,
975
+ :data, :pointer
976
+
977
+ def len
978
+ self[:len]
979
+ end
980
+
981
+ def data
982
+ self[:data]
983
+ end
984
+
985
+ def to_s
986
+ "ForeignBytes(len=#{len}, data=#{data.read_bytes(len)})"
987
+ end
988
+ end
989
+ end
990
+
991
+ private_constant :UniFFILib
992
+ # Mixin containing type-specific read methods as module functions.
993
+ # Call sites name this module explicitly (e.g.
994
+ # `::ThisNs::RustBufferStreamMixin.read_TypeFoo(stream)`) so two crates
995
+ # that both define `Foo` do not flatten `read_TypeFoo` onto one receiver.
996
+ # The `stream` argument is always the *local* crate's RustBufferStream so
997
+ # unpack_from / read route through that crate's buffer.
998
+ #
999
+ # Nested types from further crates are reached by lexical calls in this
1000
+ # mixin's generated bodies, not by `include`. Do not use `module_function`.
1001
+ # InternalError in these methods is this crate's class.
1002
+ module RustBufferStreamMixin
1003
+ def self.read_u8(stream)
1004
+ stream.unpack_from 1, 'c'
1005
+ end
1006
+
1007
+ def self.read_u16(stream)
1008
+ stream.unpack_from 2, 'S>'
1009
+ end
1010
+
1011
+ def self.read_u32(stream)
1012
+ stream.unpack_from 4, 'L>'
1013
+ end
1014
+
1015
+ def self.read_u64(stream)
1016
+ stream.unpack_from 8, 'Q>'
1017
+ end
1018
+
1019
+ def self.read_f64(stream)
1020
+ stream.unpack_from 8, 'G'
1021
+ end
1022
+
1023
+ def self.read_bool(stream)
1024
+ v = stream.unpack_from 1, 'c'
1025
+
1026
+ return false if v == 0
1027
+ return true if v == 1
1028
+
1029
+ raise InternalError, 'Unexpected byte for Boolean type'
1030
+ end
1031
+
1032
+ def self.read_string(stream)
1033
+ size = stream.unpack_from 4, 'l>'
1034
+
1035
+ raise InternalError, 'Unexpected negative string length' if size.negative?
1036
+
1037
+ stream.read(size).force_encoding(Encoding::UTF_8)
1038
+ end
1039
+
1040
+ def self.read_bytes(stream)
1041
+ size = stream.unpack_from 4, 'l>'
1042
+
1043
+ raise InternalError, 'Unexpected negative byte string length' if size.negative?
1044
+
1045
+ stream.read(size).force_encoding(Encoding::BINARY)
1046
+ end
1047
+
1048
+ # The Object type ProgressListener.
1049
+
1050
+ def self.read_TypeProgressListener(stream)
1051
+ handle = stream.unpack_from 8, 'Q>'
1052
+ return ProgressListener.uniffi_lift(handle)
1053
+ end
1054
+
1055
+ # The Object type ProofModeCallbacks.
1056
+
1057
+ def self.read_TypeProofModeCallbacks(stream)
1058
+ handle = stream.unpack_from 8, 'Q>'
1059
+ return ProofModeCallbacks.uniffi_lift(handle)
1060
+ end
1061
+
1062
+ # The Object type ProofSigner.
1063
+
1064
+ def self.read_TypeProofSigner(stream)
1065
+ handle = stream.unpack_from 8, 'Q>'
1066
+ return ProofSigner.uniffi_lift(handle)
1067
+ end
1068
+
1069
+ # The Object type UrlFetcher.
1070
+
1071
+ def self.read_TypeUrlFetcher(stream)
1072
+ handle = stream.unpack_from 8, 'Q>'
1073
+ return UrlFetcher.uniffi_lift(handle)
1074
+ end
1075
+
1076
+ # The Record type C2paCredentials.
1077
+
1078
+ def self.read_TypeC2paCredentials(stream)
1079
+ C2paCredentials.new(
1080
+ private_key_pem: ::Proofmode::RustBufferStreamMixin.read_string(stream),
1081
+ certificate_chain_pem: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1082
+ )
1083
+ end
1084
+
1085
+ # The Record type CellInfo.
1086
+
1087
+ def self.read_TypeCellInfo(stream)
1088
+ CellInfo.new(
1089
+ carrier: ::Proofmode::RustBufferStreamMixin.read_string(stream),
1090
+ cell_id: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1091
+ lac: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream)
1092
+ )
1093
+ end
1094
+
1095
+ # The Record type CheckOptions.
1096
+
1097
+ def self.read_TypeCheckOptions(stream)
1098
+ CheckOptions.new(
1099
+ c2pa_trust_anchors: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1100
+ cawg_trust_anchors: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1101
+ cawg_allowed_list: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1102
+ media: ::Proofmode::RustBufferStreamMixin.read_OptionalTypeMediaReturn(stream),
1103
+ thumbnail_max_dim: ::Proofmode::RustBufferStreamMixin.read_Optionalu32(stream),
1104
+ gateway: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1105
+ max_input_bytes: ::Proofmode::RustBufferStreamMixin.read_Optionalu64(stream)
1106
+ )
1107
+ end
1108
+
1109
+ # The Record type DeviceData.
1110
+
1111
+ def self.read_TypeDeviceData(stream)
1112
+ DeviceData.new(
1113
+ manufacturer: ::Proofmode::RustBufferStreamMixin.read_string(stream),
1114
+ model: ::Proofmode::RustBufferStreamMixin.read_string(stream),
1115
+ os_version: ::Proofmode::RustBufferStreamMixin.read_string(stream),
1116
+ device_id: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream)
1117
+ )
1118
+ end
1119
+
1120
+ # The Record type FileIndex.
1121
+
1122
+ def self.read_TypeFileIndex(stream)
1123
+ FileIndex.new(
1124
+ index: ::Proofmode::RustBufferStreamMixin.read_u32(stream),
1125
+ total: ::Proofmode::RustBufferStreamMixin.read_u32(stream)
1126
+ )
1127
+ end
1128
+
1129
+ # The Record type FileProofOptions.
1130
+
1131
+ def self.read_TypeFileProofOptions(stream)
1132
+ FileProofOptions.new(
1133
+ passphrase: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1134
+ email: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1135
+ description: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1136
+ location: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1137
+ event_type: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1138
+ tags: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1139
+ digital_source_type: ::Proofmode::RustBufferStreamMixin.read_OptionalTypeDigitalSourceType(stream),
1140
+ c2pa_credentials: ::Proofmode::RustBufferStreamMixin.read_OptionalTypeC2paCredentials(stream)
1141
+ )
1142
+ end
1143
+
1144
+ # The Record type HttpResponse.
1145
+
1146
+ def self.read_TypeHttpResponse(stream)
1147
+ HttpResponse.new(
1148
+ status: ::Proofmode::RustBufferStreamMixin.read_u16(stream),
1149
+ content_type: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1150
+ body: ::Proofmode::RustBufferStreamMixin.read_bytes(stream)
1151
+ )
1152
+ end
1153
+
1154
+ # The Record type LocationData.
1155
+
1156
+ def self.read_TypeLocationData(stream)
1157
+ LocationData.new(
1158
+ latitude: ::Proofmode::RustBufferStreamMixin.read_f64(stream),
1159
+ longitude: ::Proofmode::RustBufferStreamMixin.read_f64(stream),
1160
+ altitude: ::Proofmode::RustBufferStreamMixin.read_Optionalf64(stream),
1161
+ accuracy: ::Proofmode::RustBufferStreamMixin.read_Optionalf64(stream),
1162
+ provider: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream)
1163
+ )
1164
+ end
1165
+
1166
+ # The Record type NetworkData.
1167
+
1168
+ def self.read_TypeNetworkData(stream)
1169
+ NetworkData.new(
1170
+ network_type: ::Proofmode::RustBufferStreamMixin.read_string(stream),
1171
+ wifi_ssid: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1172
+ cell_info: ::Proofmode::RustBufferStreamMixin.read_OptionalTypeCellInfo(stream)
1173
+ )
1174
+ end
1175
+
1176
+ # The Record type ProgressEvent.
1177
+
1178
+ def self.read_TypeProgressEvent(stream)
1179
+ ProgressEvent.new(
1180
+ phase: ::Proofmode::RustBufferStreamMixin.read_TypePhase(stream),
1181
+ percent: ::Proofmode::RustBufferStreamMixin.read_u8(stream),
1182
+ detail: ::Proofmode::RustBufferStreamMixin.read_Optionalstring(stream),
1183
+ file: ::Proofmode::RustBufferStreamMixin.read_OptionalTypeFileIndex(stream)
1184
+ )
1185
+ end
1186
+
1187
+ # The Record type ProofModeConfig.
1188
+
1189
+ def self.read_TypeProofModeConfig(stream)
1190
+ ProofModeConfig.new(
1191
+ auto_notarize: ::Proofmode::RustBufferStreamMixin.read_bool(stream),
1192
+ track_location: ::Proofmode::RustBufferStreamMixin.read_bool(stream),
1193
+ track_device_id: ::Proofmode::RustBufferStreamMixin.read_bool(stream),
1194
+ track_network: ::Proofmode::RustBufferStreamMixin.read_bool(stream),
1195
+ add_credentials: ::Proofmode::RustBufferStreamMixin.read_bool(stream),
1196
+ embed_c2pa: ::Proofmode::RustBufferStreamMixin.read_bool(stream),
1197
+ digital_source_type: ::Proofmode::RustBufferStreamMixin.read_OptionalTypeDigitalSourceType(stream),
1198
+ c2pa_credentials: ::Proofmode::RustBufferStreamMixin.read_OptionalTypeC2paCredentials(stream)
1199
+ )
1200
+ end
1201
+
1202
+
1203
+
1204
+ # The Enum type DigitalSourceType.
1205
+
1206
+ def self.read_TypeDigitalSourceType(stream)
1207
+ variant = stream.unpack_from 4, 'l>'
1208
+
1209
+ if variant == 1
1210
+ return DigitalSourceType::DIGITAL_CAPTURE
1211
+ end
1212
+ if variant == 2
1213
+ return DigitalSourceType::SCREEN_CAPTURE
1214
+ end
1215
+
1216
+ raise InternalError, 'Unexpected variant tag for TypeDigitalSourceType'
1217
+ end
1218
+
1219
+
1220
+
1221
+
1222
+
1223
+ # The Enum type MediaReturn.
1224
+
1225
+ def self.read_TypeMediaReturn(stream)
1226
+ variant = stream.unpack_from 4, 'l>'
1227
+
1228
+ if variant == 1
1229
+ return MediaReturn::NONE
1230
+ end
1231
+ if variant == 2
1232
+ return MediaReturn::THUMBNAIL
1233
+ end
1234
+ if variant == 3
1235
+ return MediaReturn::FULL
1236
+ end
1237
+
1238
+ raise InternalError, 'Unexpected variant tag for TypeMediaReturn'
1239
+ end
1240
+
1241
+
1242
+
1243
+
1244
+
1245
+ # The Enum type Phase.
1246
+
1247
+ def self.read_TypePhase(stream)
1248
+ variant = stream.unpack_from 4, 'l>'
1249
+
1250
+ if variant == 1
1251
+ return Phase::FETCH
1252
+ end
1253
+ if variant == 2
1254
+ return Phase::PREPROCESS
1255
+ end
1256
+ if variant == 3
1257
+ return Phase::INTEGRITY
1258
+ end
1259
+ if variant == 4
1260
+ return Phase::CONSISTENCY
1261
+ end
1262
+ if variant == 5
1263
+ return Phase::SYNCHRONY
1264
+ end
1265
+ if variant == 6
1266
+ return Phase::CLASSIFY
1267
+ end
1268
+ if variant == 7
1269
+ return Phase::DONE
1270
+ end
1271
+
1272
+ raise InternalError, 'Unexpected variant tag for TypePhase'
1273
+ end
1274
+
1275
+
1276
+
1277
+
1278
+
1279
+
1280
+
1281
+ # The Error type ProofModeError
1282
+
1283
+ def self.read_TypeProofModeError(stream)
1284
+ variant = stream.unpack_from 4, 'l>'
1285
+
1286
+ if variant == 1
1287
+ return ProofModeError::Io.new(
1288
+ reason: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1289
+ )
1290
+ end
1291
+ if variant == 2
1292
+ return ProofModeError::Generation.new(
1293
+ reason: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1294
+ )
1295
+ end
1296
+ if variant == 3
1297
+ return ProofModeError::Check.new(
1298
+ reason: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1299
+ )
1300
+ end
1301
+
1302
+ raise InternalError, 'Unexpected variant tag for TypeProofModeError'
1303
+ end
1304
+
1305
+
1306
+
1307
+
1308
+
1309
+
1310
+ # The Error type ProofSignerError
1311
+
1312
+ def self.read_TypeProofSignerError(stream)
1313
+ variant = stream.unpack_from 4, 'l>'
1314
+
1315
+ if variant == 1
1316
+ return ProofSignerError::EmptyPassphrase.new
1317
+ end
1318
+ if variant == 2
1319
+ return ProofSignerError::WrongPassphrase.new(
1320
+ path: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1321
+ )
1322
+ end
1323
+ if variant == 3
1324
+ return ProofSignerError::EmailNeeded.new(
1325
+ path: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1326
+ )
1327
+ end
1328
+ if variant == 4
1329
+ return ProofSignerError::CannotSign.new(
1330
+ reason: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1331
+ )
1332
+ end
1333
+ if variant == 5
1334
+ return ProofSignerError::CannotCreate.new(
1335
+ reason: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1336
+ )
1337
+ end
1338
+ if variant == 6
1339
+ return ProofSignerError::InvalidKey.new(
1340
+ reason: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1341
+ )
1342
+ end
1343
+ if variant == 7
1344
+ return ProofSignerError::Io.new(
1345
+ reason: ::Proofmode::RustBufferStreamMixin.read_string(stream)
1346
+ )
1347
+ end
1348
+
1349
+ raise InternalError, 'Unexpected variant tag for TypeProofSignerError'
1350
+ end
1351
+
1352
+
1353
+
1354
+ # The Optional<T> type for u32.
1355
+
1356
+ def self.read_Optionalu32(stream)
1357
+ flag = stream.unpack_from 1, 'c'
1358
+
1359
+ if flag == 0
1360
+ return nil
1361
+ elsif flag == 1
1362
+ return ::Proofmode::RustBufferStreamMixin.read_u32(stream)
1363
+ else
1364
+ raise InternalError, 'Unexpected flag byte for Optionalu32'
1365
+ end
1366
+ end
1367
+
1368
+
1369
+ # The Optional<T> type for u64.
1370
+
1371
+ def self.read_Optionalu64(stream)
1372
+ flag = stream.unpack_from 1, 'c'
1373
+
1374
+ if flag == 0
1375
+ return nil
1376
+ elsif flag == 1
1377
+ return ::Proofmode::RustBufferStreamMixin.read_u64(stream)
1378
+ else
1379
+ raise InternalError, 'Unexpected flag byte for Optionalu64'
1380
+ end
1381
+ end
1382
+
1383
+
1384
+ # The Optional<T> type for f64.
1385
+
1386
+ def self.read_Optionalf64(stream)
1387
+ flag = stream.unpack_from 1, 'c'
1388
+
1389
+ if flag == 0
1390
+ return nil
1391
+ elsif flag == 1
1392
+ return ::Proofmode::RustBufferStreamMixin.read_f64(stream)
1393
+ else
1394
+ raise InternalError, 'Unexpected flag byte for Optionalf64'
1395
+ end
1396
+ end
1397
+
1398
+
1399
+ # The Optional<T> type for string.
1400
+
1401
+ def self.read_Optionalstring(stream)
1402
+ flag = stream.unpack_from 1, 'c'
1403
+
1404
+ if flag == 0
1405
+ return nil
1406
+ elsif flag == 1
1407
+ return ::Proofmode::RustBufferStreamMixin.read_string(stream)
1408
+ else
1409
+ raise InternalError, 'Unexpected flag byte for Optionalstring'
1410
+ end
1411
+ end
1412
+
1413
+
1414
+ # The Optional<T> type for bytes.
1415
+
1416
+ def self.read_Optionalbytes(stream)
1417
+ flag = stream.unpack_from 1, 'c'
1418
+
1419
+ if flag == 0
1420
+ return nil
1421
+ elsif flag == 1
1422
+ return ::Proofmode::RustBufferStreamMixin.read_bytes(stream)
1423
+ else
1424
+ raise InternalError, 'Unexpected flag byte for Optionalbytes'
1425
+ end
1426
+ end
1427
+
1428
+
1429
+ # The Optional<T> type for TypeProgressListener.
1430
+
1431
+ def self.read_OptionalTypeProgressListener(stream)
1432
+ flag = stream.unpack_from 1, 'c'
1433
+
1434
+ if flag == 0
1435
+ return nil
1436
+ elsif flag == 1
1437
+ return ::Proofmode::RustBufferStreamMixin.read_TypeProgressListener(stream)
1438
+ else
1439
+ raise InternalError, 'Unexpected flag byte for OptionalTypeProgressListener'
1440
+ end
1441
+ end
1442
+
1443
+
1444
+ # The Optional<T> type for TypeC2paCredentials.
1445
+
1446
+ def self.read_OptionalTypeC2paCredentials(stream)
1447
+ flag = stream.unpack_from 1, 'c'
1448
+
1449
+ if flag == 0
1450
+ return nil
1451
+ elsif flag == 1
1452
+ return ::Proofmode::RustBufferStreamMixin.read_TypeC2paCredentials(stream)
1453
+ else
1454
+ raise InternalError, 'Unexpected flag byte for OptionalTypeC2paCredentials'
1455
+ end
1456
+ end
1457
+
1458
+
1459
+ # The Optional<T> type for TypeCellInfo.
1460
+
1461
+ def self.read_OptionalTypeCellInfo(stream)
1462
+ flag = stream.unpack_from 1, 'c'
1463
+
1464
+ if flag == 0
1465
+ return nil
1466
+ elsif flag == 1
1467
+ return ::Proofmode::RustBufferStreamMixin.read_TypeCellInfo(stream)
1468
+ else
1469
+ raise InternalError, 'Unexpected flag byte for OptionalTypeCellInfo'
1470
+ end
1471
+ end
1472
+
1473
+
1474
+ # The Optional<T> type for TypeCheckOptions.
1475
+
1476
+ def self.read_OptionalTypeCheckOptions(stream)
1477
+ flag = stream.unpack_from 1, 'c'
1478
+
1479
+ if flag == 0
1480
+ return nil
1481
+ elsif flag == 1
1482
+ return ::Proofmode::RustBufferStreamMixin.read_TypeCheckOptions(stream)
1483
+ else
1484
+ raise InternalError, 'Unexpected flag byte for OptionalTypeCheckOptions'
1485
+ end
1486
+ end
1487
+
1488
+
1489
+ # The Optional<T> type for TypeDeviceData.
1490
+
1491
+ def self.read_OptionalTypeDeviceData(stream)
1492
+ flag = stream.unpack_from 1, 'c'
1493
+
1494
+ if flag == 0
1495
+ return nil
1496
+ elsif flag == 1
1497
+ return ::Proofmode::RustBufferStreamMixin.read_TypeDeviceData(stream)
1498
+ else
1499
+ raise InternalError, 'Unexpected flag byte for OptionalTypeDeviceData'
1500
+ end
1501
+ end
1502
+
1503
+
1504
+ # The Optional<T> type for TypeFileIndex.
1505
+
1506
+ def self.read_OptionalTypeFileIndex(stream)
1507
+ flag = stream.unpack_from 1, 'c'
1508
+
1509
+ if flag == 0
1510
+ return nil
1511
+ elsif flag == 1
1512
+ return ::Proofmode::RustBufferStreamMixin.read_TypeFileIndex(stream)
1513
+ else
1514
+ raise InternalError, 'Unexpected flag byte for OptionalTypeFileIndex'
1515
+ end
1516
+ end
1517
+
1518
+
1519
+ # The Optional<T> type for TypeLocationData.
1520
+
1521
+ def self.read_OptionalTypeLocationData(stream)
1522
+ flag = stream.unpack_from 1, 'c'
1523
+
1524
+ if flag == 0
1525
+ return nil
1526
+ elsif flag == 1
1527
+ return ::Proofmode::RustBufferStreamMixin.read_TypeLocationData(stream)
1528
+ else
1529
+ raise InternalError, 'Unexpected flag byte for OptionalTypeLocationData'
1530
+ end
1531
+ end
1532
+
1533
+
1534
+ # The Optional<T> type for TypeNetworkData.
1535
+
1536
+ def self.read_OptionalTypeNetworkData(stream)
1537
+ flag = stream.unpack_from 1, 'c'
1538
+
1539
+ if flag == 0
1540
+ return nil
1541
+ elsif flag == 1
1542
+ return ::Proofmode::RustBufferStreamMixin.read_TypeNetworkData(stream)
1543
+ else
1544
+ raise InternalError, 'Unexpected flag byte for OptionalTypeNetworkData'
1545
+ end
1546
+ end
1547
+
1548
+
1549
+ # The Optional<T> type for TypeDigitalSourceType.
1550
+
1551
+ def self.read_OptionalTypeDigitalSourceType(stream)
1552
+ flag = stream.unpack_from 1, 'c'
1553
+
1554
+ if flag == 0
1555
+ return nil
1556
+ elsif flag == 1
1557
+ return ::Proofmode::RustBufferStreamMixin.read_TypeDigitalSourceType(stream)
1558
+ else
1559
+ raise InternalError, 'Unexpected flag byte for OptionalTypeDigitalSourceType'
1560
+ end
1561
+ end
1562
+
1563
+
1564
+ # The Optional<T> type for TypeMediaReturn.
1565
+
1566
+ def self.read_OptionalTypeMediaReturn(stream)
1567
+ flag = stream.unpack_from 1, 'c'
1568
+
1569
+ if flag == 0
1570
+ return nil
1571
+ elsif flag == 1
1572
+ return ::Proofmode::RustBufferStreamMixin.read_TypeMediaReturn(stream)
1573
+ else
1574
+ raise InternalError, 'Unexpected flag byte for OptionalTypeMediaReturn'
1575
+ end
1576
+ end
1577
+
1578
+ # The Sequence<T> type for string.
1579
+
1580
+ def self.read_Sequencestring(stream)
1581
+ count = stream.unpack_from 4, 'l>'
1582
+
1583
+ raise InternalError, 'Unexpected negative sequence length' if count.negative?
1584
+
1585
+ items = []
1586
+
1587
+ count.times do
1588
+ items.append ::Proofmode::RustBufferStreamMixin.read_string(stream)
1589
+ end
1590
+
1591
+ items
1592
+ end
1593
+
1594
+ # The Map<T> type for MapStringString.
1595
+
1596
+ def self.read_MapStringString(stream)
1597
+ count = stream.unpack_from 4, 'l>'
1598
+ raise InternalError, 'Unexpected negative map size' if count.negative?
1599
+
1600
+ items = {}
1601
+ count.times do
1602
+ key = ::Proofmode::RustBufferStreamMixin.read_string(stream)
1603
+ items[key] = ::Proofmode::RustBufferStreamMixin.read_string(stream)
1604
+ end
1605
+
1606
+ items
1607
+ end
1608
+
1609
+
1610
+ end
1611
+
1612
+ # Helper for structured reading of values from a RustBuffer.
1613
+ class RustBufferStream
1614
+ def initialize(rbuf)
1615
+ @rbuf = rbuf
1616
+ @offset = 0
1617
+ end
1618
+
1619
+ def remaining
1620
+ @rbuf.len - @offset
1621
+ end
1622
+
1623
+ def read(size)
1624
+ raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
1625
+
1626
+ data = @rbuf.data.get_bytes @offset, size
1627
+
1628
+ @offset += size
1629
+
1630
+ data
1631
+ end
1632
+
1633
+ def unpack_from(size, format)
1634
+ raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
1635
+
1636
+ value = @rbuf.data.get_bytes(@offset, size).unpack format
1637
+
1638
+ @offset += size
1639
+
1640
+ # TODO: verify this
1641
+ raise 'more than one element!!!' if value.size > 1
1642
+
1643
+ value[0]
1644
+ end
1645
+ end
1646
+
1647
+ private_constant :RustBufferStream
1648
+ # Mixin containing type-specific write methods as module functions.
1649
+ # Call sites name this module explicitly (e.g.
1650
+ # `::ThisNs::RustBufferBuilderMixin.write_TypeFoo(builder, v)`) so two crates
1651
+ # that both define `Foo` do not flatten `write_TypeFoo` onto one receiver.
1652
+ # The `builder` argument is always the *local* crate's RustBufferBuilder so
1653
+ # pack_into / reserve / write route through that crate's allocator.
1654
+ #
1655
+ # Nested types from further crates are reached by lexical calls in this
1656
+ # mixin's generated bodies, not by `include`. Do not use `module_function`
1657
+ # (it would reintroduce private instance methods).
1658
+ # InternalError in these methods is this crate's class.
1659
+ module RustBufferBuilderMixin
1660
+ def self.write_u8(builder, v)
1661
+ v = ::Proofmode::uniffi_in_range(v, "u8", 0, 2**8)
1662
+ builder.pack_into(1, 'c', v)
1663
+ end
1664
+
1665
+ def self.write_u16(builder, v)
1666
+ v = ::Proofmode::uniffi_in_range(v, "u16", 0, 2**16)
1667
+ builder.pack_into(2, 'S>', v)
1668
+ end
1669
+
1670
+ def self.write_u32(builder, v)
1671
+ v = ::Proofmode::uniffi_in_range(v, "u32", 0, 2**32)
1672
+ builder.pack_into(4, 'L>', v)
1673
+ end
1674
+
1675
+ def self.write_u64(builder, v)
1676
+ v = ::Proofmode::uniffi_in_range(v, "u64", 0, 2**64)
1677
+ builder.pack_into(8, 'Q>', v)
1678
+ end
1679
+
1680
+ def self.write_f64(builder, v)
1681
+ builder.pack_into(8, 'G', v)
1682
+ end
1683
+
1684
+ def self.write_bool(builder, v)
1685
+ builder.pack_into(1, 'c', v ? 1 : 0)
1686
+ end
1687
+
1688
+ def self.write_string(builder, v)
1689
+ v = ::Proofmode::uniffi_utf8(v)
1690
+ builder.pack_into 4, 'l>', v.bytes.size
1691
+ builder.write v
1692
+ end
1693
+
1694
+ def self.write_bytes(builder, v)
1695
+ v = ::Proofmode::uniffi_bytes(v)
1696
+ builder.pack_into 4, 'l>', v.bytes.size
1697
+ builder.write v
1698
+ end
1699
+
1700
+ # The Object type ProgressListener.
1701
+
1702
+ def self.write_TypeProgressListener(builder, obj)
1703
+ handle = ProgressListener.uniffi_lower obj
1704
+ builder.pack_into(8, 'Q>', handle)
1705
+ end
1706
+
1707
+ # The Object type ProofModeCallbacks.
1708
+
1709
+ def self.write_TypeProofModeCallbacks(builder, obj)
1710
+ handle = ProofModeCallbacks.uniffi_lower obj
1711
+ builder.pack_into(8, 'Q>', handle)
1712
+ end
1713
+
1714
+ # The Object type ProofSigner.
1715
+
1716
+ def self.write_TypeProofSigner(builder, obj)
1717
+ handle = ProofSigner.uniffi_lower obj
1718
+ builder.pack_into(8, 'Q>', handle)
1719
+ end
1720
+
1721
+ # The Object type UrlFetcher.
1722
+
1723
+ def self.write_TypeUrlFetcher(builder, obj)
1724
+ handle = UrlFetcher.uniffi_lower obj
1725
+ builder.pack_into(8, 'Q>', handle)
1726
+ end
1727
+
1728
+ # The Record type C2paCredentials.
1729
+
1730
+ def self.write_TypeC2paCredentials(builder, v)
1731
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.private_key_pem)
1732
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.certificate_chain_pem)
1733
+ end
1734
+
1735
+ # The Record type CellInfo.
1736
+
1737
+ def self.write_TypeCellInfo(builder, v)
1738
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.carrier)
1739
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.cell_id)
1740
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.lac)
1741
+ end
1742
+
1743
+ # The Record type CheckOptions.
1744
+
1745
+ def self.write_TypeCheckOptions(builder, v)
1746
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.c2pa_trust_anchors)
1747
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.cawg_trust_anchors)
1748
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.cawg_allowed_list)
1749
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeMediaReturn(builder, v.media)
1750
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalu32(builder, v.thumbnail_max_dim)
1751
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.gateway)
1752
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalu64(builder, v.max_input_bytes)
1753
+ end
1754
+
1755
+ # The Record type DeviceData.
1756
+
1757
+ def self.write_TypeDeviceData(builder, v)
1758
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.manufacturer)
1759
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.model)
1760
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.os_version)
1761
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.device_id)
1762
+ end
1763
+
1764
+ # The Record type FileIndex.
1765
+
1766
+ def self.write_TypeFileIndex(builder, v)
1767
+ ::Proofmode::RustBufferBuilderMixin.write_u32(builder, v.index)
1768
+ ::Proofmode::RustBufferBuilderMixin.write_u32(builder, v.total)
1769
+ end
1770
+
1771
+ # The Record type FileProofOptions.
1772
+
1773
+ def self.write_TypeFileProofOptions(builder, v)
1774
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.passphrase)
1775
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.email)
1776
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.description)
1777
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.location)
1778
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.event_type)
1779
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.tags)
1780
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeDigitalSourceType(builder, v.digital_source_type)
1781
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeC2paCredentials(builder, v.c2pa_credentials)
1782
+ end
1783
+
1784
+ # The Record type HttpResponse.
1785
+
1786
+ def self.write_TypeHttpResponse(builder, v)
1787
+ ::Proofmode::RustBufferBuilderMixin.write_u16(builder, v.status)
1788
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.content_type)
1789
+ ::Proofmode::RustBufferBuilderMixin.write_bytes(builder, v.body)
1790
+ end
1791
+
1792
+ # The Record type LocationData.
1793
+
1794
+ def self.write_TypeLocationData(builder, v)
1795
+ ::Proofmode::RustBufferBuilderMixin.write_f64(builder, v.latitude)
1796
+ ::Proofmode::RustBufferBuilderMixin.write_f64(builder, v.longitude)
1797
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalf64(builder, v.altitude)
1798
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalf64(builder, v.accuracy)
1799
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.provider)
1800
+ end
1801
+
1802
+ # The Record type NetworkData.
1803
+
1804
+ def self.write_TypeNetworkData(builder, v)
1805
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.network_type)
1806
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.wifi_ssid)
1807
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeCellInfo(builder, v.cell_info)
1808
+ end
1809
+
1810
+ # The Record type ProgressEvent.
1811
+
1812
+ def self.write_TypeProgressEvent(builder, v)
1813
+ ::Proofmode::RustBufferBuilderMixin.write_TypePhase(builder, v.phase)
1814
+ ::Proofmode::RustBufferBuilderMixin.write_u8(builder, v.percent)
1815
+ ::Proofmode::RustBufferBuilderMixin.write_Optionalstring(builder, v.detail)
1816
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeFileIndex(builder, v.file)
1817
+ end
1818
+
1819
+ # The Record type ProofModeConfig.
1820
+
1821
+ def self.write_TypeProofModeConfig(builder, v)
1822
+ ::Proofmode::RustBufferBuilderMixin.write_bool(builder, v.auto_notarize)
1823
+ ::Proofmode::RustBufferBuilderMixin.write_bool(builder, v.track_location)
1824
+ ::Proofmode::RustBufferBuilderMixin.write_bool(builder, v.track_device_id)
1825
+ ::Proofmode::RustBufferBuilderMixin.write_bool(builder, v.track_network)
1826
+ ::Proofmode::RustBufferBuilderMixin.write_bool(builder, v.add_credentials)
1827
+ ::Proofmode::RustBufferBuilderMixin.write_bool(builder, v.embed_c2pa)
1828
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeDigitalSourceType(builder, v.digital_source_type)
1829
+ ::Proofmode::RustBufferBuilderMixin.write_OptionalTypeC2paCredentials(builder, v.c2pa_credentials)
1830
+ end
1831
+
1832
+ # The Enum type DigitalSourceType.
1833
+
1834
+ def self.write_TypeDigitalSourceType(builder, v)
1835
+ if v == DigitalSourceType::DIGITAL_CAPTURE
1836
+ builder.pack_into(4, 'l>', 1)
1837
+ end
1838
+ if v == DigitalSourceType::SCREEN_CAPTURE
1839
+ builder.pack_into(4, 'l>', 2)
1840
+ end
1841
+ end
1842
+
1843
+
1844
+ # The Enum type MediaReturn.
1845
+
1846
+ def self.write_TypeMediaReturn(builder, v)
1847
+ if v == MediaReturn::NONE
1848
+ builder.pack_into(4, 'l>', 1)
1849
+ end
1850
+ if v == MediaReturn::THUMBNAIL
1851
+ builder.pack_into(4, 'l>', 2)
1852
+ end
1853
+ if v == MediaReturn::FULL
1854
+ builder.pack_into(4, 'l>', 3)
1855
+ end
1856
+ end
1857
+
1858
+
1859
+ # The Enum type Phase.
1860
+
1861
+ def self.write_TypePhase(builder, v)
1862
+ if v == Phase::FETCH
1863
+ builder.pack_into(4, 'l>', 1)
1864
+ end
1865
+ if v == Phase::PREPROCESS
1866
+ builder.pack_into(4, 'l>', 2)
1867
+ end
1868
+ if v == Phase::INTEGRITY
1869
+ builder.pack_into(4, 'l>', 3)
1870
+ end
1871
+ if v == Phase::CONSISTENCY
1872
+ builder.pack_into(4, 'l>', 4)
1873
+ end
1874
+ if v == Phase::SYNCHRONY
1875
+ builder.pack_into(4, 'l>', 5)
1876
+ end
1877
+ if v == Phase::CLASSIFY
1878
+ builder.pack_into(4, 'l>', 6)
1879
+ end
1880
+ if v == Phase::DONE
1881
+ builder.pack_into(4, 'l>', 7)
1882
+ end
1883
+ end
1884
+
1885
+
1886
+ # The Error type ProofModeError - write for callback error returns.
1887
+
1888
+ def self.write_TypeProofModeError(builder, v)
1889
+ if v.is_a?(ProofModeError::Io)
1890
+ builder.pack_into 4, 'l>', 1
1891
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.reason)
1892
+ return
1893
+ end
1894
+ if v.is_a?(ProofModeError::Generation)
1895
+ builder.pack_into 4, 'l>', 2
1896
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.reason)
1897
+ return
1898
+ end
1899
+ if v.is_a?(ProofModeError::Check)
1900
+ builder.pack_into 4, 'l>', 3
1901
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.reason)
1902
+ return
1903
+ end
1904
+ end
1905
+
1906
+
1907
+ # The Error type ProofSignerError - write for callback error returns.
1908
+
1909
+ def self.write_TypeProofSignerError(builder, v)
1910
+ if v.is_a?(ProofSignerError::EmptyPassphrase)
1911
+ builder.pack_into 4, 'l>', 1
1912
+ return
1913
+ end
1914
+ if v.is_a?(ProofSignerError::WrongPassphrase)
1915
+ builder.pack_into 4, 'l>', 2
1916
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.path)
1917
+ return
1918
+ end
1919
+ if v.is_a?(ProofSignerError::EmailNeeded)
1920
+ builder.pack_into 4, 'l>', 3
1921
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.path)
1922
+ return
1923
+ end
1924
+ if v.is_a?(ProofSignerError::CannotSign)
1925
+ builder.pack_into 4, 'l>', 4
1926
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.reason)
1927
+ return
1928
+ end
1929
+ if v.is_a?(ProofSignerError::CannotCreate)
1930
+ builder.pack_into 4, 'l>', 5
1931
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.reason)
1932
+ return
1933
+ end
1934
+ if v.is_a?(ProofSignerError::InvalidKey)
1935
+ builder.pack_into 4, 'l>', 6
1936
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.reason)
1937
+ return
1938
+ end
1939
+ if v.is_a?(ProofSignerError::Io)
1940
+ builder.pack_into 4, 'l>', 7
1941
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v.reason)
1942
+ return
1943
+ end
1944
+ end
1945
+
1946
+
1947
+ # The Optional<T> type for u32.
1948
+
1949
+ def self.write_Optionalu32(builder, v)
1950
+ if v.nil?
1951
+ builder.pack_into(1, 'c', 0)
1952
+ else
1953
+ builder.pack_into(1, 'c', 1)
1954
+ ::Proofmode::RustBufferBuilderMixin.write_u32(builder, v)
1955
+ end
1956
+ end
1957
+
1958
+ # The Optional<T> type for u64.
1959
+
1960
+ def self.write_Optionalu64(builder, v)
1961
+ if v.nil?
1962
+ builder.pack_into(1, 'c', 0)
1963
+ else
1964
+ builder.pack_into(1, 'c', 1)
1965
+ ::Proofmode::RustBufferBuilderMixin.write_u64(builder, v)
1966
+ end
1967
+ end
1968
+
1969
+ # The Optional<T> type for f64.
1970
+
1971
+ def self.write_Optionalf64(builder, v)
1972
+ if v.nil?
1973
+ builder.pack_into(1, 'c', 0)
1974
+ else
1975
+ builder.pack_into(1, 'c', 1)
1976
+ ::Proofmode::RustBufferBuilderMixin.write_f64(builder, v)
1977
+ end
1978
+ end
1979
+
1980
+ # The Optional<T> type for string.
1981
+
1982
+ def self.write_Optionalstring(builder, v)
1983
+ if v.nil?
1984
+ builder.pack_into(1, 'c', 0)
1985
+ else
1986
+ builder.pack_into(1, 'c', 1)
1987
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v)
1988
+ end
1989
+ end
1990
+
1991
+ # The Optional<T> type for bytes.
1992
+
1993
+ def self.write_Optionalbytes(builder, v)
1994
+ if v.nil?
1995
+ builder.pack_into(1, 'c', 0)
1996
+ else
1997
+ builder.pack_into(1, 'c', 1)
1998
+ ::Proofmode::RustBufferBuilderMixin.write_bytes(builder, v)
1999
+ end
2000
+ end
2001
+
2002
+ # The Optional<T> type for TypeProgressListener.
2003
+
2004
+ def self.write_OptionalTypeProgressListener(builder, v)
2005
+ if v.nil?
2006
+ builder.pack_into(1, 'c', 0)
2007
+ else
2008
+ builder.pack_into(1, 'c', 1)
2009
+ ::Proofmode::RustBufferBuilderMixin.write_TypeProgressListener(builder, v)
2010
+ end
2011
+ end
2012
+
2013
+ # The Optional<T> type for TypeC2paCredentials.
2014
+
2015
+ def self.write_OptionalTypeC2paCredentials(builder, v)
2016
+ if v.nil?
2017
+ builder.pack_into(1, 'c', 0)
2018
+ else
2019
+ builder.pack_into(1, 'c', 1)
2020
+ ::Proofmode::RustBufferBuilderMixin.write_TypeC2paCredentials(builder, v)
2021
+ end
2022
+ end
2023
+
2024
+ # The Optional<T> type for TypeCellInfo.
2025
+
2026
+ def self.write_OptionalTypeCellInfo(builder, v)
2027
+ if v.nil?
2028
+ builder.pack_into(1, 'c', 0)
2029
+ else
2030
+ builder.pack_into(1, 'c', 1)
2031
+ ::Proofmode::RustBufferBuilderMixin.write_TypeCellInfo(builder, v)
2032
+ end
2033
+ end
2034
+
2035
+ # The Optional<T> type for TypeCheckOptions.
2036
+
2037
+ def self.write_OptionalTypeCheckOptions(builder, v)
2038
+ if v.nil?
2039
+ builder.pack_into(1, 'c', 0)
2040
+ else
2041
+ builder.pack_into(1, 'c', 1)
2042
+ ::Proofmode::RustBufferBuilderMixin.write_TypeCheckOptions(builder, v)
2043
+ end
2044
+ end
2045
+
2046
+ # The Optional<T> type for TypeDeviceData.
2047
+
2048
+ def self.write_OptionalTypeDeviceData(builder, v)
2049
+ if v.nil?
2050
+ builder.pack_into(1, 'c', 0)
2051
+ else
2052
+ builder.pack_into(1, 'c', 1)
2053
+ ::Proofmode::RustBufferBuilderMixin.write_TypeDeviceData(builder, v)
2054
+ end
2055
+ end
2056
+
2057
+ # The Optional<T> type for TypeFileIndex.
2058
+
2059
+ def self.write_OptionalTypeFileIndex(builder, v)
2060
+ if v.nil?
2061
+ builder.pack_into(1, 'c', 0)
2062
+ else
2063
+ builder.pack_into(1, 'c', 1)
2064
+ ::Proofmode::RustBufferBuilderMixin.write_TypeFileIndex(builder, v)
2065
+ end
2066
+ end
2067
+
2068
+ # The Optional<T> type for TypeLocationData.
2069
+
2070
+ def self.write_OptionalTypeLocationData(builder, v)
2071
+ if v.nil?
2072
+ builder.pack_into(1, 'c', 0)
2073
+ else
2074
+ builder.pack_into(1, 'c', 1)
2075
+ ::Proofmode::RustBufferBuilderMixin.write_TypeLocationData(builder, v)
2076
+ end
2077
+ end
2078
+
2079
+ # The Optional<T> type for TypeNetworkData.
2080
+
2081
+ def self.write_OptionalTypeNetworkData(builder, v)
2082
+ if v.nil?
2083
+ builder.pack_into(1, 'c', 0)
2084
+ else
2085
+ builder.pack_into(1, 'c', 1)
2086
+ ::Proofmode::RustBufferBuilderMixin.write_TypeNetworkData(builder, v)
2087
+ end
2088
+ end
2089
+
2090
+ # The Optional<T> type for TypeDigitalSourceType.
2091
+
2092
+ def self.write_OptionalTypeDigitalSourceType(builder, v)
2093
+ if v.nil?
2094
+ builder.pack_into(1, 'c', 0)
2095
+ else
2096
+ builder.pack_into(1, 'c', 1)
2097
+ ::Proofmode::RustBufferBuilderMixin.write_TypeDigitalSourceType(builder, v)
2098
+ end
2099
+ end
2100
+
2101
+ # The Optional<T> type for TypeMediaReturn.
2102
+
2103
+ def self.write_OptionalTypeMediaReturn(builder, v)
2104
+ if v.nil?
2105
+ builder.pack_into(1, 'c', 0)
2106
+ else
2107
+ builder.pack_into(1, 'c', 1)
2108
+ ::Proofmode::RustBufferBuilderMixin.write_TypeMediaReturn(builder, v)
2109
+ end
2110
+ end
2111
+
2112
+ # The Sequence<T> type for string.
2113
+
2114
+ def self.write_Sequencestring(builder, items)
2115
+ builder.pack_into(4, 'l>', items.size)
2116
+
2117
+ items.each do |item|
2118
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, item)
2119
+ end
2120
+ end
2121
+
2122
+ # The Map<T> type for MapStringString.
2123
+
2124
+ def self.write_MapStringString(builder, items)
2125
+ builder.pack_into(4, 'l>', items.size)
2126
+
2127
+ items.each do |k, v|
2128
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, k)
2129
+ ::Proofmode::RustBufferBuilderMixin.write_string(builder, v)
2130
+ end
2131
+ end
2132
+
2133
+
2134
+ end
2135
+
2136
+ # Helper for structured writing of values into a RustBuffer.
2137
+ class RustBufferBuilder
2138
+ def initialize
2139
+ @rust_buf = RustBuffer.alloc 16
2140
+ @rust_buf.len = 0
2141
+ end
2142
+
2143
+ def finalize
2144
+ rbuf = @rust_buf
2145
+
2146
+ @rust_buf = nil
2147
+
2148
+ rbuf
2149
+ end
2150
+
2151
+ def discard
2152
+ return if @rust_buf.nil?
2153
+
2154
+ rbuf = finalize
2155
+ rbuf.free
2156
+ end
2157
+
2158
+ def write(value)
2159
+ reserve(value.bytes.size) do
2160
+ @rust_buf.data.put_array_of_char @rust_buf.len, value.bytes
2161
+ end
2162
+ end
2163
+
2164
+ # Public so RustBufferBuilderMixin module functions can pack without
2165
+ # `include` flattening instance methods onto this class.
2166
+ # The class itself is private_constant. `reserve` stays private.
2167
+ def pack_into(size, format, value)
2168
+ reserve(size) do
2169
+ @rust_buf.data.put_array_of_char @rust_buf.len, [value].pack(format).bytes
2170
+ end
2171
+ end
2172
+
2173
+ private
2174
+
2175
+ def reserve(num_bytes)
2176
+ if @rust_buf.len + num_bytes > @rust_buf.capacity
2177
+ @rust_buf = RustBuffer.reserve(@rust_buf, num_bytes)
2178
+ end
2179
+
2180
+ yield
2181
+
2182
+ @rust_buf.len += num_bytes
2183
+ end
2184
+ end
2185
+
2186
+ private_constant :RustBufferBuilder
2187
+
2188
+ # Error definitions
2189
+ class RustCallStatus < FFI::Struct
2190
+ layout :code, :int8,
2191
+ :error_buf, RustBuffer
2192
+
2193
+ def code
2194
+ self[:code]
2195
+ end
2196
+
2197
+ def error_buf
2198
+ self[:error_buf]
2199
+ end
2200
+
2201
+ def to_s
2202
+ "RustCallStatus(code=#{self[:code]})"
2203
+ end
2204
+ end
2205
+
2206
+ # These match the values from the uniffi::rustcalls module
2207
+ CALL_SUCCESS = 0
2208
+ CALL_ERROR = 1
2209
+ CALL_PANIC = 2
2210
+
2211
+
2212
+ module ProofModeError
2213
+ class Io < StandardError
2214
+ def initialize(reason:)
2215
+
2216
+ @reason = reason
2217
+
2218
+ super()
2219
+ end
2220
+
2221
+
2222
+ attr_reader :reason
2223
+
2224
+
2225
+ def to_s
2226
+ "#{self.class.name}(reason=#{@reason.inspect})"
2227
+
2228
+ end
2229
+
2230
+
2231
+ def io?
2232
+ instance_of? ProofModeError::Io
2233
+ end
2234
+
2235
+ def generation?
2236
+ instance_of? ProofModeError::Generation
2237
+ end
2238
+
2239
+ def check?
2240
+ instance_of? ProofModeError::Check
2241
+ end
2242
+
2243
+ end
2244
+ class Generation < StandardError
2245
+ def initialize(reason:)
2246
+
2247
+ @reason = reason
2248
+
2249
+ super()
2250
+ end
2251
+
2252
+
2253
+ attr_reader :reason
2254
+
2255
+
2256
+ def to_s
2257
+ "#{self.class.name}(reason=#{@reason.inspect})"
2258
+
2259
+ end
2260
+
2261
+
2262
+ def io?
2263
+ instance_of? ProofModeError::Io
2264
+ end
2265
+
2266
+ def generation?
2267
+ instance_of? ProofModeError::Generation
2268
+ end
2269
+
2270
+ def check?
2271
+ instance_of? ProofModeError::Check
2272
+ end
2273
+
2274
+ end
2275
+ class Check < StandardError
2276
+ def initialize(reason:)
2277
+
2278
+ @reason = reason
2279
+
2280
+ super()
2281
+ end
2282
+
2283
+
2284
+ attr_reader :reason
2285
+
2286
+
2287
+ def to_s
2288
+ "#{self.class.name}(reason=#{@reason.inspect})"
2289
+
2290
+ end
2291
+
2292
+
2293
+ def io?
2294
+ instance_of? ProofModeError::Io
2295
+ end
2296
+
2297
+ def generation?
2298
+ instance_of? ProofModeError::Generation
2299
+ end
2300
+
2301
+ def check?
2302
+ instance_of? ProofModeError::Check
2303
+ end
2304
+
2305
+ end
2306
+
2307
+ end
2308
+
2309
+
2310
+
2311
+ module ProofSignerError
2312
+ class EmptyPassphrase < StandardError
2313
+ def initialize()
2314
+
2315
+ super()
2316
+ end
2317
+
2318
+
2319
+ def to_s
2320
+ "#{self.class.name}()"
2321
+
2322
+ end
2323
+
2324
+
2325
+ def empty_passphrase?
2326
+ instance_of? ProofSignerError::EmptyPassphrase
2327
+ end
2328
+
2329
+ def wrong_passphrase?
2330
+ instance_of? ProofSignerError::WrongPassphrase
2331
+ end
2332
+
2333
+ def email_needed?
2334
+ instance_of? ProofSignerError::EmailNeeded
2335
+ end
2336
+
2337
+ def cannot_sign?
2338
+ instance_of? ProofSignerError::CannotSign
2339
+ end
2340
+
2341
+ def cannot_create?
2342
+ instance_of? ProofSignerError::CannotCreate
2343
+ end
2344
+
2345
+ def invalid_key?
2346
+ instance_of? ProofSignerError::InvalidKey
2347
+ end
2348
+
2349
+ def io?
2350
+ instance_of? ProofSignerError::Io
2351
+ end
2352
+
2353
+ end
2354
+ class WrongPassphrase < StandardError
2355
+ def initialize(path:)
2356
+
2357
+ @path = path
2358
+
2359
+ super()
2360
+ end
2361
+
2362
+
2363
+ attr_reader :path
2364
+
2365
+
2366
+ def to_s
2367
+ "#{self.class.name}(path=#{@path.inspect})"
2368
+
2369
+ end
2370
+
2371
+
2372
+ def empty_passphrase?
2373
+ instance_of? ProofSignerError::EmptyPassphrase
2374
+ end
2375
+
2376
+ def wrong_passphrase?
2377
+ instance_of? ProofSignerError::WrongPassphrase
2378
+ end
2379
+
2380
+ def email_needed?
2381
+ instance_of? ProofSignerError::EmailNeeded
2382
+ end
2383
+
2384
+ def cannot_sign?
2385
+ instance_of? ProofSignerError::CannotSign
2386
+ end
2387
+
2388
+ def cannot_create?
2389
+ instance_of? ProofSignerError::CannotCreate
2390
+ end
2391
+
2392
+ def invalid_key?
2393
+ instance_of? ProofSignerError::InvalidKey
2394
+ end
2395
+
2396
+ def io?
2397
+ instance_of? ProofSignerError::Io
2398
+ end
2399
+
2400
+ end
2401
+ class EmailNeeded < StandardError
2402
+ def initialize(path:)
2403
+
2404
+ @path = path
2405
+
2406
+ super()
2407
+ end
2408
+
2409
+
2410
+ attr_reader :path
2411
+
2412
+
2413
+ def to_s
2414
+ "#{self.class.name}(path=#{@path.inspect})"
2415
+
2416
+ end
2417
+
2418
+
2419
+ def empty_passphrase?
2420
+ instance_of? ProofSignerError::EmptyPassphrase
2421
+ end
2422
+
2423
+ def wrong_passphrase?
2424
+ instance_of? ProofSignerError::WrongPassphrase
2425
+ end
2426
+
2427
+ def email_needed?
2428
+ instance_of? ProofSignerError::EmailNeeded
2429
+ end
2430
+
2431
+ def cannot_sign?
2432
+ instance_of? ProofSignerError::CannotSign
2433
+ end
2434
+
2435
+ def cannot_create?
2436
+ instance_of? ProofSignerError::CannotCreate
2437
+ end
2438
+
2439
+ def invalid_key?
2440
+ instance_of? ProofSignerError::InvalidKey
2441
+ end
2442
+
2443
+ def io?
2444
+ instance_of? ProofSignerError::Io
2445
+ end
2446
+
2447
+ end
2448
+ class CannotSign < StandardError
2449
+ def initialize(reason:)
2450
+
2451
+ @reason = reason
2452
+
2453
+ super()
2454
+ end
2455
+
2456
+
2457
+ attr_reader :reason
2458
+
2459
+
2460
+ def to_s
2461
+ "#{self.class.name}(reason=#{@reason.inspect})"
2462
+
2463
+ end
2464
+
2465
+
2466
+ def empty_passphrase?
2467
+ instance_of? ProofSignerError::EmptyPassphrase
2468
+ end
2469
+
2470
+ def wrong_passphrase?
2471
+ instance_of? ProofSignerError::WrongPassphrase
2472
+ end
2473
+
2474
+ def email_needed?
2475
+ instance_of? ProofSignerError::EmailNeeded
2476
+ end
2477
+
2478
+ def cannot_sign?
2479
+ instance_of? ProofSignerError::CannotSign
2480
+ end
2481
+
2482
+ def cannot_create?
2483
+ instance_of? ProofSignerError::CannotCreate
2484
+ end
2485
+
2486
+ def invalid_key?
2487
+ instance_of? ProofSignerError::InvalidKey
2488
+ end
2489
+
2490
+ def io?
2491
+ instance_of? ProofSignerError::Io
2492
+ end
2493
+
2494
+ end
2495
+ class CannotCreate < StandardError
2496
+ def initialize(reason:)
2497
+
2498
+ @reason = reason
2499
+
2500
+ super()
2501
+ end
2502
+
2503
+
2504
+ attr_reader :reason
2505
+
2506
+
2507
+ def to_s
2508
+ "#{self.class.name}(reason=#{@reason.inspect})"
2509
+
2510
+ end
2511
+
2512
+
2513
+ def empty_passphrase?
2514
+ instance_of? ProofSignerError::EmptyPassphrase
2515
+ end
2516
+
2517
+ def wrong_passphrase?
2518
+ instance_of? ProofSignerError::WrongPassphrase
2519
+ end
2520
+
2521
+ def email_needed?
2522
+ instance_of? ProofSignerError::EmailNeeded
2523
+ end
2524
+
2525
+ def cannot_sign?
2526
+ instance_of? ProofSignerError::CannotSign
2527
+ end
2528
+
2529
+ def cannot_create?
2530
+ instance_of? ProofSignerError::CannotCreate
2531
+ end
2532
+
2533
+ def invalid_key?
2534
+ instance_of? ProofSignerError::InvalidKey
2535
+ end
2536
+
2537
+ def io?
2538
+ instance_of? ProofSignerError::Io
2539
+ end
2540
+
2541
+ end
2542
+ class InvalidKey < StandardError
2543
+ def initialize(reason:)
2544
+
2545
+ @reason = reason
2546
+
2547
+ super()
2548
+ end
2549
+
2550
+
2551
+ attr_reader :reason
2552
+
2553
+
2554
+ def to_s
2555
+ "#{self.class.name}(reason=#{@reason.inspect})"
2556
+
2557
+ end
2558
+
2559
+
2560
+ def empty_passphrase?
2561
+ instance_of? ProofSignerError::EmptyPassphrase
2562
+ end
2563
+
2564
+ def wrong_passphrase?
2565
+ instance_of? ProofSignerError::WrongPassphrase
2566
+ end
2567
+
2568
+ def email_needed?
2569
+ instance_of? ProofSignerError::EmailNeeded
2570
+ end
2571
+
2572
+ def cannot_sign?
2573
+ instance_of? ProofSignerError::CannotSign
2574
+ end
2575
+
2576
+ def cannot_create?
2577
+ instance_of? ProofSignerError::CannotCreate
2578
+ end
2579
+
2580
+ def invalid_key?
2581
+ instance_of? ProofSignerError::InvalidKey
2582
+ end
2583
+
2584
+ def io?
2585
+ instance_of? ProofSignerError::Io
2586
+ end
2587
+
2588
+ end
2589
+ class Io < StandardError
2590
+ def initialize(reason:)
2591
+
2592
+ @reason = reason
2593
+
2594
+ super()
2595
+ end
2596
+
2597
+
2598
+ attr_reader :reason
2599
+
2600
+
2601
+ def to_s
2602
+ "#{self.class.name}(reason=#{@reason.inspect})"
2603
+
2604
+ end
2605
+
2606
+
2607
+ def empty_passphrase?
2608
+ instance_of? ProofSignerError::EmptyPassphrase
2609
+ end
2610
+
2611
+ def wrong_passphrase?
2612
+ instance_of? ProofSignerError::WrongPassphrase
2613
+ end
2614
+
2615
+ def email_needed?
2616
+ instance_of? ProofSignerError::EmailNeeded
2617
+ end
2618
+
2619
+ def cannot_sign?
2620
+ instance_of? ProofSignerError::CannotSign
2621
+ end
2622
+
2623
+ def cannot_create?
2624
+ instance_of? ProofSignerError::CannotCreate
2625
+ end
2626
+
2627
+ def invalid_key?
2628
+ instance_of? ProofSignerError::InvalidKey
2629
+ end
2630
+
2631
+ def io?
2632
+ instance_of? ProofSignerError::Io
2633
+ end
2634
+
2635
+ end
2636
+
2637
+ end
2638
+
2639
+
2640
+
2641
+
2642
+
2643
+ private_constant :CALL_SUCCESS, :CALL_ERROR, :CALL_PANIC, :RustCallStatus
2644
+
2645
+ def self.consume_buffer_into_error(reader, rust_buffer)
2646
+ rust_buffer.consumeWithStream do |stream|
2647
+ return reader.call(stream)
2648
+ end
2649
+ end
2650
+
2651
+ # This crate's bindings error (panics, protocol mismatches, corrupt buffers).
2652
+ # Mixin readers/writers raise this class, so a consumer lifting this crate's types
2653
+ # should rescue Proofmode::InternalError — not their own
2654
+ # crate's InternalError. Matches Python InternalError / Kotlin InternalException.
2655
+ class InternalError < StandardError
2656
+ end
2657
+
2658
+ def self.rust_call(fn_name, *args)
2659
+ rust_call_with_error(nil, fn_name, *args)
2660
+ end
2661
+
2662
+ def self.rust_call_with_error(error_reader, fn_name, *args)
2663
+ status = RustCallStatus.new
2664
+ args << status
2665
+
2666
+ result = UniFFILib.public_send(fn_name, *args)
2667
+
2668
+ case status.code
2669
+ when CALL_SUCCESS
2670
+ result
2671
+ when CALL_ERROR
2672
+ if error_reader.nil?
2673
+ status.error_buf.free
2674
+ raise InternalError, "CALL_ERROR with no error_reader set"
2675
+ end
2676
+ raise consume_buffer_into_error(error_reader, status.error_buf)
2677
+ when CALL_PANIC
2678
+ if status.error_buf.len > 0
2679
+ raise InternalError, status.error_buf.consume_into_string
2680
+ else
2681
+ raise InternalError, "Rust panic"
2682
+ end
2683
+ else
2684
+ raise InternalError, "Unknown call status: #{status.code}"
2685
+ end
2686
+ end
2687
+
2688
+ private_class_method :consume_buffer_into_error
2689
+
2690
+ # This is how we find and load the dynamic library provided by the component.
2691
+ # For now we just look it up by name.
2692
+ module UniFFILib
2693
+ extend FFI::Library
2694
+
2695
+
2696
+ ffi_lib File.join(__dir__, 'libproofmode.so')
2697
+
2698
+
2699
+ # Define FFI callback types and structs (vtables, etc.)
2700
+
2701
+ callback :RustFutureContinuationCallback,
2702
+ [:uint64, :int8, ],
2703
+ :void
2704
+
2705
+ callback :ForeignFutureDroppedCallback,
2706
+ [:uint64, ],
2707
+ :void
2708
+
2709
+ callback :CallbackInterfaceFree,
2710
+ [:uint64, ],
2711
+ :void
2712
+
2713
+ callback :CallbackInterfaceClone,
2714
+ [:uint64, ],
2715
+ :uint64
2716
+
2717
+ class ForeignFutureDroppedCallbackStruct < FFI::Struct
2718
+ layout(
2719
+ :handle, :uint64,
2720
+ :free, :ForeignFutureDroppedCallback
2721
+ )
2722
+ end
2723
+
2724
+ class ForeignFutureResultU8 < FFI::Struct
2725
+ layout(
2726
+ :return_value, :uint8,
2727
+ :call_status, RustCallStatus
2728
+ )
2729
+ end
2730
+
2731
+ callback :ForeignFutureCompleteU8,
2732
+ [:uint64, ForeignFutureResultU8.by_value, ],
2733
+ :void
2734
+
2735
+ class ForeignFutureResultI8 < FFI::Struct
2736
+ layout(
2737
+ :return_value, :int8,
2738
+ :call_status, RustCallStatus
2739
+ )
2740
+ end
2741
+
2742
+ callback :ForeignFutureCompleteI8,
2743
+ [:uint64, ForeignFutureResultI8.by_value, ],
2744
+ :void
2745
+
2746
+ class ForeignFutureResultU16 < FFI::Struct
2747
+ layout(
2748
+ :return_value, :uint16,
2749
+ :call_status, RustCallStatus
2750
+ )
2751
+ end
2752
+
2753
+ callback :ForeignFutureCompleteU16,
2754
+ [:uint64, ForeignFutureResultU16.by_value, ],
2755
+ :void
2756
+
2757
+ class ForeignFutureResultI16 < FFI::Struct
2758
+ layout(
2759
+ :return_value, :int16,
2760
+ :call_status, RustCallStatus
2761
+ )
2762
+ end
2763
+
2764
+ callback :ForeignFutureCompleteI16,
2765
+ [:uint64, ForeignFutureResultI16.by_value, ],
2766
+ :void
2767
+
2768
+ class ForeignFutureResultU32 < FFI::Struct
2769
+ layout(
2770
+ :return_value, :uint32,
2771
+ :call_status, RustCallStatus
2772
+ )
2773
+ end
2774
+
2775
+ callback :ForeignFutureCompleteU32,
2776
+ [:uint64, ForeignFutureResultU32.by_value, ],
2777
+ :void
2778
+
2779
+ class ForeignFutureResultI32 < FFI::Struct
2780
+ layout(
2781
+ :return_value, :int32,
2782
+ :call_status, RustCallStatus
2783
+ )
2784
+ end
2785
+
2786
+ callback :ForeignFutureCompleteI32,
2787
+ [:uint64, ForeignFutureResultI32.by_value, ],
2788
+ :void
2789
+
2790
+ class ForeignFutureResultU64 < FFI::Struct
2791
+ layout(
2792
+ :return_value, :uint64,
2793
+ :call_status, RustCallStatus
2794
+ )
2795
+ end
2796
+
2797
+ callback :ForeignFutureCompleteU64,
2798
+ [:uint64, ForeignFutureResultU64.by_value, ],
2799
+ :void
2800
+
2801
+ class ForeignFutureResultI64 < FFI::Struct
2802
+ layout(
2803
+ :return_value, :int64,
2804
+ :call_status, RustCallStatus
2805
+ )
2806
+ end
2807
+
2808
+ callback :ForeignFutureCompleteI64,
2809
+ [:uint64, ForeignFutureResultI64.by_value, ],
2810
+ :void
2811
+
2812
+ class ForeignFutureResultF32 < FFI::Struct
2813
+ layout(
2814
+ :return_value, :float,
2815
+ :call_status, RustCallStatus
2816
+ )
2817
+ end
2818
+
2819
+ callback :ForeignFutureCompleteF32,
2820
+ [:uint64, ForeignFutureResultF32.by_value, ],
2821
+ :void
2822
+
2823
+ class ForeignFutureResultF64 < FFI::Struct
2824
+ layout(
2825
+ :return_value, :double,
2826
+ :call_status, RustCallStatus
2827
+ )
2828
+ end
2829
+
2830
+ callback :ForeignFutureCompleteF64,
2831
+ [:uint64, ForeignFutureResultF64.by_value, ],
2832
+ :void
2833
+
2834
+ class ForeignFutureResultRustBuffer < FFI::Struct
2835
+ layout(
2836
+ :return_value, RustBuffer.by_value,
2837
+ :call_status, RustCallStatus
2838
+ )
2839
+ end
2840
+
2841
+ callback :ForeignFutureCompleteRustBuffer,
2842
+ [:uint64, ForeignFutureResultRustBuffer.by_value, ],
2843
+ :void
2844
+
2845
+ class ForeignFutureResultVoid < FFI::Struct
2846
+ layout(
2847
+ :call_status, RustCallStatus
2848
+ )
2849
+ end
2850
+
2851
+ callback :ForeignFutureCompleteVoid,
2852
+ [:uint64, ForeignFutureResultVoid.by_value, ],
2853
+ :void
2854
+
2855
+ callback :CallbackInterfaceProgressListenerMethod0,
2856
+ [:uint64, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
2857
+ :void
2858
+
2859
+ callback :CallbackInterfaceProofModeCallbacksMethod0,
2860
+ [:uint64, :pointer, RustCallStatus.by_ref],
2861
+ :void
2862
+
2863
+ callback :CallbackInterfaceProofModeCallbacksMethod1,
2864
+ [:uint64, :pointer, RustCallStatus.by_ref],
2865
+ :void
2866
+
2867
+ callback :CallbackInterfaceProofModeCallbacksMethod2,
2868
+ [:uint64, :pointer, RustCallStatus.by_ref],
2869
+ :void
2870
+
2871
+ callback :CallbackInterfaceProofModeCallbacksMethod3,
2872
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
2873
+ :void
2874
+
2875
+ callback :CallbackInterfaceProofModeCallbacksMethod4,
2876
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
2877
+ :void
2878
+
2879
+ callback :CallbackInterfaceProofModeCallbacksMethod5,
2880
+ [:uint64, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
2881
+ :void
2882
+
2883
+ callback :CallbackInterfaceProofModeCallbacksMethod6,
2884
+ [:uint64, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
2885
+ :void
2886
+
2887
+ callback :CallbackInterfaceProofModeCallbacksMethod7,
2888
+ [:uint64, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
2889
+ :void
2890
+
2891
+ callback :CallbackInterfaceUrlFetcherMethod0,
2892
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
2893
+ :void
2894
+
2895
+ class VTableCallbackInterfaceProgressListener < FFI::Struct
2896
+ layout(
2897
+ :uniffi_free, :CallbackInterfaceFree,
2898
+ :uniffi_clone, :CallbackInterfaceClone,
2899
+ :on_progress, :CallbackInterfaceProgressListenerMethod0
2900
+ )
2901
+ end
2902
+
2903
+ class VTableCallbackInterfaceProofModeCallbacks < FFI::Struct
2904
+ layout(
2905
+ :uniffi_free, :CallbackInterfaceFree,
2906
+ :uniffi_clone, :CallbackInterfaceClone,
2907
+ :get_location, :CallbackInterfaceProofModeCallbacksMethod0,
2908
+ :get_device_info, :CallbackInterfaceProofModeCallbacksMethod1,
2909
+ :get_network_info, :CallbackInterfaceProofModeCallbacksMethod2,
2910
+ :save_data, :CallbackInterfaceProofModeCallbacksMethod3,
2911
+ :save_text, :CallbackInterfaceProofModeCallbacksMethod4,
2912
+ :sign_data, :CallbackInterfaceProofModeCallbacksMethod5,
2913
+ :notarize_hash, :CallbackInterfaceProofModeCallbacksMethod6,
2914
+ :report_progress, :CallbackInterfaceProofModeCallbacksMethod7
2915
+ )
2916
+ end
2917
+
2918
+ class VTableCallbackInterfaceUrlFetcher < FFI::Struct
2919
+ layout(
2920
+ :uniffi_free, :CallbackInterfaceFree,
2921
+ :uniffi_clone, :CallbackInterfaceClone,
2922
+ :get, :CallbackInterfaceUrlFetcherMethod0
2923
+ )
2924
+ end
2925
+
2926
+ attach_function :uniffi_proofmode_fn_clone_progresslistener,
2927
+ [:uint64, RustCallStatus.by_ref],
2928
+ :uint64
2929
+
2930
+ attach_function :uniffi_proofmode_fn_free_progresslistener,
2931
+ [:uint64, RustCallStatus.by_ref],
2932
+ :void
2933
+
2934
+ attach_function :uniffi_proofmode_fn_init_callback_vtable_progresslistener,
2935
+ [VTableCallbackInterfaceProgressListener.by_ref, ],
2936
+ :void
2937
+
2938
+ attach_function :uniffi_proofmode_fn_method_progresslistener_on_progress,
2939
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
2940
+ :void
2941
+
2942
+ attach_function :uniffi_proofmode_fn_clone_proofmodecallbacks,
2943
+ [:uint64, RustCallStatus.by_ref],
2944
+ :uint64
2945
+
2946
+ attach_function :uniffi_proofmode_fn_free_proofmodecallbacks,
2947
+ [:uint64, RustCallStatus.by_ref],
2948
+ :void
2949
+
2950
+ attach_function :uniffi_proofmode_fn_init_callback_vtable_proofmodecallbacks,
2951
+ [VTableCallbackInterfaceProofModeCallbacks.by_ref, ],
2952
+ :void
2953
+
2954
+ attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_get_location,
2955
+ [:uint64, RustCallStatus.by_ref],
2956
+ RustBuffer.by_value
2957
+
2958
+ attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_get_device_info,
2959
+ [:uint64, RustCallStatus.by_ref],
2960
+ RustBuffer.by_value
2961
+
2962
+ attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_get_network_info,
2963
+ [:uint64, RustCallStatus.by_ref],
2964
+ RustBuffer.by_value
2965
+
2966
+ attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_save_data,
2967
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
2968
+ :void
2969
+
2970
+ attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_save_text,
2971
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
2972
+ :void
2973
+
2974
+ attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_sign_data,
2975
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
2976
+ RustBuffer.by_value
2977
+
2978
+ attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_notarize_hash,
2979
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
2980
+ RustBuffer.by_value
2981
+
2982
+ attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_report_progress,
2983
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
2984
+ :void
2985
+
2986
+ attach_function :uniffi_proofmode_fn_clone_proofsigner,
2987
+ [:uint64, RustCallStatus.by_ref],
2988
+ :uint64
2989
+
2990
+ attach_function :uniffi_proofmode_fn_free_proofsigner,
2991
+ [:uint64, RustCallStatus.by_ref],
2992
+ :void
2993
+
2994
+ attach_function :uniffi_proofmode_fn_constructor_proofsigner_open,
2995
+ [RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
2996
+ :uint64
2997
+
2998
+ attach_function :uniffi_proofmode_fn_method_proofsigner_public_key,
2999
+ [:uint64, RustCallStatus.by_ref],
3000
+ RustBuffer.by_value
3001
+
3002
+ attach_function :uniffi_proofmode_fn_method_proofsigner_sign,
3003
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
3004
+ RustBuffer.by_value
3005
+
3006
+ attach_function :uniffi_proofmode_fn_clone_urlfetcher,
3007
+ [:uint64, RustCallStatus.by_ref],
3008
+ :uint64
3009
+
3010
+ attach_function :uniffi_proofmode_fn_free_urlfetcher,
3011
+ [:uint64, RustCallStatus.by_ref],
3012
+ :void
3013
+
3014
+ attach_function :uniffi_proofmode_fn_init_callback_vtable_urlfetcher,
3015
+ [VTableCallbackInterfaceUrlFetcher.by_ref, ],
3016
+ :void
3017
+
3018
+ attach_function :uniffi_proofmode_fn_method_urlfetcher_get,
3019
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
3020
+ RustBuffer.by_value
3021
+
3022
+ attach_function :uniffi_proofmode_fn_func_check_cids,
3023
+ [RustBuffer.by_value, :uint64, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
3024
+ RustBuffer.by_value
3025
+
3026
+ attach_function :uniffi_proofmode_fn_func_check_files,
3027
+ [RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
3028
+ RustBuffer.by_value
3029
+
3030
+ attach_function :uniffi_proofmode_fn_func_check_urls,
3031
+ [RustBuffer.by_value, :uint64, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
3032
+ RustBuffer.by_value
3033
+
3034
+ attach_function :uniffi_proofmode_fn_func_generate_proof,
3035
+ [RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
3036
+ RustBuffer.by_value
3037
+
3038
+ attach_function :uniffi_proofmode_fn_func_generate_proof_for_file,
3039
+ [RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
3040
+ RustBuffer.by_value
3041
+
3042
+ attach_function :uniffi_proofmode_fn_func_get_version,
3043
+ [RustCallStatus.by_ref],
3044
+ RustBuffer.by_value
3045
+
3046
+ attach_function :uniffi_proofmode_fn_func_media_sha256,
3047
+ [RustBuffer.by_value, RustCallStatus.by_ref],
3048
+ RustBuffer.by_value
3049
+
3050
+ attach_function :ffi_proofmode_rustbuffer_alloc,
3051
+ [:uint64, RustCallStatus.by_ref],
3052
+ RustBuffer.by_value
3053
+
3054
+ attach_function :ffi_proofmode_rustbuffer_from_bytes,
3055
+ [ForeignBytes, RustCallStatus.by_ref],
3056
+ RustBuffer.by_value
3057
+
3058
+ attach_function :ffi_proofmode_rustbuffer_free,
3059
+ [RustBuffer.by_value, RustCallStatus.by_ref],
3060
+ :void
3061
+
3062
+ attach_function :ffi_proofmode_rustbuffer_reserve,
3063
+ [RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
3064
+ RustBuffer.by_value
3065
+
3066
+ attach_function :ffi_proofmode_rust_future_poll_u8,
3067
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3068
+ :void
3069
+
3070
+ attach_function :ffi_proofmode_rust_future_cancel_u8,
3071
+ [:uint64, ],
3072
+ :void
3073
+
3074
+ attach_function :ffi_proofmode_rust_future_free_u8,
3075
+ [:uint64, ],
3076
+ :void
3077
+
3078
+ attach_function :ffi_proofmode_rust_future_complete_u8,
3079
+ [:uint64, RustCallStatus.by_ref],
3080
+ :uint8
3081
+
3082
+ attach_function :ffi_proofmode_rust_future_poll_i8,
3083
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3084
+ :void
3085
+
3086
+ attach_function :ffi_proofmode_rust_future_cancel_i8,
3087
+ [:uint64, ],
3088
+ :void
3089
+
3090
+ attach_function :ffi_proofmode_rust_future_free_i8,
3091
+ [:uint64, ],
3092
+ :void
3093
+
3094
+ attach_function :ffi_proofmode_rust_future_complete_i8,
3095
+ [:uint64, RustCallStatus.by_ref],
3096
+ :int8
3097
+
3098
+ attach_function :ffi_proofmode_rust_future_poll_u16,
3099
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3100
+ :void
3101
+
3102
+ attach_function :ffi_proofmode_rust_future_cancel_u16,
3103
+ [:uint64, ],
3104
+ :void
3105
+
3106
+ attach_function :ffi_proofmode_rust_future_free_u16,
3107
+ [:uint64, ],
3108
+ :void
3109
+
3110
+ attach_function :ffi_proofmode_rust_future_complete_u16,
3111
+ [:uint64, RustCallStatus.by_ref],
3112
+ :uint16
3113
+
3114
+ attach_function :ffi_proofmode_rust_future_poll_i16,
3115
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3116
+ :void
3117
+
3118
+ attach_function :ffi_proofmode_rust_future_cancel_i16,
3119
+ [:uint64, ],
3120
+ :void
3121
+
3122
+ attach_function :ffi_proofmode_rust_future_free_i16,
3123
+ [:uint64, ],
3124
+ :void
3125
+
3126
+ attach_function :ffi_proofmode_rust_future_complete_i16,
3127
+ [:uint64, RustCallStatus.by_ref],
3128
+ :int16
3129
+
3130
+ attach_function :ffi_proofmode_rust_future_poll_u32,
3131
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3132
+ :void
3133
+
3134
+ attach_function :ffi_proofmode_rust_future_cancel_u32,
3135
+ [:uint64, ],
3136
+ :void
3137
+
3138
+ attach_function :ffi_proofmode_rust_future_free_u32,
3139
+ [:uint64, ],
3140
+ :void
3141
+
3142
+ attach_function :ffi_proofmode_rust_future_complete_u32,
3143
+ [:uint64, RustCallStatus.by_ref],
3144
+ :uint32
3145
+
3146
+ attach_function :ffi_proofmode_rust_future_poll_i32,
3147
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3148
+ :void
3149
+
3150
+ attach_function :ffi_proofmode_rust_future_cancel_i32,
3151
+ [:uint64, ],
3152
+ :void
3153
+
3154
+ attach_function :ffi_proofmode_rust_future_free_i32,
3155
+ [:uint64, ],
3156
+ :void
3157
+
3158
+ attach_function :ffi_proofmode_rust_future_complete_i32,
3159
+ [:uint64, RustCallStatus.by_ref],
3160
+ :int32
3161
+
3162
+ attach_function :ffi_proofmode_rust_future_poll_u64,
3163
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3164
+ :void
3165
+
3166
+ attach_function :ffi_proofmode_rust_future_cancel_u64,
3167
+ [:uint64, ],
3168
+ :void
3169
+
3170
+ attach_function :ffi_proofmode_rust_future_free_u64,
3171
+ [:uint64, ],
3172
+ :void
3173
+
3174
+ attach_function :ffi_proofmode_rust_future_complete_u64,
3175
+ [:uint64, RustCallStatus.by_ref],
3176
+ :uint64
3177
+
3178
+ attach_function :ffi_proofmode_rust_future_poll_i64,
3179
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3180
+ :void
3181
+
3182
+ attach_function :ffi_proofmode_rust_future_cancel_i64,
3183
+ [:uint64, ],
3184
+ :void
3185
+
3186
+ attach_function :ffi_proofmode_rust_future_free_i64,
3187
+ [:uint64, ],
3188
+ :void
3189
+
3190
+ attach_function :ffi_proofmode_rust_future_complete_i64,
3191
+ [:uint64, RustCallStatus.by_ref],
3192
+ :int64
3193
+
3194
+ attach_function :ffi_proofmode_rust_future_poll_f32,
3195
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3196
+ :void
3197
+
3198
+ attach_function :ffi_proofmode_rust_future_cancel_f32,
3199
+ [:uint64, ],
3200
+ :void
3201
+
3202
+ attach_function :ffi_proofmode_rust_future_free_f32,
3203
+ [:uint64, ],
3204
+ :void
3205
+
3206
+ attach_function :ffi_proofmode_rust_future_complete_f32,
3207
+ [:uint64, RustCallStatus.by_ref],
3208
+ :float
3209
+
3210
+ attach_function :ffi_proofmode_rust_future_poll_f64,
3211
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3212
+ :void
3213
+
3214
+ attach_function :ffi_proofmode_rust_future_cancel_f64,
3215
+ [:uint64, ],
3216
+ :void
3217
+
3218
+ attach_function :ffi_proofmode_rust_future_free_f64,
3219
+ [:uint64, ],
3220
+ :void
3221
+
3222
+ attach_function :ffi_proofmode_rust_future_complete_f64,
3223
+ [:uint64, RustCallStatus.by_ref],
3224
+ :double
3225
+
3226
+ attach_function :ffi_proofmode_rust_future_poll_rust_buffer,
3227
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3228
+ :void
3229
+
3230
+ attach_function :ffi_proofmode_rust_future_cancel_rust_buffer,
3231
+ [:uint64, ],
3232
+ :void
3233
+
3234
+ attach_function :ffi_proofmode_rust_future_free_rust_buffer,
3235
+ [:uint64, ],
3236
+ :void
3237
+
3238
+ attach_function :ffi_proofmode_rust_future_complete_rust_buffer,
3239
+ [:uint64, RustCallStatus.by_ref],
3240
+ RustBuffer.by_value
3241
+
3242
+ attach_function :ffi_proofmode_rust_future_poll_void,
3243
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
3244
+ :void
3245
+
3246
+ attach_function :ffi_proofmode_rust_future_cancel_void,
3247
+ [:uint64, ],
3248
+ :void
3249
+
3250
+ attach_function :ffi_proofmode_rust_future_free_void,
3251
+ [:uint64, ],
3252
+ :void
3253
+
3254
+ attach_function :ffi_proofmode_rust_future_complete_void,
3255
+ [:uint64, RustCallStatus.by_ref],
3256
+ :void
3257
+
3258
+ attach_function :uniffi_proofmode_checksum_func_check_cids,
3259
+ [],
3260
+ :uint16
3261
+
3262
+ attach_function :uniffi_proofmode_checksum_func_check_files,
3263
+ [],
3264
+ :uint16
3265
+
3266
+ attach_function :uniffi_proofmode_checksum_func_check_urls,
3267
+ [],
3268
+ :uint16
3269
+
3270
+ attach_function :uniffi_proofmode_checksum_func_generate_proof,
3271
+ [],
3272
+ :uint16
3273
+
3274
+ attach_function :uniffi_proofmode_checksum_func_generate_proof_for_file,
3275
+ [],
3276
+ :uint16
3277
+
3278
+ attach_function :uniffi_proofmode_checksum_func_get_version,
3279
+ [],
3280
+ :uint16
3281
+
3282
+ attach_function :uniffi_proofmode_checksum_func_media_sha256,
3283
+ [],
3284
+ :uint16
3285
+
3286
+ attach_function :uniffi_proofmode_checksum_method_progresslistener_on_progress,
3287
+ [],
3288
+ :uint16
3289
+
3290
+ attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_get_location,
3291
+ [],
3292
+ :uint16
3293
+
3294
+ attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_get_device_info,
3295
+ [],
3296
+ :uint16
3297
+
3298
+ attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_get_network_info,
3299
+ [],
3300
+ :uint16
3301
+
3302
+ attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_save_data,
3303
+ [],
3304
+ :uint16
3305
+
3306
+ attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_save_text,
3307
+ [],
3308
+ :uint16
3309
+
3310
+ attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_sign_data,
3311
+ [],
3312
+ :uint16
3313
+
3314
+ attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_notarize_hash,
3315
+ [],
3316
+ :uint16
3317
+
3318
+ attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_report_progress,
3319
+ [],
3320
+ :uint16
3321
+
3322
+ attach_function :uniffi_proofmode_checksum_method_proofsigner_public_key,
3323
+ [],
3324
+ :uint16
3325
+
3326
+ attach_function :uniffi_proofmode_checksum_method_proofsigner_sign,
3327
+ [],
3328
+ :uint16
3329
+
3330
+ attach_function :uniffi_proofmode_checksum_method_urlfetcher_get,
3331
+ [],
3332
+ :uint16
3333
+
3334
+ attach_function :uniffi_proofmode_checksum_constructor_proofsigner_open,
3335
+ [],
3336
+ :uint16
3337
+
3338
+ attach_function :ffi_proofmode_uniffi_contract_version,
3339
+ [],
3340
+ :uint32
3341
+
3342
+ end
3343
+ # Base class for callback interface FfiConverters.
3344
+ # Stores Ruby callback objects in a handle map, and converts to/from integer handles.
3345
+
3346
+ class CallbackInterfaceFfiConverter
3347
+ attr_reader :handle_map
3348
+
3349
+ def initialize
3350
+ @handle_map = UniffiHandleMap.new
3351
+ end
3352
+
3353
+ def lift(handle)
3354
+ @handle_map.get handle
3355
+ end
3356
+
3357
+ def lower(cb)
3358
+ @handle_map.insert cb
3359
+ end
3360
+ end
3361
+
3362
+ private_constant :CallbackInterfaceFfiConverter
3363
+
3364
+ # Custom type definitions.
3365
+
3366
+ # Public interface members begin here.
3367
+
3368
+
3369
+
3370
+
3371
+
3372
+
3373
+
3374
+ class DigitalSourceType
3375
+ DIGITAL_CAPTURE = 0
3376
+ SCREEN_CAPTURE = 1
3377
+
3378
+ end
3379
+
3380
+
3381
+
3382
+
3383
+
3384
+
3385
+ class MediaReturn
3386
+ NONE = 0
3387
+ THUMBNAIL = 1
3388
+ FULL = 2
3389
+
3390
+ end
3391
+
3392
+
3393
+
3394
+
3395
+
3396
+
3397
+ class Phase
3398
+ FETCH = 0
3399
+ PREPROCESS = 1
3400
+ INTEGRITY = 2
3401
+ CONSISTENCY = 3
3402
+ SYNCHRONY = 4
3403
+ CLASSIFY = 5
3404
+ DONE = 6
3405
+
3406
+ end
3407
+
3408
+
3409
+
3410
+ # Record type FileIndex
3411
+ class FileIndex
3412
+ attr_reader :index, :total
3413
+
3414
+ def initialize(index:, total:)
3415
+ @index = index
3416
+ @total = total
3417
+ end
3418
+
3419
+ def ==(other)
3420
+ if @index != other.index
3421
+ return false
3422
+ end
3423
+ if @total != other.total
3424
+ return false
3425
+ end
3426
+
3427
+ true
3428
+ end
3429
+
3430
+ end
3431
+
3432
+ # Record type FileProofOptions
3433
+ class FileProofOptions
3434
+ attr_reader :passphrase, :email, :description, :location, :event_type, :tags, :digital_source_type, :c2pa_credentials
3435
+
3436
+ def initialize(passphrase: nil, email: nil, description: nil, location: nil, event_type: nil, tags: nil, digital_source_type: nil, c2pa_credentials: nil)
3437
+ @passphrase = passphrase
3438
+ @email = email
3439
+ @description = description
3440
+ @location = location
3441
+ @event_type = event_type
3442
+ @tags = tags
3443
+ @digital_source_type = digital_source_type
3444
+ @c2pa_credentials = c2pa_credentials
3445
+ end
3446
+
3447
+ def ==(other)
3448
+ if @passphrase != other.passphrase
3449
+ return false
3450
+ end
3451
+ if @email != other.email
3452
+ return false
3453
+ end
3454
+ if @description != other.description
3455
+ return false
3456
+ end
3457
+ if @location != other.location
3458
+ return false
3459
+ end
3460
+ if @event_type != other.event_type
3461
+ return false
3462
+ end
3463
+ if @tags != other.tags
3464
+ return false
3465
+ end
3466
+ if @digital_source_type != other.digital_source_type
3467
+ return false
3468
+ end
3469
+ if @c2pa_credentials != other.c2pa_credentials
3470
+ return false
3471
+ end
3472
+
3473
+ true
3474
+ end
3475
+
3476
+ end
3477
+
3478
+ # Record type HttpResponse
3479
+ class HttpResponse
3480
+ attr_reader :status, :content_type, :body
3481
+
3482
+ def initialize(status:, content_type:, body:)
3483
+ @status = status
3484
+ @content_type = content_type
3485
+ @body = body
3486
+ end
3487
+
3488
+ def ==(other)
3489
+ if @status != other.status
3490
+ return false
3491
+ end
3492
+ if @content_type != other.content_type
3493
+ return false
3494
+ end
3495
+ if @body != other.body
3496
+ return false
3497
+ end
3498
+
3499
+ true
3500
+ end
3501
+
3502
+ end
3503
+
3504
+ # Record type ProgressEvent
3505
+ class ProgressEvent
3506
+ attr_reader :phase, :percent, :detail, :file
3507
+
3508
+ def initialize(phase:, percent:, detail:, file:)
3509
+ @phase = phase
3510
+ @percent = percent
3511
+ @detail = detail
3512
+ @file = file
3513
+ end
3514
+
3515
+ def ==(other)
3516
+ if @phase != other.phase
3517
+ return false
3518
+ end
3519
+ if @percent != other.percent
3520
+ return false
3521
+ end
3522
+ if @detail != other.detail
3523
+ return false
3524
+ end
3525
+ if @file != other.file
3526
+ return false
3527
+ end
3528
+
3529
+ true
3530
+ end
3531
+
3532
+ end
3533
+
3534
+ # Record type C2paCredentials
3535
+ class C2paCredentials
3536
+ attr_reader :private_key_pem, :certificate_chain_pem
3537
+
3538
+ def initialize(private_key_pem:, certificate_chain_pem:)
3539
+ @private_key_pem = private_key_pem
3540
+ @certificate_chain_pem = certificate_chain_pem
3541
+ end
3542
+
3543
+ def ==(other)
3544
+ if @private_key_pem != other.private_key_pem
3545
+ return false
3546
+ end
3547
+ if @certificate_chain_pem != other.certificate_chain_pem
3548
+ return false
3549
+ end
3550
+
3551
+ true
3552
+ end
3553
+
3554
+ end
3555
+
3556
+ # Record type CellInfo
3557
+ class CellInfo
3558
+ attr_reader :carrier, :cell_id, :lac
3559
+
3560
+ def initialize(carrier:, cell_id:, lac:)
3561
+ @carrier = carrier
3562
+ @cell_id = cell_id
3563
+ @lac = lac
3564
+ end
3565
+
3566
+ def ==(other)
3567
+ if @carrier != other.carrier
3568
+ return false
3569
+ end
3570
+ if @cell_id != other.cell_id
3571
+ return false
3572
+ end
3573
+ if @lac != other.lac
3574
+ return false
3575
+ end
3576
+
3577
+ true
3578
+ end
3579
+
3580
+ end
3581
+
3582
+ # Record type CheckOptions
3583
+ class CheckOptions
3584
+ attr_reader :c2pa_trust_anchors, :cawg_trust_anchors, :cawg_allowed_list, :media, :thumbnail_max_dim, :gateway, :max_input_bytes
3585
+
3586
+ def initialize(c2pa_trust_anchors: nil, cawg_trust_anchors: nil, cawg_allowed_list: nil, media: nil, thumbnail_max_dim: nil, gateway: nil, max_input_bytes: nil)
3587
+ @c2pa_trust_anchors = c2pa_trust_anchors
3588
+ @cawg_trust_anchors = cawg_trust_anchors
3589
+ @cawg_allowed_list = cawg_allowed_list
3590
+ @media = media
3591
+ @thumbnail_max_dim = thumbnail_max_dim
3592
+ @gateway = gateway
3593
+ @max_input_bytes = max_input_bytes
3594
+ end
3595
+
3596
+ def ==(other)
3597
+ if @c2pa_trust_anchors != other.c2pa_trust_anchors
3598
+ return false
3599
+ end
3600
+ if @cawg_trust_anchors != other.cawg_trust_anchors
3601
+ return false
3602
+ end
3603
+ if @cawg_allowed_list != other.cawg_allowed_list
3604
+ return false
3605
+ end
3606
+ if @media != other.media
3607
+ return false
3608
+ end
3609
+ if @thumbnail_max_dim != other.thumbnail_max_dim
3610
+ return false
3611
+ end
3612
+ if @gateway != other.gateway
3613
+ return false
3614
+ end
3615
+ if @max_input_bytes != other.max_input_bytes
3616
+ return false
3617
+ end
3618
+
3619
+ true
3620
+ end
3621
+
3622
+ end
3623
+
3624
+ # Record type DeviceData
3625
+ class DeviceData
3626
+ attr_reader :manufacturer, :model, :os_version, :device_id
3627
+
3628
+ def initialize(manufacturer:, model:, os_version:, device_id:)
3629
+ @manufacturer = manufacturer
3630
+ @model = model
3631
+ @os_version = os_version
3632
+ @device_id = device_id
3633
+ end
3634
+
3635
+ def ==(other)
3636
+ if @manufacturer != other.manufacturer
3637
+ return false
3638
+ end
3639
+ if @model != other.model
3640
+ return false
3641
+ end
3642
+ if @os_version != other.os_version
3643
+ return false
3644
+ end
3645
+ if @device_id != other.device_id
3646
+ return false
3647
+ end
3648
+
3649
+ true
3650
+ end
3651
+
3652
+ end
3653
+
3654
+ # Record type LocationData
3655
+ class LocationData
3656
+ attr_reader :latitude, :longitude, :altitude, :accuracy, :provider
3657
+
3658
+ def initialize(latitude:, longitude:, altitude:, accuracy:, provider:)
3659
+ @latitude = latitude
3660
+ @longitude = longitude
3661
+ @altitude = altitude
3662
+ @accuracy = accuracy
3663
+ @provider = provider
3664
+ end
3665
+
3666
+ def ==(other)
3667
+ if @latitude != other.latitude
3668
+ return false
3669
+ end
3670
+ if @longitude != other.longitude
3671
+ return false
3672
+ end
3673
+ if @altitude != other.altitude
3674
+ return false
3675
+ end
3676
+ if @accuracy != other.accuracy
3677
+ return false
3678
+ end
3679
+ if @provider != other.provider
3680
+ return false
3681
+ end
3682
+
3683
+ true
3684
+ end
3685
+
3686
+ end
3687
+
3688
+ # Record type NetworkData
3689
+ class NetworkData
3690
+ attr_reader :network_type, :wifi_ssid, :cell_info
3691
+
3692
+ def initialize(network_type:, wifi_ssid:, cell_info:)
3693
+ @network_type = network_type
3694
+ @wifi_ssid = wifi_ssid
3695
+ @cell_info = cell_info
3696
+ end
3697
+
3698
+ def ==(other)
3699
+ if @network_type != other.network_type
3700
+ return false
3701
+ end
3702
+ if @wifi_ssid != other.wifi_ssid
3703
+ return false
3704
+ end
3705
+ if @cell_info != other.cell_info
3706
+ return false
3707
+ end
3708
+
3709
+ true
3710
+ end
3711
+
3712
+ end
3713
+
3714
+ # Record type ProofModeConfig
3715
+ class ProofModeConfig
3716
+ attr_reader :auto_notarize, :track_location, :track_device_id, :track_network, :add_credentials, :embed_c2pa, :digital_source_type, :c2pa_credentials
3717
+
3718
+ def initialize(auto_notarize:, track_location:, track_device_id:, track_network:, add_credentials:, embed_c2pa:, digital_source_type: nil, c2pa_credentials: nil)
3719
+ @auto_notarize = auto_notarize
3720
+ @track_location = track_location
3721
+ @track_device_id = track_device_id
3722
+ @track_network = track_network
3723
+ @add_credentials = add_credentials
3724
+ @embed_c2pa = embed_c2pa
3725
+ @digital_source_type = digital_source_type
3726
+ @c2pa_credentials = c2pa_credentials
3727
+ end
3728
+
3729
+ def ==(other)
3730
+ if @auto_notarize != other.auto_notarize
3731
+ return false
3732
+ end
3733
+ if @track_location != other.track_location
3734
+ return false
3735
+ end
3736
+ if @track_device_id != other.track_device_id
3737
+ return false
3738
+ end
3739
+ if @track_network != other.track_network
3740
+ return false
3741
+ end
3742
+ if @add_credentials != other.add_credentials
3743
+ return false
3744
+ end
3745
+ if @embed_c2pa != other.embed_c2pa
3746
+ return false
3747
+ end
3748
+ if @digital_source_type != other.digital_source_type
3749
+ return false
3750
+ end
3751
+ if @c2pa_credentials != other.c2pa_credentials
3752
+ return false
3753
+ end
3754
+
3755
+ true
3756
+ end
3757
+
3758
+ end
3759
+
3760
+
3761
+
3762
+
3763
+
3764
+ def self.check_cids(cids, fetcher, options = nil, listener = nil)
3765
+ cids = cids.map { |v| ::Proofmode::uniffi_utf8(v) }
3766
+ RustBuffer.check_lower_Sequencestring(cids)
3767
+
3768
+ fetcher = fetcher
3769
+ (UrlFetcher.uniffi_check_lower fetcher)
3770
+
3771
+ options = (options ? options : nil)
3772
+ RustBuffer.check_lower_OptionalTypeCheckOptions(options)
3773
+
3774
+ listener = (listener ? listener : nil)
3775
+ RustBuffer.check_lower_OptionalTypeProgressListener(listener)
3776
+
3777
+ result =
3778
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_func_check_cids,RustBuffer.alloc_from_Sequencestring(cids),(UrlFetcher.uniffi_lower fetcher),RustBuffer.alloc_from_OptionalTypeCheckOptions(options),RustBuffer.alloc_from_OptionalTypeProgressListener(listener))
3779
+ return result.consume_into_string
3780
+ end
3781
+
3782
+
3783
+
3784
+
3785
+
3786
+ def self.check_files(file_paths, options = nil, listener = nil)
3787
+ file_paths = file_paths.map { |v| ::Proofmode::uniffi_utf8(v) }
3788
+ RustBuffer.check_lower_Sequencestring(file_paths)
3789
+
3790
+ options = (options ? options : nil)
3791
+ RustBuffer.check_lower_OptionalTypeCheckOptions(options)
3792
+
3793
+ listener = (listener ? listener : nil)
3794
+ RustBuffer.check_lower_OptionalTypeProgressListener(listener)
3795
+
3796
+ result =
3797
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_func_check_files,RustBuffer.alloc_from_Sequencestring(file_paths),RustBuffer.alloc_from_OptionalTypeCheckOptions(options),RustBuffer.alloc_from_OptionalTypeProgressListener(listener))
3798
+ return result.consume_into_string
3799
+ end
3800
+
3801
+
3802
+
3803
+
3804
+
3805
+ def self.check_urls(urls, fetcher, options = nil, listener = nil)
3806
+ urls = urls.map { |v| ::Proofmode::uniffi_utf8(v) }
3807
+ RustBuffer.check_lower_Sequencestring(urls)
3808
+
3809
+ fetcher = fetcher
3810
+ (UrlFetcher.uniffi_check_lower fetcher)
3811
+
3812
+ options = (options ? options : nil)
3813
+ RustBuffer.check_lower_OptionalTypeCheckOptions(options)
3814
+
3815
+ listener = (listener ? listener : nil)
3816
+ RustBuffer.check_lower_OptionalTypeProgressListener(listener)
3817
+
3818
+ result =
3819
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_func_check_urls,RustBuffer.alloc_from_Sequencestring(urls),(UrlFetcher.uniffi_lower fetcher),RustBuffer.alloc_from_OptionalTypeCheckOptions(options),RustBuffer.alloc_from_OptionalTypeProgressListener(listener))
3820
+ return result.consume_into_string
3821
+ end
3822
+
3823
+
3824
+
3825
+
3826
+
3827
+ def self.generate_proof(media_data, metadata, config, callbacks)
3828
+ media_data = ::Proofmode::uniffi_bytes(media_data)
3829
+
3830
+
3831
+ metadata = metadata.each.with_object({}) { |(k, v), res| res[::Proofmode::uniffi_utf8(k)] = ::Proofmode::uniffi_utf8(v) }
3832
+ RustBuffer.check_lower_MapStringString(metadata)
3833
+
3834
+ config = config
3835
+ RustBuffer.check_lower_TypeProofModeConfig(config)
3836
+
3837
+ callbacks = callbacks
3838
+ (ProofModeCallbacks.uniffi_check_lower callbacks)
3839
+
3840
+ result =
3841
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_func_generate_proof,RustBuffer.alloc_from_bytes(media_data),RustBuffer.alloc_from_MapStringString(metadata),RustBuffer.alloc_from_TypeProofModeConfig(config),(ProofModeCallbacks.uniffi_lower callbacks))
3842
+ return result.consume_into_string
3843
+ end
3844
+
3845
+
3846
+
3847
+
3848
+
3849
+ def self.generate_proof_for_file(file_path, storage_path, options)
3850
+ file_path = ::Proofmode::uniffi_utf8(file_path)
3851
+
3852
+
3853
+ storage_path = ::Proofmode::uniffi_utf8(storage_path)
3854
+
3855
+
3856
+ options = options
3857
+ RustBuffer.check_lower_TypeFileProofOptions(options)
3858
+
3859
+ result =
3860
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_func_generate_proof_for_file,RustBuffer.alloc_from_string(file_path),RustBuffer.alloc_from_string(storage_path),RustBuffer.alloc_from_TypeFileProofOptions(options))
3861
+ return result.consume_into_string
3862
+ end
3863
+
3864
+
3865
+
3866
+
3867
+
3868
+ def self.get_version()
3869
+ result =
3870
+ ::Proofmode.rust_call(:uniffi_proofmode_fn_func_get_version,)
3871
+ return result.consume_into_string
3872
+ end
3873
+
3874
+
3875
+
3876
+
3877
+
3878
+ def self.media_sha256(media_data)
3879
+ media_data = ::Proofmode::uniffi_bytes(media_data)
3880
+
3881
+
3882
+ result =
3883
+ ::Proofmode.rust_call(:uniffi_proofmode_fn_func_media_sha256,RustBuffer.alloc_from_bytes(media_data))
3884
+ return result.consume_into_string
3885
+ end
3886
+
3887
+
3888
+
3889
+
3890
+
3891
+ class ProgressListener
3892
+
3893
+ # A private helper for initializing instances of the class from a raw handle,
3894
+ # bypassing any initialization logic and ensuring they are GC'd properly.
3895
+ def self.uniffi_allocate(handle)
3896
+ inst = allocate
3897
+ inst.instance_variable_set :@handle, handle
3898
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
3899
+ return inst
3900
+ end
3901
+
3902
+ # A private helper for registering an object finalizer.
3903
+ # N.B. it's important that this does not capture a reference
3904
+ # to the actual instance, only its underlying handle.
3905
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
3906
+ Proc.new do |_id|
3907
+ ::Proofmode.rust_call(
3908
+ :uniffi_proofmode_fn_free_progresslistener,
3909
+ handle
3910
+ )
3911
+ end
3912
+ end
3913
+ # HandleMap for trait interface: stores Ruby-native objects keyed by odd handles.
3914
+ @uniffi_handle_map = UniffiHandleMap.new
3915
+
3916
+ class << self
3917
+ attr_reader :uniffi_handle_map
3918
+ end
3919
+
3920
+ # For trait interfaces: check that the object is either a Rust-backed instance or
3921
+ # responds to the required interface methods.
3922
+ def self.uniffi_check_lower(inst)
3923
+ if !inst.respond_to?(:on_progress)
3924
+ raise TypeError.new "Expected a ProgressListener instance or an object implementing the interface, got #{inst}"
3925
+ end
3926
+ end
3927
+
3928
+ def uniffi_clone_handle
3929
+ return ::Proofmode.rust_call(
3930
+ :uniffi_proofmode_fn_clone_progresslistener,
3931
+ @handle
3932
+ )
3933
+ end
3934
+
3935
+ # For trait interfaces: lowering distinguishes between Rust-backed and Ruby-native instances.
3936
+ def self.uniffi_lower(inst)
3937
+ if inst.is_a?(self) && inst.instance_variable_defined?(:@handle)
3938
+ inst.uniffi_clone_handle()
3939
+ else
3940
+ @uniffi_handle_map.insert(inst)
3941
+ end
3942
+ end
3943
+
3944
+ # For trait interfaces: lifting distinguishes even handles (Rust) from odd handles (Ruby).
3945
+ def self.uniffi_lift(handle)
3946
+ if (handle & 1) == 0
3947
+ uniffi_allocate handle
3948
+ else
3949
+ @uniffi_handle_map.remove handle
3950
+ end
3951
+ end
3952
+
3953
+
3954
+
3955
+ def on_progress(event)
3956
+ event = event
3957
+ RustBuffer.check_lower_TypeProgressEvent(event)
3958
+
3959
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_progresslistener_on_progress,uniffi_clone_handle(),RustBuffer.alloc_from_TypeProgressEvent(event))
3960
+ end
3961
+
3962
+
3963
+ end
3964
+
3965
+
3966
+ # Trait interface vtable implementation for ProgressListener.
3967
+ module UniffiCallbackInterfaceProgressListener
3968
+ # Callback method for on_progress
3969
+ ON_PROGRESS_CALLBACK = Proc.new do |uniffi_handle, event, uniffi_out_return, uniffi_call_status|
3970
+ uniffi_obj = ProgressListener.uniffi_handle_map.get(uniffi_handle)
3971
+ make_call = Proc.new do
3972
+ uniffi_obj.on_progress(
3973
+ event.consume_into_TypeProgressEvent
3974
+ )
3975
+ end
3976
+ # No return value, so do nothing
3977
+ write_return_value = Proc.new { |_v| }
3978
+ ::Proofmode.uniffi_trait_interface_call(
3979
+ uniffi_call_status,
3980
+ make_call,
3981
+ write_return_value,
3982
+ ProofModeError,
3983
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
3984
+ )
3985
+ end
3986
+
3987
+ # Free callback: removes the handle from the map.
3988
+ UNIFFI_FREE_CALLBACK = Proc.new do |uniffi_handle|
3989
+ ProgressListener.uniffi_handle_map.remove uniffi_handle
3990
+ end
3991
+
3992
+ # Clone callback: clones the handle in the map.
3993
+ UNIFFI_CLONE_CALLBACK = Proc.new do |uniffi_handle|
3994
+ ProgressListener.uniffi_handle_map.clone_handle(uniffi_handle)
3995
+ end
3996
+
3997
+ # Create the VTable struct instance.
3998
+ UNIFFI_VTABLE = UniFFILib::VTableCallbackInterfaceProgressListener.new
3999
+ UNIFFI_VTABLE[:uniffi_free] = UNIFFI_FREE_CALLBACK
4000
+ UNIFFI_VTABLE[:uniffi_clone] = UNIFFI_CLONE_CALLBACK
4001
+ UNIFFI_VTABLE[:on_progress] = ON_PROGRESS_CALLBACK
4002
+
4003
+ # Register the VTable with Rust.
4004
+ UniFFILib.uniffi_proofmode_fn_init_callback_vtable_progresslistener(UNIFFI_VTABLE)
4005
+ end
4006
+
4007
+ class ProofModeCallbacks
4008
+
4009
+ # A private helper for initializing instances of the class from a raw handle,
4010
+ # bypassing any initialization logic and ensuring they are GC'd properly.
4011
+ def self.uniffi_allocate(handle)
4012
+ inst = allocate
4013
+ inst.instance_variable_set :@handle, handle
4014
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
4015
+ return inst
4016
+ end
4017
+
4018
+ # A private helper for registering an object finalizer.
4019
+ # N.B. it's important that this does not capture a reference
4020
+ # to the actual instance, only its underlying handle.
4021
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
4022
+ Proc.new do |_id|
4023
+ ::Proofmode.rust_call(
4024
+ :uniffi_proofmode_fn_free_proofmodecallbacks,
4025
+ handle
4026
+ )
4027
+ end
4028
+ end
4029
+ # HandleMap for trait interface: stores Ruby-native objects keyed by odd handles.
4030
+ @uniffi_handle_map = UniffiHandleMap.new
4031
+
4032
+ class << self
4033
+ attr_reader :uniffi_handle_map
4034
+ end
4035
+
4036
+ # For trait interfaces: check that the object is either a Rust-backed instance or
4037
+ # responds to the required interface methods.
4038
+ def self.uniffi_check_lower(inst)
4039
+ if !inst.respond_to?(:get_location)
4040
+ raise TypeError.new "Expected a ProofModeCallbacks instance or an object implementing the interface, got #{inst}"
4041
+ end
4042
+ if !inst.respond_to?(:get_device_info)
4043
+ raise TypeError.new "Expected a ProofModeCallbacks instance or an object implementing the interface, got #{inst}"
4044
+ end
4045
+ if !inst.respond_to?(:get_network_info)
4046
+ raise TypeError.new "Expected a ProofModeCallbacks instance or an object implementing the interface, got #{inst}"
4047
+ end
4048
+ if !inst.respond_to?(:save_data)
4049
+ raise TypeError.new "Expected a ProofModeCallbacks instance or an object implementing the interface, got #{inst}"
4050
+ end
4051
+ if !inst.respond_to?(:save_text)
4052
+ raise TypeError.new "Expected a ProofModeCallbacks instance or an object implementing the interface, got #{inst}"
4053
+ end
4054
+ if !inst.respond_to?(:sign_data)
4055
+ raise TypeError.new "Expected a ProofModeCallbacks instance or an object implementing the interface, got #{inst}"
4056
+ end
4057
+ if !inst.respond_to?(:notarize_hash)
4058
+ raise TypeError.new "Expected a ProofModeCallbacks instance or an object implementing the interface, got #{inst}"
4059
+ end
4060
+ if !inst.respond_to?(:report_progress)
4061
+ raise TypeError.new "Expected a ProofModeCallbacks instance or an object implementing the interface, got #{inst}"
4062
+ end
4063
+ end
4064
+
4065
+ def uniffi_clone_handle
4066
+ return ::Proofmode.rust_call(
4067
+ :uniffi_proofmode_fn_clone_proofmodecallbacks,
4068
+ @handle
4069
+ )
4070
+ end
4071
+
4072
+ # For trait interfaces: lowering distinguishes between Rust-backed and Ruby-native instances.
4073
+ def self.uniffi_lower(inst)
4074
+ if inst.is_a?(self) && inst.instance_variable_defined?(:@handle)
4075
+ inst.uniffi_clone_handle()
4076
+ else
4077
+ @uniffi_handle_map.insert(inst)
4078
+ end
4079
+ end
4080
+
4081
+ # For trait interfaces: lifting distinguishes even handles (Rust) from odd handles (Ruby).
4082
+ def self.uniffi_lift(handle)
4083
+ if (handle & 1) == 0
4084
+ uniffi_allocate handle
4085
+ else
4086
+ @uniffi_handle_map.remove handle
4087
+ end
4088
+ end
4089
+
4090
+
4091
+
4092
+ def get_location()
4093
+ result =
4094
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_proofmodecallbacks_get_location,uniffi_clone_handle(),)
4095
+ return result.consume_into_OptionalTypeLocationData
4096
+ end
4097
+ def get_device_info()
4098
+ result =
4099
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_proofmodecallbacks_get_device_info,uniffi_clone_handle(),)
4100
+ return result.consume_into_OptionalTypeDeviceData
4101
+ end
4102
+ def get_network_info()
4103
+ result =
4104
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_proofmodecallbacks_get_network_info,uniffi_clone_handle(),)
4105
+ return result.consume_into_OptionalTypeNetworkData
4106
+ end
4107
+ def save_data(hash, filename, data)
4108
+ hash = ::Proofmode::uniffi_utf8(hash)
4109
+
4110
+ filename = ::Proofmode::uniffi_utf8(filename)
4111
+
4112
+ data = ::Proofmode::uniffi_bytes(data)
4113
+
4114
+
4115
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_proofmodecallbacks_save_data,uniffi_clone_handle(),RustBuffer.alloc_from_string(hash),RustBuffer.alloc_from_string(filename),RustBuffer.alloc_from_bytes(data))
4116
+ end
4117
+
4118
+ def save_text(hash, filename, text)
4119
+ hash = ::Proofmode::uniffi_utf8(hash)
4120
+
4121
+ filename = ::Proofmode::uniffi_utf8(filename)
4122
+
4123
+ text = ::Proofmode::uniffi_utf8(text)
4124
+
4125
+
4126
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_proofmodecallbacks_save_text,uniffi_clone_handle(),RustBuffer.alloc_from_string(hash),RustBuffer.alloc_from_string(filename),RustBuffer.alloc_from_string(text))
4127
+ end
4128
+
4129
+ def sign_data(data)
4130
+ data = ::Proofmode::uniffi_bytes(data)
4131
+
4132
+ result =
4133
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_proofmodecallbacks_sign_data,uniffi_clone_handle(),RustBuffer.alloc_from_bytes(data))
4134
+ return result.consume_into_Optionalbytes
4135
+ end
4136
+ def notarize_hash(hash)
4137
+ hash = ::Proofmode::uniffi_utf8(hash)
4138
+
4139
+ result =
4140
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_proofmodecallbacks_notarize_hash,uniffi_clone_handle(),RustBuffer.alloc_from_string(hash))
4141
+ return result.consume_into_Optionalbytes
4142
+ end
4143
+ def report_progress(message)
4144
+ message = ::Proofmode::uniffi_utf8(message)
4145
+
4146
+
4147
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_proofmodecallbacks_report_progress,uniffi_clone_handle(),RustBuffer.alloc_from_string(message))
4148
+ end
4149
+
4150
+
4151
+ end
4152
+
4153
+
4154
+ # Trait interface vtable implementation for ProofModeCallbacks.
4155
+ module UniffiCallbackInterfaceProofModeCallbacks
4156
+ # Callback method for get_location
4157
+ GET_LOCATION_CALLBACK = Proc.new do |uniffi_handle, uniffi_out_return, uniffi_call_status|
4158
+ uniffi_obj = ProofModeCallbacks.uniffi_handle_map.get(uniffi_handle)
4159
+ make_call = Proc.new do
4160
+ uniffi_obj.get_location(
4161
+ )
4162
+ end
4163
+ write_return_value = Proc.new do |v|
4164
+ lowered = RustBuffer.alloc_from_OptionalTypeLocationData(v)
4165
+ # Write a RustBuffer struct into the out pointer
4166
+ out_buf = RustBuffer.new uniffi_out_return
4167
+ out_buf[:capacity] = lowered[:capacity]
4168
+ out_buf[:len] = lowered[:len]
4169
+ out_buf[:data] = lowered[:data]
4170
+ end
4171
+ ::Proofmode.uniffi_trait_interface_call(
4172
+ uniffi_call_status,
4173
+ make_call,
4174
+ write_return_value,
4175
+ ProofModeError,
4176
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
4177
+ )
4178
+ end
4179
+ # Callback method for get_device_info
4180
+ GET_DEVICE_INFO_CALLBACK = Proc.new do |uniffi_handle, uniffi_out_return, uniffi_call_status|
4181
+ uniffi_obj = ProofModeCallbacks.uniffi_handle_map.get(uniffi_handle)
4182
+ make_call = Proc.new do
4183
+ uniffi_obj.get_device_info(
4184
+ )
4185
+ end
4186
+ write_return_value = Proc.new do |v|
4187
+ lowered = RustBuffer.alloc_from_OptionalTypeDeviceData(v)
4188
+ # Write a RustBuffer struct into the out pointer
4189
+ out_buf = RustBuffer.new uniffi_out_return
4190
+ out_buf[:capacity] = lowered[:capacity]
4191
+ out_buf[:len] = lowered[:len]
4192
+ out_buf[:data] = lowered[:data]
4193
+ end
4194
+ ::Proofmode.uniffi_trait_interface_call(
4195
+ uniffi_call_status,
4196
+ make_call,
4197
+ write_return_value,
4198
+ ProofModeError,
4199
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
4200
+ )
4201
+ end
4202
+ # Callback method for get_network_info
4203
+ GET_NETWORK_INFO_CALLBACK = Proc.new do |uniffi_handle, uniffi_out_return, uniffi_call_status|
4204
+ uniffi_obj = ProofModeCallbacks.uniffi_handle_map.get(uniffi_handle)
4205
+ make_call = Proc.new do
4206
+ uniffi_obj.get_network_info(
4207
+ )
4208
+ end
4209
+ write_return_value = Proc.new do |v|
4210
+ lowered = RustBuffer.alloc_from_OptionalTypeNetworkData(v)
4211
+ # Write a RustBuffer struct into the out pointer
4212
+ out_buf = RustBuffer.new uniffi_out_return
4213
+ out_buf[:capacity] = lowered[:capacity]
4214
+ out_buf[:len] = lowered[:len]
4215
+ out_buf[:data] = lowered[:data]
4216
+ end
4217
+ ::Proofmode.uniffi_trait_interface_call(
4218
+ uniffi_call_status,
4219
+ make_call,
4220
+ write_return_value,
4221
+ ProofModeError,
4222
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
4223
+ )
4224
+ end
4225
+ # Callback method for save_data
4226
+ SAVE_DATA_CALLBACK = Proc.new do |uniffi_handle, hash, filename, data, uniffi_out_return, uniffi_call_status|
4227
+ uniffi_obj = ProofModeCallbacks.uniffi_handle_map.get(uniffi_handle)
4228
+ make_call = Proc.new do
4229
+ uniffi_obj.save_data(
4230
+ hash.consume_into_string,
4231
+ filename.consume_into_string,
4232
+ data.consume_into_bytes
4233
+ )
4234
+ end
4235
+ # No return value, so do nothing
4236
+ write_return_value = Proc.new { |_v| }
4237
+ ::Proofmode.uniffi_trait_interface_call(
4238
+ uniffi_call_status,
4239
+ make_call,
4240
+ write_return_value,
4241
+ ProofModeError,
4242
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
4243
+ )
4244
+ end
4245
+ # Callback method for save_text
4246
+ SAVE_TEXT_CALLBACK = Proc.new do |uniffi_handle, hash, filename, text, uniffi_out_return, uniffi_call_status|
4247
+ uniffi_obj = ProofModeCallbacks.uniffi_handle_map.get(uniffi_handle)
4248
+ make_call = Proc.new do
4249
+ uniffi_obj.save_text(
4250
+ hash.consume_into_string,
4251
+ filename.consume_into_string,
4252
+ text.consume_into_string
4253
+ )
4254
+ end
4255
+ # No return value, so do nothing
4256
+ write_return_value = Proc.new { |_v| }
4257
+ ::Proofmode.uniffi_trait_interface_call(
4258
+ uniffi_call_status,
4259
+ make_call,
4260
+ write_return_value,
4261
+ ProofModeError,
4262
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
4263
+ )
4264
+ end
4265
+ # Callback method for sign_data
4266
+ SIGN_DATA_CALLBACK = Proc.new do |uniffi_handle, data, uniffi_out_return, uniffi_call_status|
4267
+ uniffi_obj = ProofModeCallbacks.uniffi_handle_map.get(uniffi_handle)
4268
+ make_call = Proc.new do
4269
+ uniffi_obj.sign_data(
4270
+ data.consume_into_bytes
4271
+ )
4272
+ end
4273
+ write_return_value = Proc.new do |v|
4274
+ lowered = RustBuffer.alloc_from_Optionalbytes(v)
4275
+ # Write a RustBuffer struct into the out pointer
4276
+ out_buf = RustBuffer.new uniffi_out_return
4277
+ out_buf[:capacity] = lowered[:capacity]
4278
+ out_buf[:len] = lowered[:len]
4279
+ out_buf[:data] = lowered[:data]
4280
+ end
4281
+ ::Proofmode.uniffi_trait_interface_call(
4282
+ uniffi_call_status,
4283
+ make_call,
4284
+ write_return_value,
4285
+ ProofModeError,
4286
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
4287
+ )
4288
+ end
4289
+ # Callback method for notarize_hash
4290
+ NOTARIZE_HASH_CALLBACK = Proc.new do |uniffi_handle, hash, uniffi_out_return, uniffi_call_status|
4291
+ uniffi_obj = ProofModeCallbacks.uniffi_handle_map.get(uniffi_handle)
4292
+ make_call = Proc.new do
4293
+ uniffi_obj.notarize_hash(
4294
+ hash.consume_into_string
4295
+ )
4296
+ end
4297
+ write_return_value = Proc.new do |v|
4298
+ lowered = RustBuffer.alloc_from_Optionalbytes(v)
4299
+ # Write a RustBuffer struct into the out pointer
4300
+ out_buf = RustBuffer.new uniffi_out_return
4301
+ out_buf[:capacity] = lowered[:capacity]
4302
+ out_buf[:len] = lowered[:len]
4303
+ out_buf[:data] = lowered[:data]
4304
+ end
4305
+ ::Proofmode.uniffi_trait_interface_call(
4306
+ uniffi_call_status,
4307
+ make_call,
4308
+ write_return_value,
4309
+ ProofModeError,
4310
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
4311
+ )
4312
+ end
4313
+ # Callback method for report_progress
4314
+ REPORT_PROGRESS_CALLBACK = Proc.new do |uniffi_handle, message, uniffi_out_return, uniffi_call_status|
4315
+ uniffi_obj = ProofModeCallbacks.uniffi_handle_map.get(uniffi_handle)
4316
+ make_call = Proc.new do
4317
+ uniffi_obj.report_progress(
4318
+ message.consume_into_string
4319
+ )
4320
+ end
4321
+ # No return value, so do nothing
4322
+ write_return_value = Proc.new { |_v| }
4323
+ ::Proofmode.uniffi_trait_interface_call(
4324
+ uniffi_call_status,
4325
+ make_call,
4326
+ write_return_value,
4327
+ ProofModeError,
4328
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
4329
+ )
4330
+ end
4331
+
4332
+ # Free callback: removes the handle from the map.
4333
+ UNIFFI_FREE_CALLBACK = Proc.new do |uniffi_handle|
4334
+ ProofModeCallbacks.uniffi_handle_map.remove uniffi_handle
4335
+ end
4336
+
4337
+ # Clone callback: clones the handle in the map.
4338
+ UNIFFI_CLONE_CALLBACK = Proc.new do |uniffi_handle|
4339
+ ProofModeCallbacks.uniffi_handle_map.clone_handle(uniffi_handle)
4340
+ end
4341
+
4342
+ # Create the VTable struct instance.
4343
+ UNIFFI_VTABLE = UniFFILib::VTableCallbackInterfaceProofModeCallbacks.new
4344
+ UNIFFI_VTABLE[:uniffi_free] = UNIFFI_FREE_CALLBACK
4345
+ UNIFFI_VTABLE[:uniffi_clone] = UNIFFI_CLONE_CALLBACK
4346
+ UNIFFI_VTABLE[:get_location] = GET_LOCATION_CALLBACK
4347
+ UNIFFI_VTABLE[:get_device_info] = GET_DEVICE_INFO_CALLBACK
4348
+ UNIFFI_VTABLE[:get_network_info] = GET_NETWORK_INFO_CALLBACK
4349
+ UNIFFI_VTABLE[:save_data] = SAVE_DATA_CALLBACK
4350
+ UNIFFI_VTABLE[:save_text] = SAVE_TEXT_CALLBACK
4351
+ UNIFFI_VTABLE[:sign_data] = SIGN_DATA_CALLBACK
4352
+ UNIFFI_VTABLE[:notarize_hash] = NOTARIZE_HASH_CALLBACK
4353
+ UNIFFI_VTABLE[:report_progress] = REPORT_PROGRESS_CALLBACK
4354
+
4355
+ # Register the VTable with Rust.
4356
+ UniFFILib.uniffi_proofmode_fn_init_callback_vtable_proofmodecallbacks(UNIFFI_VTABLE)
4357
+ end
4358
+
4359
+ class ProofSigner
4360
+
4361
+ # A private helper for initializing instances of the class from a raw handle,
4362
+ # bypassing any initialization logic and ensuring they are GC'd properly.
4363
+ def self.uniffi_allocate(handle)
4364
+ inst = allocate
4365
+ inst.instance_variable_set :@handle, handle
4366
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
4367
+ return inst
4368
+ end
4369
+
4370
+ # A private helper for registering an object finalizer.
4371
+ # N.B. it's important that this does not capture a reference
4372
+ # to the actual instance, only its underlying handle.
4373
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
4374
+ Proc.new do |_id|
4375
+ ::Proofmode.rust_call(
4376
+ :uniffi_proofmode_fn_free_proofsigner,
4377
+ handle
4378
+ )
4379
+ end
4380
+ end
4381
+ # A private helper for lowering instances into a raw handle.
4382
+ # This does an explicit typecheck, because accidentally lowering a different type of
4383
+ # object in a place where this type is expected, could lead to memory unsafety.
4384
+ def self.uniffi_check_lower(inst)
4385
+ if !inst.is_a? self
4386
+ raise TypeError.new "Expected a ProofSigner instance, got #{inst}"
4387
+ end
4388
+ end
4389
+
4390
+ def uniffi_clone_handle()
4391
+ return ::Proofmode.rust_call(
4392
+ :uniffi_proofmode_fn_clone_proofsigner,
4393
+ @handle
4394
+ )
4395
+ end
4396
+
4397
+ def self.uniffi_lower(inst)
4398
+ return inst.uniffi_clone_handle()
4399
+ end
4400
+
4401
+ def self.uniffi_lift(handle)
4402
+ uniffi_allocate handle
4403
+ end
4404
+
4405
+
4406
+ def self.open(storage_path, passphrase, email)
4407
+ storage_path = ::Proofmode::uniffi_utf8(storage_path)
4408
+
4409
+ passphrase = ::Proofmode::uniffi_utf8(passphrase)
4410
+
4411
+ email = (email ? ::Proofmode::uniffi_utf8(email) : nil)
4412
+ RustBuffer.check_lower_Optionalstring(email)
4413
+ # Call the (fallible) function before creating any half-baked object instances.
4414
+ # Lightly yucky way to bypass the usual "initialize" logic
4415
+ # and just create a new instance with the required handle.
4416
+ return uniffi_allocate(
4417
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofSignerError),:uniffi_proofmode_fn_constructor_proofsigner_open,RustBuffer.alloc_from_string(storage_path),RustBuffer.alloc_from_string(passphrase),RustBuffer.alloc_from_Optionalstring(email)))
4418
+ end
4419
+
4420
+
4421
+ def public_key()
4422
+ result =
4423
+ ::Proofmode.rust_call(:uniffi_proofmode_fn_method_proofsigner_public_key,uniffi_clone_handle(),)
4424
+ return result.consume_into_string
4425
+ end
4426
+ def sign(data)
4427
+ data = ::Proofmode::uniffi_bytes(data)
4428
+
4429
+ result =
4430
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofSignerError),:uniffi_proofmode_fn_method_proofsigner_sign,uniffi_clone_handle(),RustBuffer.alloc_from_bytes(data))
4431
+ return result.consume_into_bytes
4432
+ end
4433
+
4434
+ end
4435
+
4436
+ class UrlFetcher
4437
+
4438
+ # A private helper for initializing instances of the class from a raw handle,
4439
+ # bypassing any initialization logic and ensuring they are GC'd properly.
4440
+ def self.uniffi_allocate(handle)
4441
+ inst = allocate
4442
+ inst.instance_variable_set :@handle, handle
4443
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
4444
+ return inst
4445
+ end
4446
+
4447
+ # A private helper for registering an object finalizer.
4448
+ # N.B. it's important that this does not capture a reference
4449
+ # to the actual instance, only its underlying handle.
4450
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
4451
+ Proc.new do |_id|
4452
+ ::Proofmode.rust_call(
4453
+ :uniffi_proofmode_fn_free_urlfetcher,
4454
+ handle
4455
+ )
4456
+ end
4457
+ end
4458
+ # HandleMap for trait interface: stores Ruby-native objects keyed by odd handles.
4459
+ @uniffi_handle_map = UniffiHandleMap.new
4460
+
4461
+ class << self
4462
+ attr_reader :uniffi_handle_map
4463
+ end
4464
+
4465
+ # For trait interfaces: check that the object is either a Rust-backed instance or
4466
+ # responds to the required interface methods.
4467
+ def self.uniffi_check_lower(inst)
4468
+ if !inst.respond_to?(:get)
4469
+ raise TypeError.new "Expected a UrlFetcher instance or an object implementing the interface, got #{inst}"
4470
+ end
4471
+ end
4472
+
4473
+ def uniffi_clone_handle
4474
+ return ::Proofmode.rust_call(
4475
+ :uniffi_proofmode_fn_clone_urlfetcher,
4476
+ @handle
4477
+ )
4478
+ end
4479
+
4480
+ # For trait interfaces: lowering distinguishes between Rust-backed and Ruby-native instances.
4481
+ def self.uniffi_lower(inst)
4482
+ if inst.is_a?(self) && inst.instance_variable_defined?(:@handle)
4483
+ inst.uniffi_clone_handle()
4484
+ else
4485
+ @uniffi_handle_map.insert(inst)
4486
+ end
4487
+ end
4488
+
4489
+ # For trait interfaces: lifting distinguishes even handles (Rust) from odd handles (Ruby).
4490
+ def self.uniffi_lift(handle)
4491
+ if (handle & 1) == 0
4492
+ uniffi_allocate handle
4493
+ else
4494
+ @uniffi_handle_map.remove handle
4495
+ end
4496
+ end
4497
+
4498
+
4499
+
4500
+ def get(url, accept)
4501
+ url = ::Proofmode::uniffi_utf8(url)
4502
+
4503
+ accept = (accept ? ::Proofmode::uniffi_utf8(accept) : nil)
4504
+ RustBuffer.check_lower_Optionalstring(accept)
4505
+ result =
4506
+ ::Proofmode.rust_call_with_error(::Proofmode::RustBufferStreamMixin.method(:read_TypeProofModeError),:uniffi_proofmode_fn_method_urlfetcher_get,uniffi_clone_handle(),RustBuffer.alloc_from_string(url),RustBuffer.alloc_from_Optionalstring(accept))
4507
+ return result.consume_into_TypeHttpResponse
4508
+ end
4509
+
4510
+ end
4511
+
4512
+
4513
+ # Trait interface vtable implementation for UrlFetcher.
4514
+ module UniffiCallbackInterfaceUrlFetcher
4515
+ # Callback method for get
4516
+ GET_CALLBACK = Proc.new do |uniffi_handle, url, accept, uniffi_out_return, uniffi_call_status|
4517
+ uniffi_obj = UrlFetcher.uniffi_handle_map.get(uniffi_handle)
4518
+ make_call = Proc.new do
4519
+ uniffi_obj.get(
4520
+ url.consume_into_string,
4521
+ accept.consume_into_Optionalstring
4522
+ )
4523
+ end
4524
+ write_return_value = Proc.new do |v|
4525
+ lowered = RustBuffer.alloc_from_TypeHttpResponse(v)
4526
+ # Write a RustBuffer struct into the out pointer
4527
+ out_buf = RustBuffer.new uniffi_out_return
4528
+ out_buf[:capacity] = lowered[:capacity]
4529
+ out_buf[:len] = lowered[:len]
4530
+ out_buf[:data] = lowered[:data]
4531
+ end
4532
+ ::Proofmode.uniffi_trait_interface_call(
4533
+ uniffi_call_status,
4534
+ make_call,
4535
+ write_return_value,
4536
+ ProofModeError,
4537
+ Proc.new { |e| RustBuffer.alloc_from_TypeProofModeError(e) }
4538
+ )
4539
+ end
4540
+
4541
+ # Free callback: removes the handle from the map.
4542
+ UNIFFI_FREE_CALLBACK = Proc.new do |uniffi_handle|
4543
+ UrlFetcher.uniffi_handle_map.remove uniffi_handle
4544
+ end
4545
+
4546
+ # Clone callback: clones the handle in the map.
4547
+ UNIFFI_CLONE_CALLBACK = Proc.new do |uniffi_handle|
4548
+ UrlFetcher.uniffi_handle_map.clone_handle(uniffi_handle)
4549
+ end
4550
+
4551
+ # Create the VTable struct instance.
4552
+ UNIFFI_VTABLE = UniFFILib::VTableCallbackInterfaceUrlFetcher.new
4553
+ UNIFFI_VTABLE[:uniffi_free] = UNIFFI_FREE_CALLBACK
4554
+ UNIFFI_VTABLE[:uniffi_clone] = UNIFFI_CLONE_CALLBACK
4555
+ UNIFFI_VTABLE[:get] = GET_CALLBACK
4556
+
4557
+ # Register the VTable with Rust.
4558
+ UniFFILib.uniffi_proofmode_fn_init_callback_vtable_urlfetcher(UNIFFI_VTABLE)
4559
+ end
4560
+
4561
+
4562
+
4563
+
4564
+ end
4565
+