proofmode 0.8.0
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.
- checksums.yaml +7 -0
- data/lib/libproofmode.so +0 -0
- data/lib/proofmode.rb +1499 -0
- data/lib/proofmode_callbacks.rb +208 -0
- data/proofmode.gemspec +22 -0
- metadata +62 -0
data/lib/proofmode.rb
ADDED
|
@@ -0,0 +1,1499 @@
|
|
|
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
|
+
|
|
18
|
+
|
|
19
|
+
module Proofmode
|
|
20
|
+
def self.uniffi_in_range(i, type_name, min, max)
|
|
21
|
+
raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
|
|
22
|
+
i = i.to_int
|
|
23
|
+
raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
|
|
24
|
+
i
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.uniffi_utf8(v)
|
|
28
|
+
raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
|
|
29
|
+
v = v.to_str.encode(Encoding::UTF_8)
|
|
30
|
+
raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
|
|
31
|
+
v
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.uniffi_bytes(v)
|
|
35
|
+
raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
|
|
36
|
+
v.to_str
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class RustBuffer < FFI::Struct
|
|
40
|
+
layout :capacity, :uint64,
|
|
41
|
+
:len, :uint64,
|
|
42
|
+
:data, :pointer
|
|
43
|
+
|
|
44
|
+
def self.alloc(size)
|
|
45
|
+
return Proofmode.rust_call(:ffi_proofmode_rustbuffer_alloc, size)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.reserve(rbuf, additional)
|
|
49
|
+
return Proofmode.rust_call(:ffi_proofmode_rustbuffer_reserve, rbuf, additional)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def free
|
|
53
|
+
Proofmode.rust_call(:ffi_proofmode_rustbuffer_free, self)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def capacity
|
|
57
|
+
self[:capacity]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def len
|
|
61
|
+
self[:len]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def len=(value)
|
|
65
|
+
self[:len] = value
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def data
|
|
69
|
+
self[:data]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def to_s
|
|
73
|
+
"RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# The allocated buffer will be automatically freed if an error occurs, ensuring that
|
|
77
|
+
# we don't accidentally leak it.
|
|
78
|
+
def self.allocWithBuilder
|
|
79
|
+
builder = RustBufferBuilder.new
|
|
80
|
+
|
|
81
|
+
begin
|
|
82
|
+
yield builder
|
|
83
|
+
rescue => e
|
|
84
|
+
builder.discard
|
|
85
|
+
raise e
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# The RustBuffer will be freed once the context-manager exits, ensuring that we don't
|
|
90
|
+
# leak it even if an error occurs.
|
|
91
|
+
def consumeWithStream
|
|
92
|
+
stream = RustBufferStream.new self
|
|
93
|
+
|
|
94
|
+
yield stream
|
|
95
|
+
|
|
96
|
+
raise RuntimeError, 'junk data left in buffer after consuming' if stream.remaining != 0
|
|
97
|
+
ensure
|
|
98
|
+
free
|
|
99
|
+
end# The primitive String type.
|
|
100
|
+
|
|
101
|
+
def self.allocFromString(value)
|
|
102
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
103
|
+
builder.write value.encode('utf-8')
|
|
104
|
+
return builder.finalize
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def consumeIntoString
|
|
109
|
+
consumeWithStream do |stream|
|
|
110
|
+
return stream.read(stream.remaining).force_encoding(Encoding::UTF_8)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# The primitive Bytes type.
|
|
115
|
+
|
|
116
|
+
def self.allocFromBytes(value)
|
|
117
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
118
|
+
builder.write_Bytes(value)
|
|
119
|
+
return builder.finalize
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def consumeIntoBytes
|
|
124
|
+
consumeWithStream do |stream|
|
|
125
|
+
return stream.readBytes
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# The Record type CellInfo.
|
|
130
|
+
|
|
131
|
+
def self.check_lower_TypeCellInfo(v)
|
|
132
|
+
|
|
133
|
+
RustBuffer.check_lower_Optionalstring(v.cell_id)
|
|
134
|
+
RustBuffer.check_lower_Optionalstring(v.lac)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def self.alloc_from_TypeCellInfo(v)
|
|
138
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
139
|
+
builder.write_TypeCellInfo(v)
|
|
140
|
+
return builder.finalize
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def consumeIntoTypeCellInfo
|
|
145
|
+
consumeWithStream do |stream|
|
|
146
|
+
return stream.readTypeCellInfo
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# The Record type DeviceData.
|
|
151
|
+
|
|
152
|
+
def self.check_lower_TypeDeviceData(v)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
RustBuffer.check_lower_Optionalstring(v.device_id)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def self.alloc_from_TypeDeviceData(v)
|
|
160
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
161
|
+
builder.write_TypeDeviceData(v)
|
|
162
|
+
return builder.finalize
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def consumeIntoTypeDeviceData
|
|
167
|
+
consumeWithStream do |stream|
|
|
168
|
+
return stream.readTypeDeviceData
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# The Record type LocationData.
|
|
173
|
+
|
|
174
|
+
def self.check_lower_TypeLocationData(v)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
RustBuffer.check_lower_Optionalf64(v.altitude)
|
|
178
|
+
RustBuffer.check_lower_Optionalf64(v.accuracy)
|
|
179
|
+
RustBuffer.check_lower_Optionalstring(v.provider)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def self.alloc_from_TypeLocationData(v)
|
|
183
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
184
|
+
builder.write_TypeLocationData(v)
|
|
185
|
+
return builder.finalize
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def consumeIntoTypeLocationData
|
|
190
|
+
consumeWithStream do |stream|
|
|
191
|
+
return stream.readTypeLocationData
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# The Record type NetworkData.
|
|
196
|
+
|
|
197
|
+
def self.check_lower_TypeNetworkData(v)
|
|
198
|
+
|
|
199
|
+
RustBuffer.check_lower_Optionalstring(v.wifi_ssid)
|
|
200
|
+
RustBuffer.check_lower_OptionalTypeCellInfo(v.cell_info)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def self.alloc_from_TypeNetworkData(v)
|
|
204
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
205
|
+
builder.write_TypeNetworkData(v)
|
|
206
|
+
return builder.finalize
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def consumeIntoTypeNetworkData
|
|
211
|
+
consumeWithStream do |stream|
|
|
212
|
+
return stream.readTypeNetworkData
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# The Record type ProofModeConfig.
|
|
217
|
+
|
|
218
|
+
def self.check_lower_TypeProofModeConfig(v)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def self.alloc_from_TypeProofModeConfig(v)
|
|
227
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
228
|
+
builder.write_TypeProofModeConfig(v)
|
|
229
|
+
return builder.finalize
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def consumeIntoTypeProofModeConfig
|
|
234
|
+
consumeWithStream do |stream|
|
|
235
|
+
return stream.readTypeProofModeConfig
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
# The Optional<T> type for f64.
|
|
242
|
+
|
|
243
|
+
def self.check_lower_Optionalf64(v)
|
|
244
|
+
if not v.nil?
|
|
245
|
+
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def self.alloc_from_Optionalf64(v)
|
|
250
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
251
|
+
builder.write_Optionalf64(v)
|
|
252
|
+
return builder.finalize()
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def consumeIntoOptionalf64
|
|
257
|
+
consumeWithStream do |stream|
|
|
258
|
+
return stream.readOptionalf64
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# The Optional<T> type for string.
|
|
263
|
+
|
|
264
|
+
def self.check_lower_Optionalstring(v)
|
|
265
|
+
if not v.nil?
|
|
266
|
+
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def self.alloc_from_Optionalstring(v)
|
|
271
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
272
|
+
builder.write_Optionalstring(v)
|
|
273
|
+
return builder.finalize()
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def consumeIntoOptionalstring
|
|
278
|
+
consumeWithStream do |stream|
|
|
279
|
+
return stream.readOptionalstring
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# The Optional<T> type for bytes.
|
|
284
|
+
|
|
285
|
+
def self.check_lower_Optionalbytes(v)
|
|
286
|
+
if not v.nil?
|
|
287
|
+
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def self.alloc_from_Optionalbytes(v)
|
|
292
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
293
|
+
builder.write_Optionalbytes(v)
|
|
294
|
+
return builder.finalize()
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def consumeIntoOptionalbytes
|
|
299
|
+
consumeWithStream do |stream|
|
|
300
|
+
return stream.readOptionalbytes
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
# The Optional<T> type for TypeCellInfo.
|
|
305
|
+
|
|
306
|
+
def self.check_lower_OptionalTypeCellInfo(v)
|
|
307
|
+
if not v.nil?
|
|
308
|
+
RustBuffer.check_lower_TypeCellInfo(v)
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def self.alloc_from_OptionalTypeCellInfo(v)
|
|
313
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
314
|
+
builder.write_OptionalTypeCellInfo(v)
|
|
315
|
+
return builder.finalize()
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
def consumeIntoOptionalTypeCellInfo
|
|
320
|
+
consumeWithStream do |stream|
|
|
321
|
+
return stream.readOptionalTypeCellInfo
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
# The Optional<T> type for TypeDeviceData.
|
|
326
|
+
|
|
327
|
+
def self.check_lower_OptionalTypeDeviceData(v)
|
|
328
|
+
if not v.nil?
|
|
329
|
+
RustBuffer.check_lower_TypeDeviceData(v)
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
def self.alloc_from_OptionalTypeDeviceData(v)
|
|
334
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
335
|
+
builder.write_OptionalTypeDeviceData(v)
|
|
336
|
+
return builder.finalize()
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
def consumeIntoOptionalTypeDeviceData
|
|
341
|
+
consumeWithStream do |stream|
|
|
342
|
+
return stream.readOptionalTypeDeviceData
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
# The Optional<T> type for TypeLocationData.
|
|
347
|
+
|
|
348
|
+
def self.check_lower_OptionalTypeLocationData(v)
|
|
349
|
+
if not v.nil?
|
|
350
|
+
RustBuffer.check_lower_TypeLocationData(v)
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def self.alloc_from_OptionalTypeLocationData(v)
|
|
355
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
356
|
+
builder.write_OptionalTypeLocationData(v)
|
|
357
|
+
return builder.finalize()
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
def consumeIntoOptionalTypeLocationData
|
|
362
|
+
consumeWithStream do |stream|
|
|
363
|
+
return stream.readOptionalTypeLocationData
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
# The Optional<T> type for TypeNetworkData.
|
|
368
|
+
|
|
369
|
+
def self.check_lower_OptionalTypeNetworkData(v)
|
|
370
|
+
if not v.nil?
|
|
371
|
+
RustBuffer.check_lower_TypeNetworkData(v)
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
def self.alloc_from_OptionalTypeNetworkData(v)
|
|
376
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
377
|
+
builder.write_OptionalTypeNetworkData(v)
|
|
378
|
+
return builder.finalize()
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
def consumeIntoOptionalTypeNetworkData
|
|
383
|
+
consumeWithStream do |stream|
|
|
384
|
+
return stream.readOptionalTypeNetworkData
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
# The Sequence<T> type for string.
|
|
389
|
+
|
|
390
|
+
def self.check_lower_Sequencestring(v)
|
|
391
|
+
v.each do |item|
|
|
392
|
+
|
|
393
|
+
end
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
def self.alloc_from_Sequencestring(v)
|
|
397
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
398
|
+
builder.write_Sequencestring(v)
|
|
399
|
+
return builder.finalize()
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
def consumeIntoSequencestring
|
|
404
|
+
consumeWithStream do |stream|
|
|
405
|
+
return stream.readSequencestring
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
# The Map<T> type for string.
|
|
410
|
+
|
|
411
|
+
def self.check_lower_MapStringString(v)
|
|
412
|
+
v.each do |k, v|
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
end
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
def self.alloc_from_MapStringString(v)
|
|
419
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
420
|
+
builder.write_MapStringString(v)
|
|
421
|
+
return builder.finalize
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
def consumeIntoMapStringString
|
|
426
|
+
consumeWithStream do |stream|
|
|
427
|
+
return stream.readMapStringString
|
|
428
|
+
end
|
|
429
|
+
end
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
module UniFFILib
|
|
433
|
+
class ForeignBytes < FFI::Struct
|
|
434
|
+
layout :len, :int32,
|
|
435
|
+
:data, :pointer
|
|
436
|
+
|
|
437
|
+
def len
|
|
438
|
+
self[:len]
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def data
|
|
442
|
+
self[:data]
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
def to_s
|
|
446
|
+
"ForeignBytes(len=#{len}, data=#{data.read_bytes(len)})"
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
private_constant :UniFFILib
|
|
452
|
+
|
|
453
|
+
# Helper for structured reading of values from a RustBuffer.
|
|
454
|
+
class RustBufferStream
|
|
455
|
+
|
|
456
|
+
def initialize(rbuf)
|
|
457
|
+
@rbuf = rbuf
|
|
458
|
+
@offset = 0
|
|
459
|
+
end
|
|
460
|
+
|
|
461
|
+
def remaining
|
|
462
|
+
@rbuf.len - @offset
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
def read(size)
|
|
466
|
+
raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
|
|
467
|
+
|
|
468
|
+
data = @rbuf.data.get_bytes @offset, size
|
|
469
|
+
|
|
470
|
+
@offset += size
|
|
471
|
+
|
|
472
|
+
data
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
def readF64
|
|
476
|
+
unpack_from 8, 'G'
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
def readBool
|
|
480
|
+
v = unpack_from 1, 'c'
|
|
481
|
+
|
|
482
|
+
return false if v == 0
|
|
483
|
+
return true if v == 1
|
|
484
|
+
|
|
485
|
+
raise InternalError, 'Unexpected byte for Boolean type'
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
def readString
|
|
489
|
+
size = unpack_from 4, 'l>'
|
|
490
|
+
|
|
491
|
+
raise InternalError, 'Unexpected negative string length' if size.negative?
|
|
492
|
+
|
|
493
|
+
read(size).force_encoding(Encoding::UTF_8)
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
def readBytes
|
|
497
|
+
size = unpack_from 4, 'l>'
|
|
498
|
+
|
|
499
|
+
raise InternalError, 'Unexpected negative byte string length' if size.negative?
|
|
500
|
+
|
|
501
|
+
read(size).force_encoding(Encoding::BINARY)
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
# The Object type ProofModeCallbacks.
|
|
505
|
+
|
|
506
|
+
def readTypeProofModeCallbacks
|
|
507
|
+
handle = unpack_from 8, 'Q>'
|
|
508
|
+
return ProofModeCallbacks.uniffi_allocate(handle)
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
# The Record type CellInfo.
|
|
512
|
+
|
|
513
|
+
def readTypeCellInfo
|
|
514
|
+
CellInfo.new(
|
|
515
|
+
carrier: readString,
|
|
516
|
+
cell_id: readOptionalstring,
|
|
517
|
+
lac: readOptionalstring
|
|
518
|
+
)
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
# The Record type DeviceData.
|
|
522
|
+
|
|
523
|
+
def readTypeDeviceData
|
|
524
|
+
DeviceData.new(
|
|
525
|
+
manufacturer: readString,
|
|
526
|
+
model: readString,
|
|
527
|
+
os_version: readString,
|
|
528
|
+
device_id: readOptionalstring
|
|
529
|
+
)
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
# The Record type LocationData.
|
|
533
|
+
|
|
534
|
+
def readTypeLocationData
|
|
535
|
+
LocationData.new(
|
|
536
|
+
latitude: readF64,
|
|
537
|
+
longitude: readF64,
|
|
538
|
+
altitude: readOptionalf64,
|
|
539
|
+
accuracy: readOptionalf64,
|
|
540
|
+
provider: readOptionalstring
|
|
541
|
+
)
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
# The Record type NetworkData.
|
|
545
|
+
|
|
546
|
+
def readTypeNetworkData
|
|
547
|
+
NetworkData.new(
|
|
548
|
+
network_type: readString,
|
|
549
|
+
wifi_ssid: readOptionalstring,
|
|
550
|
+
cell_info: readOptionalTypeCellInfo
|
|
551
|
+
)
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
# The Record type ProofModeConfig.
|
|
555
|
+
|
|
556
|
+
def readTypeProofModeConfig
|
|
557
|
+
ProofModeConfig.new(
|
|
558
|
+
auto_notarize: readBool,
|
|
559
|
+
track_location: readBool,
|
|
560
|
+
track_device_id: readBool,
|
|
561
|
+
track_network: readBool,
|
|
562
|
+
add_credentials: readBool
|
|
563
|
+
)
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
# The Error type ProofModeError
|
|
571
|
+
|
|
572
|
+
def readTypeProofModeError
|
|
573
|
+
variant = unpack_from 4, 'l>'
|
|
574
|
+
|
|
575
|
+
if variant == 1
|
|
576
|
+
return ProofModeError::Io.new(
|
|
577
|
+
readString()
|
|
578
|
+
)
|
|
579
|
+
end
|
|
580
|
+
if variant == 2
|
|
581
|
+
return ProofModeError::Generation.new(
|
|
582
|
+
readString()
|
|
583
|
+
)
|
|
584
|
+
end
|
|
585
|
+
if variant == 3
|
|
586
|
+
return ProofModeError::Check.new(
|
|
587
|
+
readString()
|
|
588
|
+
)
|
|
589
|
+
end
|
|
590
|
+
|
|
591
|
+
raise InternalError, 'Unexpected variant tag for TypeProofModeError'
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
# The Optional<T> type for f64.
|
|
596
|
+
|
|
597
|
+
def readOptionalf64
|
|
598
|
+
flag = unpack_from 1, 'c'
|
|
599
|
+
|
|
600
|
+
if flag == 0
|
|
601
|
+
return nil
|
|
602
|
+
elsif flag == 1
|
|
603
|
+
return readF64
|
|
604
|
+
else
|
|
605
|
+
raise InternalError, 'Unexpected flag byte for Optionalf64'
|
|
606
|
+
end
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
# The Optional<T> type for string.
|
|
610
|
+
|
|
611
|
+
def readOptionalstring
|
|
612
|
+
flag = unpack_from 1, 'c'
|
|
613
|
+
|
|
614
|
+
if flag == 0
|
|
615
|
+
return nil
|
|
616
|
+
elsif flag == 1
|
|
617
|
+
return readString
|
|
618
|
+
else
|
|
619
|
+
raise InternalError, 'Unexpected flag byte for Optionalstring'
|
|
620
|
+
end
|
|
621
|
+
end
|
|
622
|
+
|
|
623
|
+
# The Optional<T> type for bytes.
|
|
624
|
+
|
|
625
|
+
def readOptionalbytes
|
|
626
|
+
flag = unpack_from 1, 'c'
|
|
627
|
+
|
|
628
|
+
if flag == 0
|
|
629
|
+
return nil
|
|
630
|
+
elsif flag == 1
|
|
631
|
+
return readBytes
|
|
632
|
+
else
|
|
633
|
+
raise InternalError, 'Unexpected flag byte for Optionalbytes'
|
|
634
|
+
end
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
# The Optional<T> type for TypeCellInfo.
|
|
638
|
+
|
|
639
|
+
def readOptionalTypeCellInfo
|
|
640
|
+
flag = unpack_from 1, 'c'
|
|
641
|
+
|
|
642
|
+
if flag == 0
|
|
643
|
+
return nil
|
|
644
|
+
elsif flag == 1
|
|
645
|
+
return readTypeCellInfo
|
|
646
|
+
else
|
|
647
|
+
raise InternalError, 'Unexpected flag byte for OptionalTypeCellInfo'
|
|
648
|
+
end
|
|
649
|
+
end
|
|
650
|
+
|
|
651
|
+
# The Optional<T> type for TypeDeviceData.
|
|
652
|
+
|
|
653
|
+
def readOptionalTypeDeviceData
|
|
654
|
+
flag = unpack_from 1, 'c'
|
|
655
|
+
|
|
656
|
+
if flag == 0
|
|
657
|
+
return nil
|
|
658
|
+
elsif flag == 1
|
|
659
|
+
return readTypeDeviceData
|
|
660
|
+
else
|
|
661
|
+
raise InternalError, 'Unexpected flag byte for OptionalTypeDeviceData'
|
|
662
|
+
end
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
# The Optional<T> type for TypeLocationData.
|
|
666
|
+
|
|
667
|
+
def readOptionalTypeLocationData
|
|
668
|
+
flag = unpack_from 1, 'c'
|
|
669
|
+
|
|
670
|
+
if flag == 0
|
|
671
|
+
return nil
|
|
672
|
+
elsif flag == 1
|
|
673
|
+
return readTypeLocationData
|
|
674
|
+
else
|
|
675
|
+
raise InternalError, 'Unexpected flag byte for OptionalTypeLocationData'
|
|
676
|
+
end
|
|
677
|
+
end
|
|
678
|
+
|
|
679
|
+
# The Optional<T> type for TypeNetworkData.
|
|
680
|
+
|
|
681
|
+
def readOptionalTypeNetworkData
|
|
682
|
+
flag = unpack_from 1, 'c'
|
|
683
|
+
|
|
684
|
+
if flag == 0
|
|
685
|
+
return nil
|
|
686
|
+
elsif flag == 1
|
|
687
|
+
return readTypeNetworkData
|
|
688
|
+
else
|
|
689
|
+
raise InternalError, 'Unexpected flag byte for OptionalTypeNetworkData'
|
|
690
|
+
end
|
|
691
|
+
end
|
|
692
|
+
|
|
693
|
+
# The Sequence<T> type for string.
|
|
694
|
+
|
|
695
|
+
def readSequencestring
|
|
696
|
+
count = unpack_from 4, 'l>'
|
|
697
|
+
|
|
698
|
+
raise InternalError, 'Unexpected negative sequence length' if count.negative?
|
|
699
|
+
|
|
700
|
+
items = []
|
|
701
|
+
|
|
702
|
+
count.times do
|
|
703
|
+
items.append readString
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
items
|
|
707
|
+
end
|
|
708
|
+
|
|
709
|
+
# The Map<T> type for string.
|
|
710
|
+
|
|
711
|
+
def readMapStringString
|
|
712
|
+
count = unpack_from 4, 'l>'
|
|
713
|
+
raise InternalError, 'Unexpected negative map size' if count.negative?
|
|
714
|
+
|
|
715
|
+
items = {}
|
|
716
|
+
count.times do
|
|
717
|
+
key = readString
|
|
718
|
+
items[key] = readString
|
|
719
|
+
end
|
|
720
|
+
|
|
721
|
+
items
|
|
722
|
+
end
|
|
723
|
+
|
|
724
|
+
def unpack_from(size, format)
|
|
725
|
+
raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
|
|
726
|
+
|
|
727
|
+
value = @rbuf.data.get_bytes(@offset, size).unpack format
|
|
728
|
+
|
|
729
|
+
@offset += size
|
|
730
|
+
|
|
731
|
+
# TODO: verify this
|
|
732
|
+
raise 'more than one element!!!' if value.size > 1
|
|
733
|
+
|
|
734
|
+
value[0]
|
|
735
|
+
end
|
|
736
|
+
end
|
|
737
|
+
|
|
738
|
+
private_constant :RustBufferStream
|
|
739
|
+
|
|
740
|
+
# Helper for structured writing of values into a RustBuffer.
|
|
741
|
+
class RustBufferBuilder
|
|
742
|
+
def initialize
|
|
743
|
+
@rust_buf = RustBuffer.alloc 16
|
|
744
|
+
@rust_buf.len = 0
|
|
745
|
+
end
|
|
746
|
+
|
|
747
|
+
def finalize
|
|
748
|
+
rbuf = @rust_buf
|
|
749
|
+
|
|
750
|
+
@rust_buf = nil
|
|
751
|
+
|
|
752
|
+
rbuf
|
|
753
|
+
end
|
|
754
|
+
|
|
755
|
+
def discard
|
|
756
|
+
return if @rust_buf.nil?
|
|
757
|
+
|
|
758
|
+
rbuf = finalize
|
|
759
|
+
rbuf.free
|
|
760
|
+
end
|
|
761
|
+
|
|
762
|
+
def write(value)
|
|
763
|
+
reserve(value.bytes.size) do
|
|
764
|
+
@rust_buf.data.put_array_of_char @rust_buf.len, value.bytes
|
|
765
|
+
end
|
|
766
|
+
end
|
|
767
|
+
|
|
768
|
+
def write_F64(v)
|
|
769
|
+
pack_into(8, 'G', v)
|
|
770
|
+
end
|
|
771
|
+
|
|
772
|
+
def write_Bool(v)
|
|
773
|
+
pack_into(1, 'c', v ? 1 : 0)
|
|
774
|
+
end
|
|
775
|
+
|
|
776
|
+
def write_String(v)
|
|
777
|
+
v = Proofmode::uniffi_utf8(v)
|
|
778
|
+
pack_into 4, 'l>', v.bytes.size
|
|
779
|
+
write v
|
|
780
|
+
end
|
|
781
|
+
|
|
782
|
+
def write_Bytes(v)
|
|
783
|
+
v = Proofmode::uniffi_bytes(v)
|
|
784
|
+
pack_into 4, 'l>', v.bytes.size
|
|
785
|
+
write v
|
|
786
|
+
end
|
|
787
|
+
|
|
788
|
+
# The Object type ProofModeCallbacks.
|
|
789
|
+
|
|
790
|
+
def write_TypeProofModeCallbacks(obj)
|
|
791
|
+
handle = ProofModeCallbacks.uniffi_lower obj
|
|
792
|
+
pack_into(8, 'Q>', handle)
|
|
793
|
+
end
|
|
794
|
+
|
|
795
|
+
# The Record type CellInfo.
|
|
796
|
+
|
|
797
|
+
def write_TypeCellInfo(v)
|
|
798
|
+
self.write_String(v.carrier)
|
|
799
|
+
self.write_Optionalstring(v.cell_id)
|
|
800
|
+
self.write_Optionalstring(v.lac)
|
|
801
|
+
end
|
|
802
|
+
|
|
803
|
+
# The Record type DeviceData.
|
|
804
|
+
|
|
805
|
+
def write_TypeDeviceData(v)
|
|
806
|
+
self.write_String(v.manufacturer)
|
|
807
|
+
self.write_String(v.model)
|
|
808
|
+
self.write_String(v.os_version)
|
|
809
|
+
self.write_Optionalstring(v.device_id)
|
|
810
|
+
end
|
|
811
|
+
|
|
812
|
+
# The Record type LocationData.
|
|
813
|
+
|
|
814
|
+
def write_TypeLocationData(v)
|
|
815
|
+
self.write_F64(v.latitude)
|
|
816
|
+
self.write_F64(v.longitude)
|
|
817
|
+
self.write_Optionalf64(v.altitude)
|
|
818
|
+
self.write_Optionalf64(v.accuracy)
|
|
819
|
+
self.write_Optionalstring(v.provider)
|
|
820
|
+
end
|
|
821
|
+
|
|
822
|
+
# The Record type NetworkData.
|
|
823
|
+
|
|
824
|
+
def write_TypeNetworkData(v)
|
|
825
|
+
self.write_String(v.network_type)
|
|
826
|
+
self.write_Optionalstring(v.wifi_ssid)
|
|
827
|
+
self.write_OptionalTypeCellInfo(v.cell_info)
|
|
828
|
+
end
|
|
829
|
+
|
|
830
|
+
# The Record type ProofModeConfig.
|
|
831
|
+
|
|
832
|
+
def write_TypeProofModeConfig(v)
|
|
833
|
+
self.write_Bool(v.auto_notarize)
|
|
834
|
+
self.write_Bool(v.track_location)
|
|
835
|
+
self.write_Bool(v.track_device_id)
|
|
836
|
+
self.write_Bool(v.track_network)
|
|
837
|
+
self.write_Bool(v.add_credentials)
|
|
838
|
+
end
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
# The Optional<T> type for f64.
|
|
843
|
+
|
|
844
|
+
def write_Optionalf64(v)
|
|
845
|
+
if v.nil?
|
|
846
|
+
pack_into(1, 'c', 0)
|
|
847
|
+
else
|
|
848
|
+
pack_into(1, 'c', 1)
|
|
849
|
+
self.write_F64(v)
|
|
850
|
+
end
|
|
851
|
+
end
|
|
852
|
+
|
|
853
|
+
# The Optional<T> type for string.
|
|
854
|
+
|
|
855
|
+
def write_Optionalstring(v)
|
|
856
|
+
if v.nil?
|
|
857
|
+
pack_into(1, 'c', 0)
|
|
858
|
+
else
|
|
859
|
+
pack_into(1, 'c', 1)
|
|
860
|
+
self.write_String(v)
|
|
861
|
+
end
|
|
862
|
+
end
|
|
863
|
+
|
|
864
|
+
# The Optional<T> type for bytes.
|
|
865
|
+
|
|
866
|
+
def write_Optionalbytes(v)
|
|
867
|
+
if v.nil?
|
|
868
|
+
pack_into(1, 'c', 0)
|
|
869
|
+
else
|
|
870
|
+
pack_into(1, 'c', 1)
|
|
871
|
+
self.write_Bytes(v)
|
|
872
|
+
end
|
|
873
|
+
end
|
|
874
|
+
|
|
875
|
+
# The Optional<T> type for TypeCellInfo.
|
|
876
|
+
|
|
877
|
+
def write_OptionalTypeCellInfo(v)
|
|
878
|
+
if v.nil?
|
|
879
|
+
pack_into(1, 'c', 0)
|
|
880
|
+
else
|
|
881
|
+
pack_into(1, 'c', 1)
|
|
882
|
+
self.write_TypeCellInfo(v)
|
|
883
|
+
end
|
|
884
|
+
end
|
|
885
|
+
|
|
886
|
+
# The Optional<T> type for TypeDeviceData.
|
|
887
|
+
|
|
888
|
+
def write_OptionalTypeDeviceData(v)
|
|
889
|
+
if v.nil?
|
|
890
|
+
pack_into(1, 'c', 0)
|
|
891
|
+
else
|
|
892
|
+
pack_into(1, 'c', 1)
|
|
893
|
+
self.write_TypeDeviceData(v)
|
|
894
|
+
end
|
|
895
|
+
end
|
|
896
|
+
|
|
897
|
+
# The Optional<T> type for TypeLocationData.
|
|
898
|
+
|
|
899
|
+
def write_OptionalTypeLocationData(v)
|
|
900
|
+
if v.nil?
|
|
901
|
+
pack_into(1, 'c', 0)
|
|
902
|
+
else
|
|
903
|
+
pack_into(1, 'c', 1)
|
|
904
|
+
self.write_TypeLocationData(v)
|
|
905
|
+
end
|
|
906
|
+
end
|
|
907
|
+
|
|
908
|
+
# The Optional<T> type for TypeNetworkData.
|
|
909
|
+
|
|
910
|
+
def write_OptionalTypeNetworkData(v)
|
|
911
|
+
if v.nil?
|
|
912
|
+
pack_into(1, 'c', 0)
|
|
913
|
+
else
|
|
914
|
+
pack_into(1, 'c', 1)
|
|
915
|
+
self.write_TypeNetworkData(v)
|
|
916
|
+
end
|
|
917
|
+
end
|
|
918
|
+
|
|
919
|
+
# The Sequence<T> type for string.
|
|
920
|
+
|
|
921
|
+
def write_Sequencestring(items)
|
|
922
|
+
pack_into(4, 'l>', items.size)
|
|
923
|
+
|
|
924
|
+
items.each do |item|
|
|
925
|
+
self.write_String(item)
|
|
926
|
+
end
|
|
927
|
+
end
|
|
928
|
+
|
|
929
|
+
# The Map<T> type for string.
|
|
930
|
+
|
|
931
|
+
def write_MapStringString(items)
|
|
932
|
+
pack_into(4, 'l>', items.size)
|
|
933
|
+
|
|
934
|
+
items.each do |k, v|
|
|
935
|
+
write_String(k)
|
|
936
|
+
self.write_String(v)
|
|
937
|
+
end
|
|
938
|
+
end
|
|
939
|
+
|
|
940
|
+
private
|
|
941
|
+
|
|
942
|
+
def reserve(num_bytes)
|
|
943
|
+
if @rust_buf.len + num_bytes > @rust_buf.capacity
|
|
944
|
+
@rust_buf = RustBuffer.reserve(@rust_buf, num_bytes)
|
|
945
|
+
end
|
|
946
|
+
|
|
947
|
+
yield
|
|
948
|
+
|
|
949
|
+
@rust_buf.len += num_bytes
|
|
950
|
+
end
|
|
951
|
+
|
|
952
|
+
def pack_into(size, format, value)
|
|
953
|
+
reserve(size) do
|
|
954
|
+
@rust_buf.data.put_array_of_char @rust_buf.len, [value].pack(format).bytes
|
|
955
|
+
end
|
|
956
|
+
end
|
|
957
|
+
end
|
|
958
|
+
|
|
959
|
+
private_constant :RustBufferBuilder
|
|
960
|
+
|
|
961
|
+
# Error definitions
|
|
962
|
+
class RustCallStatus < FFI::Struct
|
|
963
|
+
layout :code, :int8,
|
|
964
|
+
:error_buf, RustBuffer
|
|
965
|
+
|
|
966
|
+
def code
|
|
967
|
+
self[:code]
|
|
968
|
+
end
|
|
969
|
+
|
|
970
|
+
def error_buf
|
|
971
|
+
self[:error_buf]
|
|
972
|
+
end
|
|
973
|
+
|
|
974
|
+
def to_s
|
|
975
|
+
"RustCallStatus(code=#{self[:code]})"
|
|
976
|
+
end
|
|
977
|
+
end
|
|
978
|
+
|
|
979
|
+
# These match the values from the uniffi::rustcalls module
|
|
980
|
+
CALL_SUCCESS = 0
|
|
981
|
+
CALL_ERROR = 1
|
|
982
|
+
CALL_PANIC = 2
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
module ProofModeError
|
|
986
|
+
class Io < StandardError
|
|
987
|
+
def initialize(message)
|
|
988
|
+
@message = message
|
|
989
|
+
super()
|
|
990
|
+
end
|
|
991
|
+
|
|
992
|
+
attr_reader :message
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
def to_s
|
|
996
|
+
"#{self.class.name}(message=#{@message.inspect})"
|
|
997
|
+
end
|
|
998
|
+
end
|
|
999
|
+
class Generation < StandardError
|
|
1000
|
+
def initialize(message)
|
|
1001
|
+
@message = message
|
|
1002
|
+
super()
|
|
1003
|
+
end
|
|
1004
|
+
|
|
1005
|
+
attr_reader :message
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
def to_s
|
|
1009
|
+
"#{self.class.name}(message=#{@message.inspect})"
|
|
1010
|
+
end
|
|
1011
|
+
end
|
|
1012
|
+
class Check < StandardError
|
|
1013
|
+
def initialize(message)
|
|
1014
|
+
@message = message
|
|
1015
|
+
super()
|
|
1016
|
+
end
|
|
1017
|
+
|
|
1018
|
+
attr_reader :message
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
def to_s
|
|
1022
|
+
"#{self.class.name}(message=#{@message.inspect})"
|
|
1023
|
+
end
|
|
1024
|
+
end
|
|
1025
|
+
|
|
1026
|
+
end
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
# Map error modules to the RustBuffer method name that reads them
|
|
1030
|
+
ERROR_MODULE_TO_READER_METHOD = {
|
|
1031
|
+
|
|
1032
|
+
ProofModeError => :readTypeProofModeError,
|
|
1033
|
+
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
private_constant :ERROR_MODULE_TO_READER_METHOD, :CALL_SUCCESS, :CALL_ERROR, :CALL_PANIC,
|
|
1037
|
+
:RustCallStatus
|
|
1038
|
+
|
|
1039
|
+
def self.consume_buffer_into_error(error_module, rust_buffer)
|
|
1040
|
+
rust_buffer.consumeWithStream do |stream|
|
|
1041
|
+
reader_method = ERROR_MODULE_TO_READER_METHOD[error_module]
|
|
1042
|
+
return stream.send(reader_method)
|
|
1043
|
+
end
|
|
1044
|
+
end
|
|
1045
|
+
|
|
1046
|
+
class InternalError < StandardError
|
|
1047
|
+
end
|
|
1048
|
+
|
|
1049
|
+
def self.rust_call(fn_name, *args)
|
|
1050
|
+
# Call a rust function
|
|
1051
|
+
rust_call_with_error(nil, fn_name, *args)
|
|
1052
|
+
end
|
|
1053
|
+
|
|
1054
|
+
def self.rust_call_with_error(error_module, fn_name, *args)
|
|
1055
|
+
# Call a rust function and handle errors
|
|
1056
|
+
#
|
|
1057
|
+
# Use this when the rust function returns a Result<>. error_module must be the error_module that corresponds to that Result.
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
# Note: RustCallStatus.new zeroes out the struct, which is exactly what we
|
|
1061
|
+
# want to pass to Rust (code=0, error_buf=RustBuffer(len=0, capacity=0,
|
|
1062
|
+
# data=NULL))
|
|
1063
|
+
status = RustCallStatus.new
|
|
1064
|
+
args << status
|
|
1065
|
+
|
|
1066
|
+
result = UniFFILib.public_send(fn_name, *args)
|
|
1067
|
+
|
|
1068
|
+
case status.code
|
|
1069
|
+
when CALL_SUCCESS
|
|
1070
|
+
result
|
|
1071
|
+
when CALL_ERROR
|
|
1072
|
+
if error_module.nil?
|
|
1073
|
+
status.error_buf.free
|
|
1074
|
+
raise InternalError, "CALL_ERROR with no error_module set"
|
|
1075
|
+
else
|
|
1076
|
+
raise consume_buffer_into_error(error_module, status.error_buf)
|
|
1077
|
+
end
|
|
1078
|
+
when CALL_PANIC
|
|
1079
|
+
# When the rust code sees a panic, it tries to construct a RustBuffer
|
|
1080
|
+
# with the message. But if that code panics, then it just sends back
|
|
1081
|
+
# an empty buffer.
|
|
1082
|
+
if status.error_buf.len > 0
|
|
1083
|
+
raise InternalError, status.error_buf.consumeIntoString()
|
|
1084
|
+
else
|
|
1085
|
+
raise InternalError, "Rust panic"
|
|
1086
|
+
end
|
|
1087
|
+
else
|
|
1088
|
+
raise InternalError, "Unknown call status: #{status.code}"
|
|
1089
|
+
end
|
|
1090
|
+
end
|
|
1091
|
+
|
|
1092
|
+
private_class_method :consume_buffer_into_error
|
|
1093
|
+
|
|
1094
|
+
# This is how we find and load the dynamic library provided by the component.
|
|
1095
|
+
# For now we just look it up by name.
|
|
1096
|
+
module UniFFILib
|
|
1097
|
+
extend FFI::Library
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
ffi_lib 'proofmode'
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
attach_function :uniffi_proofmode_fn_clone_proofmodecallbacks,
|
|
1104
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1105
|
+
:uint64
|
|
1106
|
+
attach_function :uniffi_proofmode_fn_free_proofmodecallbacks,
|
|
1107
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1108
|
+
:void
|
|
1109
|
+
attach_function :uniffi_proofmode_fn_init_callback_vtable_proofmodecallbacks,
|
|
1110
|
+
[:pointer, RustCallStatus.by_ref],
|
|
1111
|
+
:void
|
|
1112
|
+
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_get_location,
|
|
1113
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1114
|
+
RustBuffer.by_value
|
|
1115
|
+
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_get_device_info,
|
|
1116
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1117
|
+
RustBuffer.by_value
|
|
1118
|
+
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_get_network_info,
|
|
1119
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1120
|
+
RustBuffer.by_value
|
|
1121
|
+
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_save_data,
|
|
1122
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1123
|
+
:int8
|
|
1124
|
+
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_save_text,
|
|
1125
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1126
|
+
:int8
|
|
1127
|
+
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_sign_data,
|
|
1128
|
+
[:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1129
|
+
RustBuffer.by_value
|
|
1130
|
+
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_report_progress,
|
|
1131
|
+
[:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1132
|
+
:void
|
|
1133
|
+
attach_function :uniffi_proofmode_fn_func_check_files,
|
|
1134
|
+
[RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
|
|
1135
|
+
RustBuffer.by_value
|
|
1136
|
+
attach_function :uniffi_proofmode_fn_func_generate_proof,
|
|
1137
|
+
[RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
|
|
1138
|
+
RustBuffer.by_value
|
|
1139
|
+
attach_function :uniffi_proofmode_fn_func_get_file_hash,
|
|
1140
|
+
[RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1141
|
+
RustBuffer.by_value
|
|
1142
|
+
attach_function :uniffi_proofmode_fn_func_get_version,
|
|
1143
|
+
[RustCallStatus.by_ref],
|
|
1144
|
+
RustBuffer.by_value
|
|
1145
|
+
attach_function :ffi_proofmode_rustbuffer_alloc,
|
|
1146
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1147
|
+
RustBuffer.by_value
|
|
1148
|
+
attach_function :ffi_proofmode_rustbuffer_from_bytes,
|
|
1149
|
+
[ForeignBytes, RustCallStatus.by_ref],
|
|
1150
|
+
RustBuffer.by_value
|
|
1151
|
+
attach_function :ffi_proofmode_rustbuffer_free,
|
|
1152
|
+
[RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1153
|
+
:void
|
|
1154
|
+
attach_function :ffi_proofmode_rustbuffer_reserve,
|
|
1155
|
+
[RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
|
|
1156
|
+
RustBuffer.by_value
|
|
1157
|
+
attach_function :uniffi_proofmode_checksum_func_check_files,
|
|
1158
|
+
[RustCallStatus.by_ref],
|
|
1159
|
+
:uint16
|
|
1160
|
+
attach_function :uniffi_proofmode_checksum_func_generate_proof,
|
|
1161
|
+
[RustCallStatus.by_ref],
|
|
1162
|
+
:uint16
|
|
1163
|
+
attach_function :uniffi_proofmode_checksum_func_get_file_hash,
|
|
1164
|
+
[RustCallStatus.by_ref],
|
|
1165
|
+
:uint16
|
|
1166
|
+
attach_function :uniffi_proofmode_checksum_func_get_version,
|
|
1167
|
+
[RustCallStatus.by_ref],
|
|
1168
|
+
:uint16
|
|
1169
|
+
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_get_location,
|
|
1170
|
+
[RustCallStatus.by_ref],
|
|
1171
|
+
:uint16
|
|
1172
|
+
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_get_device_info,
|
|
1173
|
+
[RustCallStatus.by_ref],
|
|
1174
|
+
:uint16
|
|
1175
|
+
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_get_network_info,
|
|
1176
|
+
[RustCallStatus.by_ref],
|
|
1177
|
+
:uint16
|
|
1178
|
+
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_save_data,
|
|
1179
|
+
[RustCallStatus.by_ref],
|
|
1180
|
+
:uint16
|
|
1181
|
+
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_save_text,
|
|
1182
|
+
[RustCallStatus.by_ref],
|
|
1183
|
+
:uint16
|
|
1184
|
+
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_sign_data,
|
|
1185
|
+
[RustCallStatus.by_ref],
|
|
1186
|
+
:uint16
|
|
1187
|
+
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_report_progress,
|
|
1188
|
+
[RustCallStatus.by_ref],
|
|
1189
|
+
:uint16
|
|
1190
|
+
attach_function :ffi_proofmode_uniffi_contract_version,
|
|
1191
|
+
[RustCallStatus.by_ref],
|
|
1192
|
+
:uint32
|
|
1193
|
+
|
|
1194
|
+
end
|
|
1195
|
+
|
|
1196
|
+
# Public interface members begin here.
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
# Record type CellInfo
|
|
1201
|
+
class CellInfo
|
|
1202
|
+
attr_reader :carrier, :cell_id, :lac
|
|
1203
|
+
|
|
1204
|
+
def initialize(carrier:, cell_id:, lac:)
|
|
1205
|
+
@carrier = carrier
|
|
1206
|
+
@cell_id = cell_id
|
|
1207
|
+
@lac = lac
|
|
1208
|
+
end
|
|
1209
|
+
|
|
1210
|
+
def ==(other)
|
|
1211
|
+
if @carrier != other.carrier
|
|
1212
|
+
return false
|
|
1213
|
+
end
|
|
1214
|
+
if @cell_id != other.cell_id
|
|
1215
|
+
return false
|
|
1216
|
+
end
|
|
1217
|
+
if @lac != other.lac
|
|
1218
|
+
return false
|
|
1219
|
+
end
|
|
1220
|
+
|
|
1221
|
+
true
|
|
1222
|
+
end
|
|
1223
|
+
end
|
|
1224
|
+
|
|
1225
|
+
# Record type DeviceData
|
|
1226
|
+
class DeviceData
|
|
1227
|
+
attr_reader :manufacturer, :model, :os_version, :device_id
|
|
1228
|
+
|
|
1229
|
+
def initialize(manufacturer:, model:, os_version:, device_id:)
|
|
1230
|
+
@manufacturer = manufacturer
|
|
1231
|
+
@model = model
|
|
1232
|
+
@os_version = os_version
|
|
1233
|
+
@device_id = device_id
|
|
1234
|
+
end
|
|
1235
|
+
|
|
1236
|
+
def ==(other)
|
|
1237
|
+
if @manufacturer != other.manufacturer
|
|
1238
|
+
return false
|
|
1239
|
+
end
|
|
1240
|
+
if @model != other.model
|
|
1241
|
+
return false
|
|
1242
|
+
end
|
|
1243
|
+
if @os_version != other.os_version
|
|
1244
|
+
return false
|
|
1245
|
+
end
|
|
1246
|
+
if @device_id != other.device_id
|
|
1247
|
+
return false
|
|
1248
|
+
end
|
|
1249
|
+
|
|
1250
|
+
true
|
|
1251
|
+
end
|
|
1252
|
+
end
|
|
1253
|
+
|
|
1254
|
+
# Record type LocationData
|
|
1255
|
+
class LocationData
|
|
1256
|
+
attr_reader :latitude, :longitude, :altitude, :accuracy, :provider
|
|
1257
|
+
|
|
1258
|
+
def initialize(latitude:, longitude:, altitude:, accuracy:, provider:)
|
|
1259
|
+
@latitude = latitude
|
|
1260
|
+
@longitude = longitude
|
|
1261
|
+
@altitude = altitude
|
|
1262
|
+
@accuracy = accuracy
|
|
1263
|
+
@provider = provider
|
|
1264
|
+
end
|
|
1265
|
+
|
|
1266
|
+
def ==(other)
|
|
1267
|
+
if @latitude != other.latitude
|
|
1268
|
+
return false
|
|
1269
|
+
end
|
|
1270
|
+
if @longitude != other.longitude
|
|
1271
|
+
return false
|
|
1272
|
+
end
|
|
1273
|
+
if @altitude != other.altitude
|
|
1274
|
+
return false
|
|
1275
|
+
end
|
|
1276
|
+
if @accuracy != other.accuracy
|
|
1277
|
+
return false
|
|
1278
|
+
end
|
|
1279
|
+
if @provider != other.provider
|
|
1280
|
+
return false
|
|
1281
|
+
end
|
|
1282
|
+
|
|
1283
|
+
true
|
|
1284
|
+
end
|
|
1285
|
+
end
|
|
1286
|
+
|
|
1287
|
+
# Record type NetworkData
|
|
1288
|
+
class NetworkData
|
|
1289
|
+
attr_reader :network_type, :wifi_ssid, :cell_info
|
|
1290
|
+
|
|
1291
|
+
def initialize(network_type:, wifi_ssid:, cell_info:)
|
|
1292
|
+
@network_type = network_type
|
|
1293
|
+
@wifi_ssid = wifi_ssid
|
|
1294
|
+
@cell_info = cell_info
|
|
1295
|
+
end
|
|
1296
|
+
|
|
1297
|
+
def ==(other)
|
|
1298
|
+
if @network_type != other.network_type
|
|
1299
|
+
return false
|
|
1300
|
+
end
|
|
1301
|
+
if @wifi_ssid != other.wifi_ssid
|
|
1302
|
+
return false
|
|
1303
|
+
end
|
|
1304
|
+
if @cell_info != other.cell_info
|
|
1305
|
+
return false
|
|
1306
|
+
end
|
|
1307
|
+
|
|
1308
|
+
true
|
|
1309
|
+
end
|
|
1310
|
+
end
|
|
1311
|
+
|
|
1312
|
+
# Record type ProofModeConfig
|
|
1313
|
+
class ProofModeConfig
|
|
1314
|
+
attr_reader :auto_notarize, :track_location, :track_device_id, :track_network, :add_credentials
|
|
1315
|
+
|
|
1316
|
+
def initialize(auto_notarize:, track_location:, track_device_id:, track_network:, add_credentials:)
|
|
1317
|
+
@auto_notarize = auto_notarize
|
|
1318
|
+
@track_location = track_location
|
|
1319
|
+
@track_device_id = track_device_id
|
|
1320
|
+
@track_network = track_network
|
|
1321
|
+
@add_credentials = add_credentials
|
|
1322
|
+
end
|
|
1323
|
+
|
|
1324
|
+
def ==(other)
|
|
1325
|
+
if @auto_notarize != other.auto_notarize
|
|
1326
|
+
return false
|
|
1327
|
+
end
|
|
1328
|
+
if @track_location != other.track_location
|
|
1329
|
+
return false
|
|
1330
|
+
end
|
|
1331
|
+
if @track_device_id != other.track_device_id
|
|
1332
|
+
return false
|
|
1333
|
+
end
|
|
1334
|
+
if @track_network != other.track_network
|
|
1335
|
+
return false
|
|
1336
|
+
end
|
|
1337
|
+
if @add_credentials != other.add_credentials
|
|
1338
|
+
return false
|
|
1339
|
+
end
|
|
1340
|
+
|
|
1341
|
+
true
|
|
1342
|
+
end
|
|
1343
|
+
end
|
|
1344
|
+
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
def self.check_files(file_paths, callbacks)
|
|
1350
|
+
file_paths = file_paths.map { |v| Proofmode::uniffi_utf8(v) }
|
|
1351
|
+
RustBuffer.check_lower_Sequencestring(file_paths)
|
|
1352
|
+
|
|
1353
|
+
callbacks = callbacks
|
|
1354
|
+
(ProofModeCallbacks.uniffi_check_lower callbacks)
|
|
1355
|
+
|
|
1356
|
+
result = Proofmode.rust_call_with_error(ProofModeError,:uniffi_proofmode_fn_func_check_files,RustBuffer.alloc_from_Sequencestring(file_paths),(ProofModeCallbacks.uniffi_lower callbacks))
|
|
1357
|
+
return result.consumeIntoString
|
|
1358
|
+
end
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
def self.generate_proof(media_data, metadata, config, callbacks)
|
|
1365
|
+
media_data = Proofmode::uniffi_bytes(media_data)
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
metadata = metadata.each.with_object({}) { |(k, v), res| res[Proofmode::uniffi_utf8(k)] = Proofmode::uniffi_utf8(v) }
|
|
1369
|
+
RustBuffer.check_lower_MapStringString(metadata)
|
|
1370
|
+
|
|
1371
|
+
config = config
|
|
1372
|
+
RustBuffer.check_lower_TypeProofModeConfig(config)
|
|
1373
|
+
|
|
1374
|
+
callbacks = callbacks
|
|
1375
|
+
(ProofModeCallbacks.uniffi_check_lower callbacks)
|
|
1376
|
+
|
|
1377
|
+
result = Proofmode.rust_call_with_error(ProofModeError,:uniffi_proofmode_fn_func_generate_proof,RustBuffer.allocFromBytes(media_data),RustBuffer.alloc_from_MapStringString(metadata),RustBuffer.alloc_from_TypeProofModeConfig(config),(ProofModeCallbacks.uniffi_lower callbacks))
|
|
1378
|
+
return result.consumeIntoString
|
|
1379
|
+
end
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
def self.get_file_hash(media_data)
|
|
1386
|
+
media_data = Proofmode::uniffi_bytes(media_data)
|
|
1387
|
+
|
|
1388
|
+
|
|
1389
|
+
result = Proofmode.rust_call(:uniffi_proofmode_fn_func_get_file_hash,RustBuffer.allocFromBytes(media_data))
|
|
1390
|
+
return result.consumeIntoString
|
|
1391
|
+
end
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
|
|
1396
|
+
|
|
1397
|
+
def self.get_version()
|
|
1398
|
+
result = Proofmode.rust_call(:uniffi_proofmode_fn_func_get_version,)
|
|
1399
|
+
return result.consumeIntoString
|
|
1400
|
+
end
|
|
1401
|
+
|
|
1402
|
+
|
|
1403
|
+
|
|
1404
|
+
|
|
1405
|
+
|
|
1406
|
+
class ProofModeCallbacks
|
|
1407
|
+
|
|
1408
|
+
# A private helper for initializing instances of the class from a raw handle,
|
|
1409
|
+
# bypassing any initialization logic and ensuring they are GC'd properly.
|
|
1410
|
+
def self.uniffi_allocate(handle)
|
|
1411
|
+
inst = allocate
|
|
1412
|
+
inst.instance_variable_set :@handle, handle
|
|
1413
|
+
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
|
|
1414
|
+
return inst
|
|
1415
|
+
end
|
|
1416
|
+
|
|
1417
|
+
# A private helper for registering an object finalizer.
|
|
1418
|
+
# N.B. it's important that this does not capture a reference
|
|
1419
|
+
# to the actual instance, only its underlying handle.
|
|
1420
|
+
def self.uniffi_define_finalizer_by_handle(handle, object_id)
|
|
1421
|
+
Proc.new do |_id|
|
|
1422
|
+
Proofmode.rust_call(
|
|
1423
|
+
:uniffi_proofmode_fn_free_proofmodecallbacks,
|
|
1424
|
+
handle
|
|
1425
|
+
)
|
|
1426
|
+
end
|
|
1427
|
+
end
|
|
1428
|
+
|
|
1429
|
+
# A private helper for lowering instances into a raw handle.
|
|
1430
|
+
# This does an explicit typecheck, because accidentally lowering a different type of
|
|
1431
|
+
# object in a place where this type is expected, could lead to memory unsafety.
|
|
1432
|
+
def self.uniffi_check_lower(inst)
|
|
1433
|
+
if not inst.is_a? self
|
|
1434
|
+
raise TypeError.new "Expected a ProofModeCallbacks instance, got #{inst}"
|
|
1435
|
+
end
|
|
1436
|
+
end
|
|
1437
|
+
|
|
1438
|
+
def uniffi_clone_handle()
|
|
1439
|
+
return Proofmode.rust_call(
|
|
1440
|
+
:uniffi_proofmode_fn_clone_proofmodecallbacks,
|
|
1441
|
+
@handle
|
|
1442
|
+
)
|
|
1443
|
+
end
|
|
1444
|
+
|
|
1445
|
+
def self.uniffi_lower(inst)
|
|
1446
|
+
return inst.uniffi_clone_handle()
|
|
1447
|
+
end
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
def get_location()
|
|
1452
|
+
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_get_location,uniffi_clone_handle(),)
|
|
1453
|
+
return result.consumeIntoOptionalTypeLocationData
|
|
1454
|
+
end
|
|
1455
|
+
def get_device_info()
|
|
1456
|
+
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_get_device_info,uniffi_clone_handle(),)
|
|
1457
|
+
return result.consumeIntoOptionalTypeDeviceData
|
|
1458
|
+
end
|
|
1459
|
+
def get_network_info()
|
|
1460
|
+
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_get_network_info,uniffi_clone_handle(),)
|
|
1461
|
+
return result.consumeIntoOptionalTypeNetworkData
|
|
1462
|
+
end
|
|
1463
|
+
def save_data(hash, filename, data)
|
|
1464
|
+
hash = Proofmode::uniffi_utf8(hash)
|
|
1465
|
+
|
|
1466
|
+
filename = Proofmode::uniffi_utf8(filename)
|
|
1467
|
+
|
|
1468
|
+
data = Proofmode::uniffi_bytes(data)
|
|
1469
|
+
|
|
1470
|
+
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_save_data,uniffi_clone_handle(),RustBuffer.allocFromString(hash),RustBuffer.allocFromString(filename),RustBuffer.allocFromBytes(data))
|
|
1471
|
+
return 1 == result
|
|
1472
|
+
end
|
|
1473
|
+
def save_text(hash, filename, text)
|
|
1474
|
+
hash = Proofmode::uniffi_utf8(hash)
|
|
1475
|
+
|
|
1476
|
+
filename = Proofmode::uniffi_utf8(filename)
|
|
1477
|
+
|
|
1478
|
+
text = Proofmode::uniffi_utf8(text)
|
|
1479
|
+
|
|
1480
|
+
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_save_text,uniffi_clone_handle(),RustBuffer.allocFromString(hash),RustBuffer.allocFromString(filename),RustBuffer.allocFromString(text))
|
|
1481
|
+
return 1 == result
|
|
1482
|
+
end
|
|
1483
|
+
def sign_data(data)
|
|
1484
|
+
data = Proofmode::uniffi_bytes(data)
|
|
1485
|
+
|
|
1486
|
+
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_sign_data,uniffi_clone_handle(),RustBuffer.allocFromBytes(data))
|
|
1487
|
+
return result.consumeIntoOptionalbytes
|
|
1488
|
+
end
|
|
1489
|
+
def report_progress(message)
|
|
1490
|
+
message = Proofmode::uniffi_utf8(message)
|
|
1491
|
+
|
|
1492
|
+
Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_report_progress,uniffi_clone_handle(),RustBuffer.allocFromString(message))
|
|
1493
|
+
end
|
|
1494
|
+
|
|
1495
|
+
|
|
1496
|
+
end
|
|
1497
|
+
|
|
1498
|
+
end
|
|
1499
|
+
|