require 'ffi'
module Proofmode
def self.uniffi_in_range(i, type_name, min, max)
raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
i = i.to_int
raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
i
end
def self.uniffi_utf8(v)
raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
v = v.to_str.encode(Encoding::UTF_8)
raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
v
end
def self.uniffi_bytes(v)
raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
v.to_str
end
class RustBuffer < FFI::Struct
layout :capacity, :uint64,
:len, :uint64,
:data, :pointer
def self.alloc(size)
return Proofmode.rust_call(:ffi_proofmode_rustbuffer_alloc, size)
end
def self.reserve(rbuf, additional)
return Proofmode.rust_call(:ffi_proofmode_rustbuffer_reserve, rbuf, additional)
end
def free
Proofmode.rust_call(:ffi_proofmode_rustbuffer_free, self)
end
def capacity
self[:capacity]
end
def len
self[:len]
end
def len=(value)
self[:len] = value
end
def data
self[:data]
end
def to_s
"RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})"
end
def self.allocWithBuilder
builder = RustBufferBuilder.new
begin
yield builder
rescue => e
builder.discard
raise e
end
end
def consumeWithStream
stream = RustBufferStream.new self
yield stream
raise RuntimeError, 'junk data left in buffer after consuming' if stream.remaining != 0
ensure
free
end
def self.allocFromString(value)
RustBuffer.allocWithBuilder do |builder|
builder.write value.encode('utf-8')
return builder.finalize
end
end
def consumeIntoString
consumeWithStream do |stream|
return stream.read(stream.remaining).force_encoding(Encoding::UTF_8)
end
end
def self.allocFromBytes(value)
RustBuffer.allocWithBuilder do |builder|
builder.write_Bytes(value)
return builder.finalize
end
end
def consumeIntoBytes
consumeWithStream do |stream|
return stream.readBytes
end
end
def self.alloc_from_Timestamp(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_Timestamp(v)
return builder.finalize
end
end
def consumeIntoTimestamp
consumeWithStream do |stream|
return stream.readTimestamp
end
end
def self.check_lower_TypeDeviceInfo(v)
RustBuffer.check_lower_Optionalstring(v.imei)
end
def self.alloc_from_TypeDeviceInfo(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypeDeviceInfo(v)
return builder.finalize
end
end
def consumeIntoTypeDeviceInfo
consumeWithStream do |stream|
return stream.readTypeDeviceInfo
end
end
def self.check_lower_TypeLocationInfo(v)
RustBuffer.check_lower_Optionalf64(v.altitude)
RustBuffer.check_lower_Optionalf64(v.accuracy)
end
def self.alloc_from_TypeLocationInfo(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypeLocationInfo(v)
return builder.finalize
end
end
def consumeIntoTypeLocationInfo
consumeWithStream do |stream|
return stream.readTypeLocationInfo
end
end
def self.check_lower_TypeNetworkInfo(v)
RustBuffer.check_lower_Optionalstring(v.carrier)
RustBuffer.check_lower_Optionalstring(v.cell_tower_id)
RustBuffer.check_lower_Optionalstring(v.wifi_ssid)
end
def self.alloc_from_TypeNetworkInfo(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypeNetworkInfo(v)
return builder.finalize
end
end
def consumeIntoTypeNetworkInfo
consumeWithStream do |stream|
return stream.readTypeNetworkInfo
end
end
def self.check_lower_Optionalf64(v)
if not v.nil?
end
end
def self.alloc_from_Optionalf64(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_Optionalf64(v)
return builder.finalize()
end
end
def consumeIntoOptionalf64
consumeWithStream do |stream|
return stream.readOptionalf64
end
end
def self.check_lower_Optionalstring(v)
if not v.nil?
end
end
def self.alloc_from_Optionalstring(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_Optionalstring(v)
return builder.finalize()
end
end
def consumeIntoOptionalstring
consumeWithStream do |stream|
return stream.readOptionalstring
end
end
def self.check_lower_Optionalbytes(v)
if not v.nil?
end
end
def self.alloc_from_Optionalbytes(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_Optionalbytes(v)
return builder.finalize()
end
end
def consumeIntoOptionalbytes
consumeWithStream do |stream|
return stream.readOptionalbytes
end
end
def self.check_lower_OptionalTypeDeviceInfo(v)
if not v.nil?
RustBuffer.check_lower_TypeDeviceInfo(v)
end
end
def self.alloc_from_OptionalTypeDeviceInfo(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_OptionalTypeDeviceInfo(v)
return builder.finalize()
end
end
def consumeIntoOptionalTypeDeviceInfo
consumeWithStream do |stream|
return stream.readOptionalTypeDeviceInfo
end
end
def self.check_lower_OptionalTypeLocationInfo(v)
if not v.nil?
RustBuffer.check_lower_TypeLocationInfo(v)
end
end
def self.alloc_from_OptionalTypeLocationInfo(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_OptionalTypeLocationInfo(v)
return builder.finalize()
end
end
def consumeIntoOptionalTypeLocationInfo
consumeWithStream do |stream|
return stream.readOptionalTypeLocationInfo
end
end
def self.check_lower_OptionalTypeNetworkInfo(v)
if not v.nil?
RustBuffer.check_lower_TypeNetworkInfo(v)
end
end
def self.alloc_from_OptionalTypeNetworkInfo(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_OptionalTypeNetworkInfo(v)
return builder.finalize()
end
end
def consumeIntoOptionalTypeNetworkInfo
consumeWithStream do |stream|
return stream.readOptionalTypeNetworkInfo
end
end
def self.check_lower_Sequencestring(v)
v.each do |item|
end
end
def self.alloc_from_Sequencestring(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_Sequencestring(v)
return builder.finalize()
end
end
def consumeIntoSequencestring
consumeWithStream do |stream|
return stream.readSequencestring
end
end
def self.check_lower_MapStringString(v)
v.each do |k, v|
end
end
def self.alloc_from_MapStringString(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_MapStringString(v)
return builder.finalize
end
end
def consumeIntoMapStringString
consumeWithStream do |stream|
return stream.readMapStringString
end
end
end
module UniFFILib
class ForeignBytes < FFI::Struct
layout :len, :int32,
:data, :pointer
def len
self[:len]
end
def data
self[:data]
end
def to_s
"ForeignBytes(len=#{len}, data=#{data.read_bytes(len)})"
end
end
end
private_constant :UniFFILib
class RustBufferStream
def initialize(rbuf)
@rbuf = rbuf
@offset = 0
end
def remaining
@rbuf.len - @offset
end
def read(size)
raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
data = @rbuf.data.get_bytes @offset, size
@offset += size
data
end
def readF64
unpack_from 8, 'G'
end
def readBool
v = unpack_from 1, 'c'
return false if v == 0
return true if v == 1
raise InternalError, 'Unexpected byte for Boolean type'
end
def readString
size = unpack_from 4, 'l>'
raise InternalError, 'Unexpected negative string length' if size.negative?
read(size).force_encoding(Encoding::UTF_8)
end
def readBytes
size = unpack_from 4, 'l>'
raise InternalError, 'Unexpected negative byte string length' if size.negative?
read(size).force_encoding(Encoding::BINARY)
end
ONE_SECOND_IN_NANOSECONDS = 10**9
def readTimestamp
seconds = unpack_from 8, 'q>'
nanoseconds = unpack_from 4, 'L>'
if seconds < 0 && nanoseconds != 0
nanoseconds = ONE_SECOND_IN_NANOSECONDS - nanoseconds
seconds -= 1
end
Time.at(seconds, nanoseconds, :nanosecond, in: '+00:00').utc
end
def readTypeMobileCallbacks
pointer = FFI::Pointer.new unpack_from 8, 'Q>'
return MobileCallbacks.uniffi_allocate(pointer)
end
def readTypeDeviceInfo
DeviceInfo.new(
manufacturer: readString,
model: readString,
os_version: readString,
device_id: readString,
imei: readOptionalstring
)
end
def readTypeLocationInfo
LocationInfo.new(
latitude: readF64,
longitude: readF64,
altitude: readOptionalf64,
accuracy: readOptionalf64,
timestamp: readTimestamp
)
end
def readTypeNetworkInfo
NetworkInfo.new(
network_type: readString,
carrier: readOptionalstring,
cell_tower_id: readOptionalstring,
wifi_ssid: readOptionalstring
)
end
def readTypeProofModeError
variant = unpack_from 4, 'l>'
if variant == 1
return ProofModeError::Io.new(
readString()
)
end
if variant == 2
return ProofModeError::Generation.new(
readString()
)
end
if variant == 3
return ProofModeError::Check.new(
readString()
)
end
raise InternalError, 'Unexpected variant tag for TypeProofModeError'
end
def readOptionalf64
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readF64
else
raise InternalError, 'Unexpected flag byte for Optionalf64'
end
end
def readOptionalstring
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readString
else
raise InternalError, 'Unexpected flag byte for Optionalstring'
end
end
def readOptionalbytes
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readBytes
else
raise InternalError, 'Unexpected flag byte for Optionalbytes'
end
end
def readOptionalTypeDeviceInfo
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readTypeDeviceInfo
else
raise InternalError, 'Unexpected flag byte for OptionalTypeDeviceInfo'
end
end
def readOptionalTypeLocationInfo
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readTypeLocationInfo
else
raise InternalError, 'Unexpected flag byte for OptionalTypeLocationInfo'
end
end
def readOptionalTypeNetworkInfo
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readTypeNetworkInfo
else
raise InternalError, 'Unexpected flag byte for OptionalTypeNetworkInfo'
end
end
def readSequencestring
count = unpack_from 4, 'l>'
raise InternalError, 'Unexpected negative sequence length' if count.negative?
items = []
count.times do
items.append readString
end
items
end
def readMapStringString
count = unpack_from 4, 'l>'
raise InternalError, 'Unexpected negative map size' if count.negative?
items = {}
count.times do
key = readString
items[key] = readString
end
items
end
def unpack_from(size, format)
raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
value = @rbuf.data.get_bytes(@offset, size).unpack format
@offset += size
raise 'more than one element!!!' if value.size > 1
value[0]
end
end
private_constant :RustBufferStream
class RustBufferBuilder
def initialize
@rust_buf = RustBuffer.alloc 16
@rust_buf.len = 0
end
def finalize
rbuf = @rust_buf
@rust_buf = nil
rbuf
end
def discard
return if @rust_buf.nil?
rbuf = finalize
rbuf.free
end
def write(value)
reserve(value.bytes.size) do
@rust_buf.data.put_array_of_char @rust_buf.len, value.bytes
end
end
def write_F64(v)
pack_into(8, 'G', v)
end
def write_Bool(v)
pack_into(1, 'c', v ? 1 : 0)
end
def write_String(v)
v = Proofmode::uniffi_utf8(v)
pack_into 4, 'l>', v.bytes.size
write v
end
def write_Bytes(v)
v = Proofmode::uniffi_bytes(v)
pack_into 4, 'l>', v.bytes.size
write v
end
ONE_SECOND_IN_NANOSECONDS = 10**9
def write_Timestamp(v)
seconds = v.tv_sec
nanoseconds = v.tv_nsec
if seconds < 0 && nanoseconds != 0
nanoseconds = ONE_SECOND_IN_NANOSECONDS - nanoseconds
seconds += 1
end
pack_into 8, 'q>', seconds
pack_into 4, 'L>', nanoseconds
end
def write_TypeMobileCallbacks(obj)
pointer = MobileCallbacks.uniffi_lower obj
pack_into(8, 'Q>', pointer.address)
end
def write_TypeDeviceInfo(v)
self.write_String(v.manufacturer)
self.write_String(v.model)
self.write_String(v.os_version)
self.write_String(v.device_id)
self.write_Optionalstring(v.imei)
end
def write_TypeLocationInfo(v)
self.write_F64(v.latitude)
self.write_F64(v.longitude)
self.write_Optionalf64(v.altitude)
self.write_Optionalf64(v.accuracy)
self.write_Timestamp(v.timestamp)
end
def write_TypeNetworkInfo(v)
self.write_String(v.network_type)
self.write_Optionalstring(v.carrier)
self.write_Optionalstring(v.cell_tower_id)
self.write_Optionalstring(v.wifi_ssid)
end
def write_Optionalf64(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_F64(v)
end
end
def write_Optionalstring(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_String(v)
end
end
def write_Optionalbytes(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_Bytes(v)
end
end
def write_OptionalTypeDeviceInfo(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_TypeDeviceInfo(v)
end
end
def write_OptionalTypeLocationInfo(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_TypeLocationInfo(v)
end
end
def write_OptionalTypeNetworkInfo(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_TypeNetworkInfo(v)
end
end
def write_Sequencestring(items)
pack_into(4, 'l>', items.size)
items.each do |item|
self.write_String(item)
end
end
def write_MapStringString(items)
pack_into(4, 'l>', items.size)
items.each do |k, v|
write_String(k)
self.write_String(v)
end
end
private
def reserve(num_bytes)
if @rust_buf.len + num_bytes > @rust_buf.capacity
@rust_buf = RustBuffer.reserve(@rust_buf, num_bytes)
end
yield
@rust_buf.len += num_bytes
end
def pack_into(size, format, value)
reserve(size) do
@rust_buf.data.put_array_of_char @rust_buf.len, [value].pack(format).bytes
end
end
end
private_constant :RustBufferBuilder
class RustCallStatus < FFI::Struct
layout :code, :int8,
:error_buf, RustBuffer
def code
self[:code]
end
def error_buf
self[:error_buf]
end
def to_s
"RustCallStatus(code=#{self[:code]})"
end
end
CALL_SUCCESS = 0
CALL_ERROR = 1
CALL_PANIC = 2
module ProofModeError
class Io < StandardError
def initialize(message)
@message = message
super()
end
attr_reader :message
def to_s
"#{self.class.name}(message=#{@message.inspect})"
end
end
class Generation < StandardError
def initialize(message)
@message = message
super()
end
attr_reader :message
def to_s
"#{self.class.name}(message=#{@message.inspect})"
end
end
class Check < StandardError
def initialize(message)
@message = message
super()
end
attr_reader :message
def to_s
"#{self.class.name}(message=#{@message.inspect})"
end
end
end
ERROR_MODULE_TO_READER_METHOD = {
ProofModeError => :readTypeProofModeError,
}
private_constant :ERROR_MODULE_TO_READER_METHOD, :CALL_SUCCESS, :CALL_ERROR, :CALL_PANIC,
:RustCallStatus
def self.consume_buffer_into_error(error_module, rust_buffer)
rust_buffer.consumeWithStream do |stream|
reader_method = ERROR_MODULE_TO_READER_METHOD[error_module]
return stream.send(reader_method)
end
end
class InternalError < StandardError
end
def self.rust_call(fn_name, *args)
rust_call_with_error(nil, fn_name, *args)
end
def self.rust_call_with_error(error_module, fn_name, *args)
status = RustCallStatus.new
args << status
result = UniFFILib.public_send(fn_name, *args)
case status.code
when CALL_SUCCESS
result
when CALL_ERROR
if error_module.nil?
status.error_buf.free
raise InternalError, "CALL_ERROR with no error_module set"
else
raise consume_buffer_into_error(error_module, status.error_buf)
end
when CALL_PANIC
if status.error_buf.len > 0
raise InternalError, status.error_buf.consumeIntoString()
else
raise InternalError, "Rust panic"
end
else
raise InternalError, "Unknown call status: #{status.code}"
end
end
private_class_method :consume_buffer_into_error
module UniFFILib
extend FFI::Library
ffi_lib 'proofmode'
attach_function :uniffi_proofmode_fn_clone_mobilecallbacks,
[:pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_proofmode_fn_free_mobilecallbacks,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_proofmode_fn_init_callback_vtable_mobilecallbacks,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_proofmode_fn_method_mobilecallbacks_get_location,
[:pointer, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_method_mobilecallbacks_get_device_info,
[:pointer, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_method_mobilecallbacks_get_network_info,
[:pointer, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_method_mobilecallbacks_save_data,
[:pointer, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
:int8
attach_function :uniffi_proofmode_fn_method_mobilecallbacks_save_text,
[:pointer, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
:int8
attach_function :uniffi_proofmode_fn_method_mobilecallbacks_sign_data,
[:pointer, RustBuffer.by_value, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_method_mobilecallbacks_report_progress,
[:pointer, RustBuffer.by_value, RustCallStatus.by_ref],
:void
attach_function :uniffi_proofmode_fn_func_check_files_mobile,
[RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
:uint64
attach_function :uniffi_proofmode_fn_func_generate_proof_mobile,
[RustBuffer.by_value, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
:uint64
attach_function :uniffi_proofmode_fn_func_get_file_hash,
[RustBuffer.by_value, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_func_get_version,
[RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :ffi_proofmode_rustbuffer_alloc,
[:uint64, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :ffi_proofmode_rustbuffer_from_bytes,
[ForeignBytes, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :ffi_proofmode_rustbuffer_free,
[RustBuffer.by_value, RustCallStatus.by_ref],
:void
attach_function :ffi_proofmode_rustbuffer_reserve,
[RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_checksum_func_check_files_mobile,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_func_generate_proof_mobile,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_func_get_file_hash,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_func_get_version,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_mobilecallbacks_get_location,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_mobilecallbacks_get_device_info,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_mobilecallbacks_get_network_info,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_mobilecallbacks_save_data,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_mobilecallbacks_save_text,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_mobilecallbacks_sign_data,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_mobilecallbacks_report_progress,
[RustCallStatus.by_ref],
:uint16
attach_function :ffi_proofmode_uniffi_contract_version,
[RustCallStatus.by_ref],
:uint32
end
class DeviceInfo
attr_reader :manufacturer, :model, :os_version, :device_id, :imei
def initialize(manufacturer:, model:, os_version:, device_id:, imei:)
@manufacturer = manufacturer
@model = model
@os_version = os_version
@device_id = device_id
@imei = imei
end
def ==(other)
if @manufacturer != other.manufacturer
return false
end
if @model != other.model
return false
end
if @os_version != other.os_version
return false
end
if @device_id != other.device_id
return false
end
if @imei != other.imei
return false
end
true
end
end
class LocationInfo
attr_reader :latitude, :longitude, :altitude, :accuracy, :timestamp
def initialize(latitude:, longitude:, altitude:, accuracy:, timestamp:)
@latitude = latitude
@longitude = longitude
@altitude = altitude
@accuracy = accuracy
@timestamp = timestamp
end
def ==(other)
if @latitude != other.latitude
return false
end
if @longitude != other.longitude
return false
end
if @altitude != other.altitude
return false
end
if @accuracy != other.accuracy
return false
end
if @timestamp != other.timestamp
return false
end
true
end
end
class NetworkInfo
attr_reader :network_type, :carrier, :cell_tower_id, :wifi_ssid
def initialize(network_type:, carrier:, cell_tower_id:, wifi_ssid:)
@network_type = network_type
@carrier = carrier
@cell_tower_id = cell_tower_id
@wifi_ssid = wifi_ssid
end
def ==(other)
if @network_type != other.network_type
return false
end
if @carrier != other.carrier
return false
end
if @cell_tower_id != other.cell_tower_id
return false
end
if @wifi_ssid != other.wifi_ssid
return false
end
true
end
end
def self.check_files_mobile(file_paths, progress_callback)
file_paths = file_paths.map { |v| Proofmode::uniffi_utf8(v) }
RustBuffer.check_lower_Sequencestring(file_paths)
progress_callback = progress_callback
(MobileCallbacks.uniffi_check_lower progress_callback)
result = Proofmode.rust_call_with_error(ProofModeError,:uniffi_proofmode_fn_func_check_files_mobile,RustBuffer.alloc_from_Sequencestring(file_paths),(MobileCallbacks.uniffi_lower progress_callback))
return result.consumeIntoString
end
def self.generate_proof_mobile(media_data, metadata, callbacks)
media_data = Proofmode::uniffi_bytes(media_data)
metadata = metadata.each.with_object({}) { |(k, v), res| res[Proofmode::uniffi_utf8(k)] = Proofmode::uniffi_utf8(v) }
RustBuffer.check_lower_MapStringString(metadata)
callbacks = callbacks
(MobileCallbacks.uniffi_check_lower callbacks)
result = Proofmode.rust_call_with_error(ProofModeError,:uniffi_proofmode_fn_func_generate_proof_mobile,RustBuffer.allocFromBytes(media_data),RustBuffer.alloc_from_MapStringString(metadata),(MobileCallbacks.uniffi_lower callbacks))
return result.consumeIntoString
end
def self.get_file_hash(media_data)
media_data = Proofmode::uniffi_bytes(media_data)
result = Proofmode.rust_call(:uniffi_proofmode_fn_func_get_file_hash,RustBuffer.allocFromBytes(media_data))
return result.consumeIntoString
end
def self.get_version()
result = Proofmode.rust_call(:uniffi_proofmode_fn_func_get_version,)
return result.consumeIntoString
end
class MobileCallbacks
def self.uniffi_allocate(pointer)
pointer.autorelease = false
inst = allocate
inst.instance_variable_set :@pointer, pointer
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_pointer(pointer, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_pointer(pointer, object_id)
Proc.new do |_id|
Proofmode.rust_call(
:uniffi_proofmode_fn_free_mobilecallbacks,
pointer
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a MobileCallbacks instance, got #{inst}"
end
end
def uniffi_clone_pointer()
return Proofmode.rust_call(
:uniffi_proofmode_fn_clone_mobilecallbacks,
@pointer
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_pointer()
end
def get_location()
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_mobilecallbacks_get_location,uniffi_clone_pointer(),)
return result.consumeIntoOptionalTypeLocationInfo
end
def get_device_info()
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_mobilecallbacks_get_device_info,uniffi_clone_pointer(),)
return result.consumeIntoOptionalTypeDeviceInfo
end
def get_network_info()
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_mobilecallbacks_get_network_info,uniffi_clone_pointer(),)
return result.consumeIntoOptionalTypeNetworkInfo
end
def save_data(hash, filename, data)
hash = Proofmode::uniffi_utf8(hash)
filename = Proofmode::uniffi_utf8(filename)
data = Proofmode::uniffi_bytes(data)
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_mobilecallbacks_save_data,uniffi_clone_pointer(),RustBuffer.allocFromString(hash),RustBuffer.allocFromString(filename),RustBuffer.allocFromBytes(data))
return 1 == result
end
def save_text(hash, filename, text)
hash = Proofmode::uniffi_utf8(hash)
filename = Proofmode::uniffi_utf8(filename)
text = Proofmode::uniffi_utf8(text)
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_mobilecallbacks_save_text,uniffi_clone_pointer(),RustBuffer.allocFromString(hash),RustBuffer.allocFromString(filename),RustBuffer.allocFromString(text))
return 1 == result
end
def sign_data(data)
data = Proofmode::uniffi_bytes(data)
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_mobilecallbacks_sign_data,uniffi_clone_pointer(),RustBuffer.allocFromBytes(data))
return result.consumeIntoOptionalbytes
end
def report_progress(message)
message = Proofmode::uniffi_utf8(message)
Proofmode.rust_call(:uniffi_proofmode_fn_method_mobilecallbacks_report_progress,uniffi_clone_pointer(),RustBuffer.allocFromString(message))
end
end
end