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.check_lower_TypeCellInfo(v)
RustBuffer.check_lower_Optionalstring(v.cell_id)
RustBuffer.check_lower_Optionalstring(v.lac)
end
def self.alloc_from_TypeCellInfo(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypeCellInfo(v)
return builder.finalize
end
end
def consumeIntoTypeCellInfo
consumeWithStream do |stream|
return stream.readTypeCellInfo
end
end
def self.check_lower_TypeDeviceData(v)
RustBuffer.check_lower_Optionalstring(v.device_id)
end
def self.alloc_from_TypeDeviceData(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypeDeviceData(v)
return builder.finalize
end
end
def consumeIntoTypeDeviceData
consumeWithStream do |stream|
return stream.readTypeDeviceData
end
end
def self.check_lower_TypeLocationData(v)
RustBuffer.check_lower_Optionalf64(v.altitude)
RustBuffer.check_lower_Optionalf64(v.accuracy)
RustBuffer.check_lower_Optionalstring(v.provider)
end
def self.alloc_from_TypeLocationData(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypeLocationData(v)
return builder.finalize
end
end
def consumeIntoTypeLocationData
consumeWithStream do |stream|
return stream.readTypeLocationData
end
end
def self.check_lower_TypeNetworkData(v)
RustBuffer.check_lower_Optionalstring(v.wifi_ssid)
RustBuffer.check_lower_OptionalTypeCellInfo(v.cell_info)
end
def self.alloc_from_TypeNetworkData(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypeNetworkData(v)
return builder.finalize
end
end
def consumeIntoTypeNetworkData
consumeWithStream do |stream|
return stream.readTypeNetworkData
end
end
def self.check_lower_TypeProofModeConfig(v)
end
def self.alloc_from_TypeProofModeConfig(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_TypeProofModeConfig(v)
return builder.finalize
end
end
def consumeIntoTypeProofModeConfig
consumeWithStream do |stream|
return stream.readTypeProofModeConfig
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_OptionalTypeCellInfo(v)
if not v.nil?
RustBuffer.check_lower_TypeCellInfo(v)
end
end
def self.alloc_from_OptionalTypeCellInfo(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_OptionalTypeCellInfo(v)
return builder.finalize()
end
end
def consumeIntoOptionalTypeCellInfo
consumeWithStream do |stream|
return stream.readOptionalTypeCellInfo
end
end
def self.check_lower_OptionalTypeDeviceData(v)
if not v.nil?
RustBuffer.check_lower_TypeDeviceData(v)
end
end
def self.alloc_from_OptionalTypeDeviceData(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_OptionalTypeDeviceData(v)
return builder.finalize()
end
end
def consumeIntoOptionalTypeDeviceData
consumeWithStream do |stream|
return stream.readOptionalTypeDeviceData
end
end
def self.check_lower_OptionalTypeLocationData(v)
if not v.nil?
RustBuffer.check_lower_TypeLocationData(v)
end
end
def self.alloc_from_OptionalTypeLocationData(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_OptionalTypeLocationData(v)
return builder.finalize()
end
end
def consumeIntoOptionalTypeLocationData
consumeWithStream do |stream|
return stream.readOptionalTypeLocationData
end
end
def self.check_lower_OptionalTypeNetworkData(v)
if not v.nil?
RustBuffer.check_lower_TypeNetworkData(v)
end
end
def self.alloc_from_OptionalTypeNetworkData(v)
RustBuffer.allocWithBuilder do |builder|
builder.write_OptionalTypeNetworkData(v)
return builder.finalize()
end
end
def consumeIntoOptionalTypeNetworkData
consumeWithStream do |stream|
return stream.readOptionalTypeNetworkData
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
def readTypeProofModeCallbacks
handle = unpack_from 8, 'Q>'
return ProofModeCallbacks.uniffi_allocate(handle)
end
def readTypeCellInfo
CellInfo.new(
carrier: readString,
cell_id: readOptionalstring,
lac: readOptionalstring
)
end
def readTypeDeviceData
DeviceData.new(
manufacturer: readString,
model: readString,
os_version: readString,
device_id: readOptionalstring
)
end
def readTypeLocationData
LocationData.new(
latitude: readF64,
longitude: readF64,
altitude: readOptionalf64,
accuracy: readOptionalf64,
provider: readOptionalstring
)
end
def readTypeNetworkData
NetworkData.new(
network_type: readString,
wifi_ssid: readOptionalstring,
cell_info: readOptionalTypeCellInfo
)
end
def readTypeProofModeConfig
ProofModeConfig.new(
auto_notarize: readBool,
track_location: readBool,
track_device_id: readBool,
track_network: readBool,
add_credentials: readBool
)
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 readOptionalTypeCellInfo
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readTypeCellInfo
else
raise InternalError, 'Unexpected flag byte for OptionalTypeCellInfo'
end
end
def readOptionalTypeDeviceData
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readTypeDeviceData
else
raise InternalError, 'Unexpected flag byte for OptionalTypeDeviceData'
end
end
def readOptionalTypeLocationData
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readTypeLocationData
else
raise InternalError, 'Unexpected flag byte for OptionalTypeLocationData'
end
end
def readOptionalTypeNetworkData
flag = unpack_from 1, 'c'
if flag == 0
return nil
elsif flag == 1
return readTypeNetworkData
else
raise InternalError, 'Unexpected flag byte for OptionalTypeNetworkData'
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
def write_TypeProofModeCallbacks(obj)
handle = ProofModeCallbacks.uniffi_lower obj
pack_into(8, 'Q>', handle)
end
def write_TypeCellInfo(v)
self.write_String(v.carrier)
self.write_Optionalstring(v.cell_id)
self.write_Optionalstring(v.lac)
end
def write_TypeDeviceData(v)
self.write_String(v.manufacturer)
self.write_String(v.model)
self.write_String(v.os_version)
self.write_Optionalstring(v.device_id)
end
def write_TypeLocationData(v)
self.write_F64(v.latitude)
self.write_F64(v.longitude)
self.write_Optionalf64(v.altitude)
self.write_Optionalf64(v.accuracy)
self.write_Optionalstring(v.provider)
end
def write_TypeNetworkData(v)
self.write_String(v.network_type)
self.write_Optionalstring(v.wifi_ssid)
self.write_OptionalTypeCellInfo(v.cell_info)
end
def write_TypeProofModeConfig(v)
self.write_Bool(v.auto_notarize)
self.write_Bool(v.track_location)
self.write_Bool(v.track_device_id)
self.write_Bool(v.track_network)
self.write_Bool(v.add_credentials)
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_OptionalTypeCellInfo(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_TypeCellInfo(v)
end
end
def write_OptionalTypeDeviceData(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_TypeDeviceData(v)
end
end
def write_OptionalTypeLocationData(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_TypeLocationData(v)
end
end
def write_OptionalTypeNetworkData(v)
if v.nil?
pack_into(1, 'c', 0)
else
pack_into(1, 'c', 1)
self.write_TypeNetworkData(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_proofmodecallbacks,
[:uint64, RustCallStatus.by_ref],
:uint64
attach_function :uniffi_proofmode_fn_free_proofmodecallbacks,
[:uint64, RustCallStatus.by_ref],
:void
attach_function :uniffi_proofmode_fn_init_callback_vtable_proofmodecallbacks,
[:pointer, RustCallStatus.by_ref],
:void
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_get_location,
[:uint64, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_get_device_info,
[:uint64, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_get_network_info,
[:uint64, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_save_data,
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
:int8
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_save_text,
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
:int8
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_sign_data,
[:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_method_proofmodecallbacks_report_progress,
[:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
:void
attach_function :uniffi_proofmode_fn_func_check_files,
[RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
RustBuffer.by_value
attach_function :uniffi_proofmode_fn_func_generate_proof,
[RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
RustBuffer.by_value
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,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_func_generate_proof,
[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_proofmodecallbacks_get_location,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_get_device_info,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_get_network_info,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_save_data,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_save_text,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_sign_data,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_proofmode_checksum_method_proofmodecallbacks_report_progress,
[RustCallStatus.by_ref],
:uint16
attach_function :ffi_proofmode_uniffi_contract_version,
[RustCallStatus.by_ref],
:uint32
end
class CellInfo
attr_reader :carrier, :cell_id, :lac
def initialize(carrier:, cell_id:, lac:)
@carrier = carrier
@cell_id = cell_id
@lac = lac
end
def ==(other)
if @carrier != other.carrier
return false
end
if @cell_id != other.cell_id
return false
end
if @lac != other.lac
return false
end
true
end
end
class DeviceData
attr_reader :manufacturer, :model, :os_version, :device_id
def initialize(manufacturer:, model:, os_version:, device_id:)
@manufacturer = manufacturer
@model = model
@os_version = os_version
@device_id = device_id
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
true
end
end
class LocationData
attr_reader :latitude, :longitude, :altitude, :accuracy, :provider
def initialize(latitude:, longitude:, altitude:, accuracy:, provider:)
@latitude = latitude
@longitude = longitude
@altitude = altitude
@accuracy = accuracy
@provider = provider
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 @provider != other.provider
return false
end
true
end
end
class NetworkData
attr_reader :network_type, :wifi_ssid, :cell_info
def initialize(network_type:, wifi_ssid:, cell_info:)
@network_type = network_type
@wifi_ssid = wifi_ssid
@cell_info = cell_info
end
def ==(other)
if @network_type != other.network_type
return false
end
if @wifi_ssid != other.wifi_ssid
return false
end
if @cell_info != other.cell_info
return false
end
true
end
end
class ProofModeConfig
attr_reader :auto_notarize, :track_location, :track_device_id, :track_network, :add_credentials
def initialize(auto_notarize:, track_location:, track_device_id:, track_network:, add_credentials:)
@auto_notarize = auto_notarize
@track_location = track_location
@track_device_id = track_device_id
@track_network = track_network
@add_credentials = add_credentials
end
def ==(other)
if @auto_notarize != other.auto_notarize
return false
end
if @track_location != other.track_location
return false
end
if @track_device_id != other.track_device_id
return false
end
if @track_network != other.track_network
return false
end
if @add_credentials != other.add_credentials
return false
end
true
end
end
def self.check_files(file_paths, callbacks)
file_paths = file_paths.map { |v| Proofmode::uniffi_utf8(v) }
RustBuffer.check_lower_Sequencestring(file_paths)
callbacks = callbacks
(ProofModeCallbacks.uniffi_check_lower callbacks)
result = Proofmode.rust_call_with_error(ProofModeError,:uniffi_proofmode_fn_func_check_files,RustBuffer.alloc_from_Sequencestring(file_paths),(ProofModeCallbacks.uniffi_lower callbacks))
return result.consumeIntoString
end
def self.generate_proof(media_data, metadata, config, 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)
config = config
RustBuffer.check_lower_TypeProofModeConfig(config)
callbacks = callbacks
(ProofModeCallbacks.uniffi_check_lower callbacks)
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))
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 ProofModeCallbacks
def self.uniffi_allocate(handle)
inst = allocate
inst.instance_variable_set :@handle, handle
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
return inst
end
def self.uniffi_define_finalizer_by_handle(handle, object_id)
Proc.new do |_id|
Proofmode.rust_call(
:uniffi_proofmode_fn_free_proofmodecallbacks,
handle
)
end
end
def self.uniffi_check_lower(inst)
if not inst.is_a? self
raise TypeError.new "Expected a ProofModeCallbacks instance, got #{inst}"
end
end
def uniffi_clone_handle()
return Proofmode.rust_call(
:uniffi_proofmode_fn_clone_proofmodecallbacks,
@handle
)
end
def self.uniffi_lower(inst)
return inst.uniffi_clone_handle()
end
def get_location()
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_get_location,uniffi_clone_handle(),)
return result.consumeIntoOptionalTypeLocationData
end
def get_device_info()
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_get_device_info,uniffi_clone_handle(),)
return result.consumeIntoOptionalTypeDeviceData
end
def get_network_info()
result = Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_get_network_info,uniffi_clone_handle(),)
return result.consumeIntoOptionalTypeNetworkData
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_proofmodecallbacks_save_data,uniffi_clone_handle(),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_proofmodecallbacks_save_text,uniffi_clone_handle(),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_proofmodecallbacks_sign_data,uniffi_clone_handle(),RustBuffer.allocFromBytes(data))
return result.consumeIntoOptionalbytes
end
def report_progress(message)
message = Proofmode::uniffi_utf8(message)
Proofmode.rust_call(:uniffi_proofmode_fn_method_proofmodecallbacks_report_progress,uniffi_clone_handle(),RustBuffer.allocFromString(message))
end
end
end
require_relative 'proofmode_callbacks'