@genation/bridge-peer 0.1.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.
Files changed (72) hide show
  1. package/GenationBridgePeer.podspec +17 -0
  2. package/LICENSE +190 -0
  3. package/README.md +66 -0
  4. package/package.json +59 -0
  5. package/react-native/android/build.gradle +24 -0
  6. package/react-native/android/src/main/java/com/genation/bridge/GenationBridgePeerModule.kt +182 -0
  7. package/react-native/android/src/main/java/com/genation/bridge/GenationBridgePeerPackage.kt +15 -0
  8. package/react-native/android/src/main/jniLibs/arm64-v8a/libgenation_bridge_crypto_uniffi.so +0 -0
  9. package/react-native/android/src/main/jniLibs/armeabi-v7a/libgenation_bridge_crypto_uniffi.so +0 -0
  10. package/react-native/android/src/main/jniLibs/x86/libgenation_bridge_crypto_uniffi.so +0 -0
  11. package/react-native/android/src/main/jniLibs/x86_64/libgenation_bridge_crypto_uniffi.so +0 -0
  12. package/react-native/generated/kotlin/uniffi/genation_bridge_crypto_uniffi/genation_bridge_crypto_uniffi.kt +2006 -0
  13. package/react-native/generated/swift/GenationBridgeCryptoMobile.swift +1072 -0
  14. package/react-native/generated/swift/GenationBridgeCryptoMobileFFI.h +703 -0
  15. package/react-native/generated/swift/GenationBridgeCryptoMobileFFI.modulemap +7 -0
  16. package/react-native/ios/GenationBridgePeer.m +14 -0
  17. package/react-native/ios/GenationBridgePeer.swift +234 -0
  18. package/react-native/native/GenationBridgeCryptoMobile.xcframework/Info.plist +48 -0
  19. package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64/Headers/GenationBridgeCryptoMobileFFI.h +703 -0
  20. package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64/Headers/module.modulemap +7 -0
  21. package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64/libgenation_bridge_crypto_uniffi.a +0 -0
  22. package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64_x86_64-simulator/Headers/GenationBridgeCryptoMobileFFI.h +703 -0
  23. package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap +7 -0
  24. package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64_x86_64-simulator/libgenation_bridge_crypto_uniffi.a +0 -0
  25. package/react-native.config.js +8 -0
  26. package/src/core/codec.d.ts +5 -0
  27. package/src/core/codec.js +46 -0
  28. package/src/core/errors.d.ts +11 -0
  29. package/src/core/errors.js +27 -0
  30. package/src/core/identity.d.ts +16 -0
  31. package/src/core/identity.js +1 -0
  32. package/src/core/lifecycle.d.ts +4 -0
  33. package/src/core/lifecycle.js +1 -0
  34. package/src/core/mod.d.ts +6 -0
  35. package/src/core/mod.js +3 -0
  36. package/src/core/peer.d.ts +67 -0
  37. package/src/core/peer.js +373 -0
  38. package/src/core/runtime.d.ts +78 -0
  39. package/src/core/runtime.js +0 -0
  40. package/src/node/crypto-core/javascript/mod.d.ts +8 -0
  41. package/src/node/crypto-core/javascript/mod.js +24 -0
  42. package/src/node/crypto-core/javascript/provider.d.ts +2 -0
  43. package/src/node/crypto-core/javascript/provider.js +43 -0
  44. package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm.d.ts +122 -0
  45. package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm.js +433 -0
  46. package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm_bg.wasm +0 -0
  47. package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm_bg.wasm.d.ts +25 -0
  48. package/src/node/encoding.js +1 -0
  49. package/src/node/file-key-store.d.ts +6 -0
  50. package/src/node/file-key-store.js +111 -0
  51. package/src/node/identity-provider.d.ts +8 -0
  52. package/src/node/identity-provider.js +57 -0
  53. package/src/node/identity.js +45 -0
  54. package/src/node/mod.d.ts +16 -0
  55. package/src/node/mod.js +17 -0
  56. package/src/node/relay-runtime.d.ts +11 -0
  57. package/src/node/relay-runtime.js +11 -0
  58. package/src/react-native/identity-provider.d.ts +4 -0
  59. package/src/react-native/identity-provider.js +125 -0
  60. package/src/react-native/lifecycle.d.ts +8 -0
  61. package/src/react-native/lifecycle.js +9 -0
  62. package/src/react-native/mod.d.ts +20 -0
  63. package/src/react-native/mod.js +36 -0
  64. package/src/react-native/native-module.d.ts +17 -0
  65. package/src/react-native/native-module.js +9 -0
  66. package/src/relay/encoding.js +32 -0
  67. package/src/relay/frame-channel.d.ts +1 -0
  68. package/src/relay/frame-channel.js +110 -0
  69. package/src/relay/identity.d.ts +27 -0
  70. package/src/relay/identity.js +0 -0
  71. package/src/relay/runtime.d.ts +8 -0
  72. package/src/relay/runtime.js +900 -0
@@ -0,0 +1,2006 @@
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
+ @file:Suppress("NAME_SHADOWING")
5
+
6
+ package uniffi.genation_bridge_crypto_uniffi
7
+
8
+ // Common helper code.
9
+ //
10
+ // Ideally this would live in a separate .kt file where it can be unittested etc
11
+ // in isolation, and perhaps even published as a re-useable package.
12
+ //
13
+ // However, it's important that the details of how this helper code works (e.g. the
14
+ // way that different builtin types are passed across the FFI) exactly match what's
15
+ // expected by the Rust code on the other side of the interface. In practice right
16
+ // now that means coming from the exact some version of `uniffi` that was used to
17
+ // compile the Rust component. The easiest way to ensure this is to bundle the Kotlin
18
+ // helpers directly inline like we're doing here.
19
+
20
+ import com.sun.jna.Library
21
+ import com.sun.jna.IntegerType
22
+ import com.sun.jna.Native
23
+ import com.sun.jna.Pointer
24
+ import com.sun.jna.Structure
25
+ import com.sun.jna.Callback
26
+ import com.sun.jna.ptr.*
27
+ import java.nio.ByteBuffer
28
+ import java.nio.ByteOrder
29
+ import java.nio.CharBuffer
30
+ import java.nio.charset.CodingErrorAction
31
+ import java.util.concurrent.atomic.AtomicLong
32
+ import java.util.concurrent.ConcurrentHashMap
33
+ import java.util.concurrent.atomic.AtomicBoolean
34
+
35
+ // This is a helper for safely working with byte buffers returned from the Rust code.
36
+ // A rust-owned buffer is represented by its capacity, its current length, and a
37
+ // pointer to the underlying data.
38
+
39
+ /**
40
+ * @suppress
41
+ */
42
+ @Structure.FieldOrder("capacity", "len", "data")
43
+ open class RustBuffer : Structure() {
44
+ // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
45
+ // When dealing with these fields, make sure to call `toULong()`.
46
+ @JvmField var capacity: Long = 0
47
+ @JvmField var len: Long = 0
48
+ @JvmField var data: Pointer? = null
49
+
50
+ class ByValue: RustBuffer(), Structure.ByValue
51
+ class ByReference: RustBuffer(), Structure.ByReference
52
+
53
+ internal fun setValue(other: RustBuffer) {
54
+ capacity = other.capacity
55
+ len = other.len
56
+ data = other.data
57
+ }
58
+
59
+ companion object {
60
+ internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
61
+ // Note: need to convert the size to a `Long` value to make this work with JVM.
62
+ UniffiLib.INSTANCE.ffi_genation_bridge_crypto_uniffi_rustbuffer_alloc(size.toLong(), status)
63
+ }.also {
64
+ if(it.data == null) {
65
+ throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
66
+ }
67
+ }
68
+
69
+ internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
70
+ var buf = RustBuffer.ByValue()
71
+ buf.capacity = capacity.toLong()
72
+ buf.len = len.toLong()
73
+ buf.data = data
74
+ return buf
75
+ }
76
+
77
+ internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
78
+ UniffiLib.INSTANCE.ffi_genation_bridge_crypto_uniffi_rustbuffer_free(buf, status)
79
+ }
80
+ }
81
+
82
+ @Suppress("TooGenericExceptionThrown")
83
+ fun asByteBuffer() =
84
+ this.data?.getByteBuffer(0, this.len.toLong())?.also {
85
+ it.order(ByteOrder.BIG_ENDIAN)
86
+ }
87
+ }
88
+
89
+ /**
90
+ * The equivalent of the `*mut RustBuffer` type.
91
+ * Required for callbacks taking in an out pointer.
92
+ *
93
+ * Size is the sum of all values in the struct.
94
+ *
95
+ * @suppress
96
+ */
97
+ class RustBufferByReference : ByReference(16) {
98
+ /**
99
+ * Set the pointed-to `RustBuffer` to the given value.
100
+ */
101
+ fun setValue(value: RustBuffer.ByValue) {
102
+ // NOTE: The offsets are as they are in the C-like struct.
103
+ val pointer = getPointer()
104
+ pointer.setLong(0, value.capacity)
105
+ pointer.setLong(8, value.len)
106
+ pointer.setPointer(16, value.data)
107
+ }
108
+
109
+ /**
110
+ * Get a `RustBuffer.ByValue` from this reference.
111
+ */
112
+ fun getValue(): RustBuffer.ByValue {
113
+ val pointer = getPointer()
114
+ val value = RustBuffer.ByValue()
115
+ value.writeField("capacity", pointer.getLong(0))
116
+ value.writeField("len", pointer.getLong(8))
117
+ value.writeField("data", pointer.getLong(16))
118
+
119
+ return value
120
+ }
121
+ }
122
+
123
+ // This is a helper for safely passing byte references into the rust code.
124
+ // It's not actually used at the moment, because there aren't many things that you
125
+ // can take a direct pointer to in the JVM, and if we're going to copy something
126
+ // then we might as well copy it into a `RustBuffer`. But it's here for API
127
+ // completeness.
128
+
129
+ @Structure.FieldOrder("len", "data")
130
+ internal open class ForeignBytes : Structure() {
131
+ @JvmField var len: Int = 0
132
+ @JvmField var data: Pointer? = null
133
+
134
+ class ByValue : ForeignBytes(), Structure.ByValue
135
+ }
136
+ /**
137
+ * The FfiConverter interface handles converter types to and from the FFI
138
+ *
139
+ * All implementing objects should be public to support external types. When a
140
+ * type is external we need to import it's FfiConverter.
141
+ *
142
+ * @suppress
143
+ */
144
+ public interface FfiConverter<KotlinType, FfiType> {
145
+ // Convert an FFI type to a Kotlin type
146
+ fun lift(value: FfiType): KotlinType
147
+
148
+ // Convert an Kotlin type to an FFI type
149
+ fun lower(value: KotlinType): FfiType
150
+
151
+ // Read a Kotlin type from a `ByteBuffer`
152
+ fun read(buf: ByteBuffer): KotlinType
153
+
154
+ // Calculate bytes to allocate when creating a `RustBuffer`
155
+ //
156
+ // This must return at least as many bytes as the write() function will
157
+ // write. It can return more bytes than needed, for example when writing
158
+ // Strings we can't know the exact bytes needed until we the UTF-8
159
+ // encoding, so we pessimistically allocate the largest size possible (3
160
+ // bytes per codepoint). Allocating extra bytes is not really a big deal
161
+ // because the `RustBuffer` is short-lived.
162
+ fun allocationSize(value: KotlinType): ULong
163
+
164
+ // Write a Kotlin type to a `ByteBuffer`
165
+ fun write(value: KotlinType, buf: ByteBuffer)
166
+
167
+ // Lower a value into a `RustBuffer`
168
+ //
169
+ // This method lowers a value into a `RustBuffer` rather than the normal
170
+ // FfiType. It's used by the callback interface code. Callback interface
171
+ // returns are always serialized into a `RustBuffer` regardless of their
172
+ // normal FFI type.
173
+ fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
174
+ val rbuf = RustBuffer.alloc(allocationSize(value))
175
+ try {
176
+ val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
177
+ it.order(ByteOrder.BIG_ENDIAN)
178
+ }
179
+ write(value, bbuf)
180
+ rbuf.writeField("len", bbuf.position().toLong())
181
+ return rbuf
182
+ } catch (e: Throwable) {
183
+ RustBuffer.free(rbuf)
184
+ throw e
185
+ }
186
+ }
187
+
188
+ // Lift a value from a `RustBuffer`.
189
+ //
190
+ // This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
191
+ // It's currently only used by the `FfiConverterRustBuffer` class below.
192
+ fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
193
+ val byteBuf = rbuf.asByteBuffer()!!
194
+ try {
195
+ val item = read(byteBuf)
196
+ if (byteBuf.hasRemaining()) {
197
+ throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
198
+ }
199
+ return item
200
+ } finally {
201
+ RustBuffer.free(rbuf)
202
+ }
203
+ }
204
+ }
205
+
206
+ /**
207
+ * FfiConverter that uses `RustBuffer` as the FfiType
208
+ *
209
+ * @suppress
210
+ */
211
+ public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
212
+ override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
213
+ override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
214
+ }
215
+ // A handful of classes and functions to support the generated data structures.
216
+ // This would be a good candidate for isolating in its own ffi-support lib.
217
+
218
+ internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
219
+ internal const val UNIFFI_CALL_ERROR = 1.toByte()
220
+ internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()
221
+
222
+ @Structure.FieldOrder("code", "error_buf")
223
+ internal open class UniffiRustCallStatus : Structure() {
224
+ @JvmField var code: Byte = 0
225
+ @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
226
+
227
+ class ByValue: UniffiRustCallStatus(), Structure.ByValue
228
+
229
+ fun isSuccess(): Boolean {
230
+ return code == UNIFFI_CALL_SUCCESS
231
+ }
232
+
233
+ fun isError(): Boolean {
234
+ return code == UNIFFI_CALL_ERROR
235
+ }
236
+
237
+ fun isPanic(): Boolean {
238
+ return code == UNIFFI_CALL_UNEXPECTED_ERROR
239
+ }
240
+
241
+ companion object {
242
+ fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
243
+ val callStatus = UniffiRustCallStatus.ByValue()
244
+ callStatus.code = code
245
+ callStatus.error_buf = errorBuf
246
+ return callStatus
247
+ }
248
+ }
249
+ }
250
+
251
+ class InternalException(message: String) : kotlin.Exception(message)
252
+
253
+ /**
254
+ * Each top-level error class has a companion object that can lift the error from the call status's rust buffer
255
+ *
256
+ * @suppress
257
+ */
258
+ interface UniffiRustCallStatusErrorHandler<E> {
259
+ fun lift(error_buf: RustBuffer.ByValue): E;
260
+ }
261
+
262
+ // Helpers for calling Rust
263
+ // In practice we usually need to be synchronized to call this safely, so it doesn't
264
+ // synchronize itself
265
+
266
+ // Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
267
+ private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
268
+ var status = UniffiRustCallStatus()
269
+ val return_value = callback(status)
270
+ uniffiCheckCallStatus(errorHandler, status)
271
+ return return_value
272
+ }
273
+
274
+ // Check UniffiRustCallStatus and throw an error if the call wasn't successful
275
+ private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
276
+ if (status.isSuccess()) {
277
+ return
278
+ } else if (status.isError()) {
279
+ throw errorHandler.lift(status.error_buf)
280
+ } else if (status.isPanic()) {
281
+ // when the rust code sees a panic, it tries to construct a rustbuffer
282
+ // with the message. but if that code panics, then it just sends back
283
+ // an empty buffer.
284
+ if (status.error_buf.len > 0) {
285
+ throw InternalException(FfiConverterString.lift(status.error_buf))
286
+ } else {
287
+ throw InternalException("Rust panic")
288
+ }
289
+ } else {
290
+ throw InternalException("Unknown rust call status: $status.code")
291
+ }
292
+ }
293
+
294
+ /**
295
+ * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
296
+ *
297
+ * @suppress
298
+ */
299
+ object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
300
+ override fun lift(error_buf: RustBuffer.ByValue): InternalException {
301
+ RustBuffer.free(error_buf)
302
+ return InternalException("Unexpected CALL_ERROR")
303
+ }
304
+ }
305
+
306
+ // Call a rust function that returns a plain value
307
+ private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
308
+ return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
309
+ }
310
+
311
+ internal inline fun<T> uniffiTraitInterfaceCall(
312
+ callStatus: UniffiRustCallStatus,
313
+ makeCall: () -> T,
314
+ writeReturn: (T) -> Unit,
315
+ ) {
316
+ try {
317
+ writeReturn(makeCall())
318
+ } catch(e: kotlin.Exception) {
319
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
320
+ callStatus.error_buf = FfiConverterString.lower(e.toString())
321
+ }
322
+ }
323
+
324
+ internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
325
+ callStatus: UniffiRustCallStatus,
326
+ makeCall: () -> T,
327
+ writeReturn: (T) -> Unit,
328
+ lowerError: (E) -> RustBuffer.ByValue
329
+ ) {
330
+ try {
331
+ writeReturn(makeCall())
332
+ } catch(e: kotlin.Exception) {
333
+ if (e is E) {
334
+ callStatus.code = UNIFFI_CALL_ERROR
335
+ callStatus.error_buf = lowerError(e)
336
+ } else {
337
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
338
+ callStatus.error_buf = FfiConverterString.lower(e.toString())
339
+ }
340
+ }
341
+ }
342
+ // Map handles to objects
343
+ //
344
+ // This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
345
+ internal class UniffiHandleMap<T: Any> {
346
+ private val map = ConcurrentHashMap<Long, T>()
347
+ private val counter = java.util.concurrent.atomic.AtomicLong(0)
348
+
349
+ val size: Int
350
+ get() = map.size
351
+
352
+ // Insert a new object into the handle map and get a handle for it
353
+ fun insert(obj: T): Long {
354
+ val handle = counter.getAndAdd(1)
355
+ map.put(handle, obj)
356
+ return handle
357
+ }
358
+
359
+ // Get an object from the handle map
360
+ fun get(handle: Long): T {
361
+ return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
362
+ }
363
+
364
+ // Remove an entry from the handlemap and get the Kotlin object back
365
+ fun remove(handle: Long): T {
366
+ return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
367
+ }
368
+ }
369
+
370
+ // Contains loading, initialization code,
371
+ // and the FFI Function declarations in a com.sun.jna.Library.
372
+ @Synchronized
373
+ private fun findLibraryName(componentName: String): String {
374
+ val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
375
+ if (libOverride != null) {
376
+ return libOverride
377
+ }
378
+ return "genation_bridge_crypto_uniffi"
379
+ }
380
+
381
+ private inline fun <reified Lib : Library> loadIndirect(
382
+ componentName: String
383
+ ): Lib {
384
+ return Native.load<Lib>(findLibraryName(componentName), Lib::class.java)
385
+ }
386
+
387
+ // Define FFI callback types
388
+ internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
389
+ fun callback(`data`: Long,`pollResult`: Byte,)
390
+ }
391
+ internal interface UniffiForeignFutureFree : com.sun.jna.Callback {
392
+ fun callback(`handle`: Long,)
393
+ }
394
+ internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
395
+ fun callback(`handle`: Long,)
396
+ }
397
+ @Structure.FieldOrder("handle", "free")
398
+ internal open class UniffiForeignFuture(
399
+ @JvmField internal var `handle`: Long = 0.toLong(),
400
+ @JvmField internal var `free`: UniffiForeignFutureFree? = null,
401
+ ) : Structure() {
402
+ class UniffiByValue(
403
+ `handle`: Long = 0.toLong(),
404
+ `free`: UniffiForeignFutureFree? = null,
405
+ ): UniffiForeignFuture(`handle`,`free`,), Structure.ByValue
406
+
407
+ internal fun uniffiSetValue(other: UniffiForeignFuture) {
408
+ `handle` = other.`handle`
409
+ `free` = other.`free`
410
+ }
411
+
412
+ }
413
+ @Structure.FieldOrder("returnValue", "callStatus")
414
+ internal open class UniffiForeignFutureStructU8(
415
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
416
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
417
+ ) : Structure() {
418
+ class UniffiByValue(
419
+ `returnValue`: Byte = 0.toByte(),
420
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
421
+ ): UniffiForeignFutureStructU8(`returnValue`,`callStatus`,), Structure.ByValue
422
+
423
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU8) {
424
+ `returnValue` = other.`returnValue`
425
+ `callStatus` = other.`callStatus`
426
+ }
427
+
428
+ }
429
+ internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
430
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU8.UniffiByValue,)
431
+ }
432
+ @Structure.FieldOrder("returnValue", "callStatus")
433
+ internal open class UniffiForeignFutureStructI8(
434
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
435
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
436
+ ) : Structure() {
437
+ class UniffiByValue(
438
+ `returnValue`: Byte = 0.toByte(),
439
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
440
+ ): UniffiForeignFutureStructI8(`returnValue`,`callStatus`,), Structure.ByValue
441
+
442
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI8) {
443
+ `returnValue` = other.`returnValue`
444
+ `callStatus` = other.`callStatus`
445
+ }
446
+
447
+ }
448
+ internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
449
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI8.UniffiByValue,)
450
+ }
451
+ @Structure.FieldOrder("returnValue", "callStatus")
452
+ internal open class UniffiForeignFutureStructU16(
453
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
454
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
455
+ ) : Structure() {
456
+ class UniffiByValue(
457
+ `returnValue`: Short = 0.toShort(),
458
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
459
+ ): UniffiForeignFutureStructU16(`returnValue`,`callStatus`,), Structure.ByValue
460
+
461
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU16) {
462
+ `returnValue` = other.`returnValue`
463
+ `callStatus` = other.`callStatus`
464
+ }
465
+
466
+ }
467
+ internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
468
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU16.UniffiByValue,)
469
+ }
470
+ @Structure.FieldOrder("returnValue", "callStatus")
471
+ internal open class UniffiForeignFutureStructI16(
472
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
473
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
474
+ ) : Structure() {
475
+ class UniffiByValue(
476
+ `returnValue`: Short = 0.toShort(),
477
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
478
+ ): UniffiForeignFutureStructI16(`returnValue`,`callStatus`,), Structure.ByValue
479
+
480
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI16) {
481
+ `returnValue` = other.`returnValue`
482
+ `callStatus` = other.`callStatus`
483
+ }
484
+
485
+ }
486
+ internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
487
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI16.UniffiByValue,)
488
+ }
489
+ @Structure.FieldOrder("returnValue", "callStatus")
490
+ internal open class UniffiForeignFutureStructU32(
491
+ @JvmField internal var `returnValue`: Int = 0,
492
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
493
+ ) : Structure() {
494
+ class UniffiByValue(
495
+ `returnValue`: Int = 0,
496
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
497
+ ): UniffiForeignFutureStructU32(`returnValue`,`callStatus`,), Structure.ByValue
498
+
499
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU32) {
500
+ `returnValue` = other.`returnValue`
501
+ `callStatus` = other.`callStatus`
502
+ }
503
+
504
+ }
505
+ internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
506
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU32.UniffiByValue,)
507
+ }
508
+ @Structure.FieldOrder("returnValue", "callStatus")
509
+ internal open class UniffiForeignFutureStructI32(
510
+ @JvmField internal var `returnValue`: Int = 0,
511
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
512
+ ) : Structure() {
513
+ class UniffiByValue(
514
+ `returnValue`: Int = 0,
515
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
516
+ ): UniffiForeignFutureStructI32(`returnValue`,`callStatus`,), Structure.ByValue
517
+
518
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI32) {
519
+ `returnValue` = other.`returnValue`
520
+ `callStatus` = other.`callStatus`
521
+ }
522
+
523
+ }
524
+ internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
525
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI32.UniffiByValue,)
526
+ }
527
+ @Structure.FieldOrder("returnValue", "callStatus")
528
+ internal open class UniffiForeignFutureStructU64(
529
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
530
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
531
+ ) : Structure() {
532
+ class UniffiByValue(
533
+ `returnValue`: Long = 0.toLong(),
534
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
535
+ ): UniffiForeignFutureStructU64(`returnValue`,`callStatus`,), Structure.ByValue
536
+
537
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU64) {
538
+ `returnValue` = other.`returnValue`
539
+ `callStatus` = other.`callStatus`
540
+ }
541
+
542
+ }
543
+ internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
544
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU64.UniffiByValue,)
545
+ }
546
+ @Structure.FieldOrder("returnValue", "callStatus")
547
+ internal open class UniffiForeignFutureStructI64(
548
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
549
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
550
+ ) : Structure() {
551
+ class UniffiByValue(
552
+ `returnValue`: Long = 0.toLong(),
553
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
554
+ ): UniffiForeignFutureStructI64(`returnValue`,`callStatus`,), Structure.ByValue
555
+
556
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI64) {
557
+ `returnValue` = other.`returnValue`
558
+ `callStatus` = other.`callStatus`
559
+ }
560
+
561
+ }
562
+ internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
563
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI64.UniffiByValue,)
564
+ }
565
+ @Structure.FieldOrder("returnValue", "callStatus")
566
+ internal open class UniffiForeignFutureStructF32(
567
+ @JvmField internal var `returnValue`: Float = 0.0f,
568
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
569
+ ) : Structure() {
570
+ class UniffiByValue(
571
+ `returnValue`: Float = 0.0f,
572
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
573
+ ): UniffiForeignFutureStructF32(`returnValue`,`callStatus`,), Structure.ByValue
574
+
575
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructF32) {
576
+ `returnValue` = other.`returnValue`
577
+ `callStatus` = other.`callStatus`
578
+ }
579
+
580
+ }
581
+ internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
582
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF32.UniffiByValue,)
583
+ }
584
+ @Structure.FieldOrder("returnValue", "callStatus")
585
+ internal open class UniffiForeignFutureStructF64(
586
+ @JvmField internal var `returnValue`: Double = 0.0,
587
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
588
+ ) : Structure() {
589
+ class UniffiByValue(
590
+ `returnValue`: Double = 0.0,
591
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
592
+ ): UniffiForeignFutureStructF64(`returnValue`,`callStatus`,), Structure.ByValue
593
+
594
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructF64) {
595
+ `returnValue` = other.`returnValue`
596
+ `callStatus` = other.`callStatus`
597
+ }
598
+
599
+ }
600
+ internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
601
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF64.UniffiByValue,)
602
+ }
603
+ @Structure.FieldOrder("returnValue", "callStatus")
604
+ internal open class UniffiForeignFutureStructPointer(
605
+ @JvmField internal var `returnValue`: Pointer = Pointer.NULL,
606
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
607
+ ) : Structure() {
608
+ class UniffiByValue(
609
+ `returnValue`: Pointer = Pointer.NULL,
610
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
611
+ ): UniffiForeignFutureStructPointer(`returnValue`,`callStatus`,), Structure.ByValue
612
+
613
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructPointer) {
614
+ `returnValue` = other.`returnValue`
615
+ `callStatus` = other.`callStatus`
616
+ }
617
+
618
+ }
619
+ internal interface UniffiForeignFutureCompletePointer : com.sun.jna.Callback {
620
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructPointer.UniffiByValue,)
621
+ }
622
+ @Structure.FieldOrder("returnValue", "callStatus")
623
+ internal open class UniffiForeignFutureStructRustBuffer(
624
+ @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
625
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
626
+ ) : Structure() {
627
+ class UniffiByValue(
628
+ `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
629
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
630
+ ): UniffiForeignFutureStructRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue
631
+
632
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructRustBuffer) {
633
+ `returnValue` = other.`returnValue`
634
+ `callStatus` = other.`callStatus`
635
+ }
636
+
637
+ }
638
+ internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
639
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructRustBuffer.UniffiByValue,)
640
+ }
641
+ @Structure.FieldOrder("callStatus")
642
+ internal open class UniffiForeignFutureStructVoid(
643
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
644
+ ) : Structure() {
645
+ class UniffiByValue(
646
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
647
+ ): UniffiForeignFutureStructVoid(`callStatus`,), Structure.ByValue
648
+
649
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructVoid) {
650
+ `callStatus` = other.`callStatus`
651
+ }
652
+
653
+ }
654
+ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
655
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructVoid.UniffiByValue,)
656
+ }
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+
684
+
685
+
686
+
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+ // For large crates we prevent `MethodTooLargeException` (see #2340)
746
+ // N.B. the name of the extension is very misleading, since it is
747
+ // rather `InterfaceTooLargeException`, caused by too many methods
748
+ // in the interface for large crates.
749
+ //
750
+ // By splitting the otherwise huge interface into two parts
751
+ // * UniffiLib
752
+ // * IntegrityCheckingUniffiLib (this)
753
+ // we allow for ~2x as many methods in the UniffiLib interface.
754
+ //
755
+ // The `ffi_uniffi_contract_version` method and all checksum methods are put
756
+ // into `IntegrityCheckingUniffiLib` and these methods are called only once,
757
+ // when the library is loaded.
758
+ internal interface IntegrityCheckingUniffiLib : Library {
759
+ // Integrity check functions only
760
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_func_generate_mobile_identity(
761
+ ): Short
762
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_func_sign_mobile_ed25519(
763
+ ): Short
764
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_begin_handshake(
765
+ ): Short
766
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_close_session(
767
+ ): Short
768
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_decrypt(
769
+ ): Short
770
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_encrypt(
771
+ ): Short
772
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_finish_handshake(
773
+ ): Short
774
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_accept_handshake(
775
+ ): Short
776
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_close_session(
777
+ ): Short
778
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_decrypt(
779
+ ): Short
780
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_encrypt(
781
+ ): Short
782
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_constructor_mobileinitiator_new(
783
+ ): Short
784
+ fun uniffi_genation_bridge_crypto_uniffi_checksum_constructor_mobileresponder_new(
785
+ ): Short
786
+ fun ffi_genation_bridge_crypto_uniffi_uniffi_contract_version(
787
+ ): Int
788
+
789
+ }
790
+
791
+ // A JNA Library to expose the extern-C FFI definitions.
792
+ // This is an implementation detail which will be called internally by the public API.
793
+ internal interface UniffiLib : Library {
794
+ companion object {
795
+ internal val INSTANCE: UniffiLib by lazy {
796
+ val componentName = "genation_bridge_crypto_uniffi"
797
+ // For large crates we prevent `MethodTooLargeException` (see #2340)
798
+ // N.B. the name of the extension is very misleading, since it is
799
+ // rather `InterfaceTooLargeException`, caused by too many methods
800
+ // in the interface for large crates.
801
+ //
802
+ // By splitting the otherwise huge interface into two parts
803
+ // * UniffiLib (this)
804
+ // * IntegrityCheckingUniffiLib
805
+ // And all checksum methods are put into `IntegrityCheckingUniffiLib`
806
+ // we allow for ~2x as many methods in the UniffiLib interface.
807
+ //
808
+ // Thus we first load the library with `loadIndirect` as `IntegrityCheckingUniffiLib`
809
+ // so that we can (optionally!) call `uniffiCheckApiChecksums`...
810
+ loadIndirect<IntegrityCheckingUniffiLib>(componentName)
811
+ .also { lib: IntegrityCheckingUniffiLib ->
812
+ uniffiCheckContractApiVersion(lib)
813
+ uniffiCheckApiChecksums(lib)
814
+ }
815
+ // ... and then we load the library as `UniffiLib`
816
+ // N.B. we cannot use `loadIndirect` once and then try to cast it to `UniffiLib`
817
+ // => results in `java.lang.ClassCastException: com.sun.proxy.$Proxy cannot be cast to ...`
818
+ // error. So we must call `loadIndirect` twice. For crates large enough
819
+ // to trigger this issue, the performance impact is negligible, running on
820
+ // a macOS M1 machine the `loadIndirect` call takes ~50ms.
821
+ val lib = loadIndirect<UniffiLib>(componentName)
822
+ // No need to check the contract version and checksums, since
823
+ // we already did that with `IntegrityCheckingUniffiLib` above.
824
+ // Loading of library with integrity check done.
825
+ lib
826
+ }
827
+
828
+ // The Cleaner for the whole library
829
+ internal val CLEANER: UniffiCleaner by lazy {
830
+ UniffiCleaner.create()
831
+ }
832
+ }
833
+
834
+ // FFI functions
835
+ fun uniffi_genation_bridge_crypto_uniffi_fn_clone_mobileinitiator(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
836
+ ): Pointer
837
+ fun uniffi_genation_bridge_crypto_uniffi_fn_free_mobileinitiator(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
838
+ ): Unit
839
+ fun uniffi_genation_bridge_crypto_uniffi_fn_constructor_mobileinitiator_new(`prologue`: RustBuffer.ByValue,`localPrivateKey`: RustBuffer.ByValue,`responderPublicKey`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
840
+ ): Pointer
841
+ fun uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_begin_handshake(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
842
+ ): RustBuffer.ByValue
843
+ fun uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_close_session(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
844
+ ): Unit
845
+ fun uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_decrypt(`ptr`: Pointer,`aad`: RustBuffer.ByValue,`ciphertext`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
846
+ ): RustBuffer.ByValue
847
+ fun uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_encrypt(`ptr`: Pointer,`aad`: RustBuffer.ByValue,`plaintext`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
848
+ ): RustBuffer.ByValue
849
+ fun uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_finish_handshake(`ptr`: Pointer,`message`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
850
+ ): Unit
851
+ fun uniffi_genation_bridge_crypto_uniffi_fn_clone_mobileresponder(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
852
+ ): Pointer
853
+ fun uniffi_genation_bridge_crypto_uniffi_fn_free_mobileresponder(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
854
+ ): Unit
855
+ fun uniffi_genation_bridge_crypto_uniffi_fn_constructor_mobileresponder_new(`prologue`: RustBuffer.ByValue,`localPrivateKey`: RustBuffer.ByValue,`initiatorPublicKey`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
856
+ ): Pointer
857
+ fun uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_accept_handshake(`ptr`: Pointer,`message`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
858
+ ): RustBuffer.ByValue
859
+ fun uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_close_session(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
860
+ ): Unit
861
+ fun uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_decrypt(`ptr`: Pointer,`aad`: RustBuffer.ByValue,`ciphertext`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
862
+ ): RustBuffer.ByValue
863
+ fun uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_encrypt(`ptr`: Pointer,`aad`: RustBuffer.ByValue,`plaintext`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
864
+ ): RustBuffer.ByValue
865
+ fun uniffi_genation_bridge_crypto_uniffi_fn_func_generate_mobile_identity(uniffi_out_err: UniffiRustCallStatus,
866
+ ): RustBuffer.ByValue
867
+ fun uniffi_genation_bridge_crypto_uniffi_fn_func_sign_mobile_ed25519(`privateKey`: RustBuffer.ByValue,`message`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
868
+ ): RustBuffer.ByValue
869
+ fun ffi_genation_bridge_crypto_uniffi_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
870
+ ): RustBuffer.ByValue
871
+ fun ffi_genation_bridge_crypto_uniffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
872
+ ): RustBuffer.ByValue
873
+ fun ffi_genation_bridge_crypto_uniffi_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
874
+ ): Unit
875
+ fun ffi_genation_bridge_crypto_uniffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus,
876
+ ): RustBuffer.ByValue
877
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
878
+ ): Unit
879
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_u8(`handle`: Long,
880
+ ): Unit
881
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_u8(`handle`: Long,
882
+ ): Unit
883
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
884
+ ): Byte
885
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
886
+ ): Unit
887
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_i8(`handle`: Long,
888
+ ): Unit
889
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_i8(`handle`: Long,
890
+ ): Unit
891
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
892
+ ): Byte
893
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
894
+ ): Unit
895
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_u16(`handle`: Long,
896
+ ): Unit
897
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_u16(`handle`: Long,
898
+ ): Unit
899
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
900
+ ): Short
901
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
902
+ ): Unit
903
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_i16(`handle`: Long,
904
+ ): Unit
905
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_i16(`handle`: Long,
906
+ ): Unit
907
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
908
+ ): Short
909
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
910
+ ): Unit
911
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_u32(`handle`: Long,
912
+ ): Unit
913
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_u32(`handle`: Long,
914
+ ): Unit
915
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
916
+ ): Int
917
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
918
+ ): Unit
919
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_i32(`handle`: Long,
920
+ ): Unit
921
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_i32(`handle`: Long,
922
+ ): Unit
923
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
924
+ ): Int
925
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
926
+ ): Unit
927
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_u64(`handle`: Long,
928
+ ): Unit
929
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_u64(`handle`: Long,
930
+ ): Unit
931
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
932
+ ): Long
933
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
934
+ ): Unit
935
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_i64(`handle`: Long,
936
+ ): Unit
937
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_i64(`handle`: Long,
938
+ ): Unit
939
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
940
+ ): Long
941
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
942
+ ): Unit
943
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_f32(`handle`: Long,
944
+ ): Unit
945
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_f32(`handle`: Long,
946
+ ): Unit
947
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
948
+ ): Float
949
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
950
+ ): Unit
951
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_f64(`handle`: Long,
952
+ ): Unit
953
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_f64(`handle`: Long,
954
+ ): Unit
955
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
956
+ ): Double
957
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_pointer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
958
+ ): Unit
959
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_pointer(`handle`: Long,
960
+ ): Unit
961
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_pointer(`handle`: Long,
962
+ ): Unit
963
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_pointer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
964
+ ): Pointer
965
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
966
+ ): Unit
967
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_rust_buffer(`handle`: Long,
968
+ ): Unit
969
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_rust_buffer(`handle`: Long,
970
+ ): Unit
971
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
972
+ ): RustBuffer.ByValue
973
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
974
+ ): Unit
975
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_cancel_void(`handle`: Long,
976
+ ): Unit
977
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_free_void(`handle`: Long,
978
+ ): Unit
979
+ fun ffi_genation_bridge_crypto_uniffi_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
980
+ ): Unit
981
+
982
+ }
983
+
984
+ private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) {
985
+ // Get the bindings contract version from our ComponentInterface
986
+ val bindings_contract_version = 29
987
+ // Get the scaffolding contract version by calling the into the dylib
988
+ val scaffolding_contract_version = lib.ffi_genation_bridge_crypto_uniffi_uniffi_contract_version()
989
+ if (bindings_contract_version != scaffolding_contract_version) {
990
+ throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
991
+ }
992
+ }
993
+ @Suppress("UNUSED_PARAMETER")
994
+ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
995
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_func_generate_mobile_identity() != 57168.toShort()) {
996
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
997
+ }
998
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_func_sign_mobile_ed25519() != 51877.toShort()) {
999
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1000
+ }
1001
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_begin_handshake() != 65237.toShort()) {
1002
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1003
+ }
1004
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_close_session() != 30071.toShort()) {
1005
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1006
+ }
1007
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_decrypt() != 20411.toShort()) {
1008
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1009
+ }
1010
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_encrypt() != 51395.toShort()) {
1011
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1012
+ }
1013
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_finish_handshake() != 42193.toShort()) {
1014
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1015
+ }
1016
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_accept_handshake() != 15954.toShort()) {
1017
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1018
+ }
1019
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_close_session() != 32745.toShort()) {
1020
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1021
+ }
1022
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_decrypt() != 7094.toShort()) {
1023
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1024
+ }
1025
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_encrypt() != 32833.toShort()) {
1026
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1027
+ }
1028
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_constructor_mobileinitiator_new() != 58460.toShort()) {
1029
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1030
+ }
1031
+ if (lib.uniffi_genation_bridge_crypto_uniffi_checksum_constructor_mobileresponder_new() != 14675.toShort()) {
1032
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1033
+ }
1034
+ }
1035
+
1036
+ /**
1037
+ * @suppress
1038
+ */
1039
+ public fun uniffiEnsureInitialized() {
1040
+ UniffiLib.INSTANCE
1041
+ }
1042
+
1043
+ // Async support
1044
+
1045
+ // Public interface members begin here.
1046
+
1047
+
1048
+ // Interface implemented by anything that can contain an object reference.
1049
+ //
1050
+ // Such types expose a `destroy()` method that must be called to cleanly
1051
+ // dispose of the contained objects. Failure to call this method may result
1052
+ // in memory leaks.
1053
+ //
1054
+ // The easiest way to ensure this method is called is to use the `.use`
1055
+ // helper method to execute a block and destroy the object at the end.
1056
+ interface Disposable {
1057
+ fun destroy()
1058
+ companion object {
1059
+ fun destroy(vararg args: Any?) {
1060
+ for (arg in args) {
1061
+ when (arg) {
1062
+ is Disposable -> arg.destroy()
1063
+ is ArrayList<*> -> {
1064
+ for (idx in arg.indices) {
1065
+ val element = arg[idx]
1066
+ if (element is Disposable) {
1067
+ element.destroy()
1068
+ }
1069
+ }
1070
+ }
1071
+ is Map<*, *> -> {
1072
+ for (element in arg.values) {
1073
+ if (element is Disposable) {
1074
+ element.destroy()
1075
+ }
1076
+ }
1077
+ }
1078
+ is Iterable<*> -> {
1079
+ for (element in arg) {
1080
+ if (element is Disposable) {
1081
+ element.destroy()
1082
+ }
1083
+ }
1084
+ }
1085
+ }
1086
+ }
1087
+ }
1088
+ }
1089
+ }
1090
+
1091
+ /**
1092
+ * @suppress
1093
+ */
1094
+ inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
1095
+ try {
1096
+ block(this)
1097
+ } finally {
1098
+ try {
1099
+ // N.B. our implementation is on the nullable type `Disposable?`.
1100
+ this?.destroy()
1101
+ } catch (e: Throwable) {
1102
+ // swallow
1103
+ }
1104
+ }
1105
+
1106
+ /**
1107
+ * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
1108
+ *
1109
+ * @suppress
1110
+ * */
1111
+ object NoPointer
1112
+ /**
1113
+ * The cleaner interface for Object finalization code to run.
1114
+ * This is the entry point to any implementation that we're using.
1115
+ *
1116
+ * The cleaner registers objects and returns cleanables, so now we are
1117
+ * defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
1118
+ * different implmentations available at compile time.
1119
+ *
1120
+ * @suppress
1121
+ */
1122
+ interface UniffiCleaner {
1123
+ interface Cleanable {
1124
+ fun clean()
1125
+ }
1126
+
1127
+ fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable
1128
+
1129
+ companion object
1130
+ }
1131
+
1132
+ // The fallback Jna cleaner, which is available for both Android, and the JVM.
1133
+ private class UniffiJnaCleaner : UniffiCleaner {
1134
+ private val cleaner = com.sun.jna.internal.Cleaner.getCleaner()
1135
+
1136
+ override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
1137
+ UniffiJnaCleanable(cleaner.register(value, cleanUpTask))
1138
+ }
1139
+
1140
+ private class UniffiJnaCleanable(
1141
+ private val cleanable: com.sun.jna.internal.Cleaner.Cleanable,
1142
+ ) : UniffiCleaner.Cleanable {
1143
+ override fun clean() = cleanable.clean()
1144
+ }
1145
+
1146
+
1147
+ // We decide at uniffi binding generation time whether we were
1148
+ // using Android or not.
1149
+ // There are further runtime checks to chose the correct implementation
1150
+ // of the cleaner.
1151
+ private fun UniffiCleaner.Companion.create(): UniffiCleaner =
1152
+ try {
1153
+ // For safety's sake: if the library hasn't been run in android_cleaner = true
1154
+ // mode, but is being run on Android, then we still need to think about
1155
+ // Android API versions.
1156
+ // So we check if java.lang.ref.Cleaner is there, and use that…
1157
+ java.lang.Class.forName("java.lang.ref.Cleaner")
1158
+ JavaLangRefCleaner()
1159
+ } catch (e: ClassNotFoundException) {
1160
+ // … otherwise, fallback to the JNA cleaner.
1161
+ UniffiJnaCleaner()
1162
+ }
1163
+
1164
+ private class JavaLangRefCleaner : UniffiCleaner {
1165
+ val cleaner = java.lang.ref.Cleaner.create()
1166
+
1167
+ override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
1168
+ JavaLangRefCleanable(cleaner.register(value, cleanUpTask))
1169
+ }
1170
+
1171
+ private class JavaLangRefCleanable(
1172
+ val cleanable: java.lang.ref.Cleaner.Cleanable
1173
+ ) : UniffiCleaner.Cleanable {
1174
+ override fun clean() = cleanable.clean()
1175
+ }
1176
+
1177
+ /**
1178
+ * @suppress
1179
+ */
1180
+ public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
1181
+ // Note: we don't inherit from FfiConverterRustBuffer, because we use a
1182
+ // special encoding when lowering/lifting. We can use `RustBuffer.len` to
1183
+ // store our length and avoid writing it out to the buffer.
1184
+ override fun lift(value: RustBuffer.ByValue): String {
1185
+ try {
1186
+ val byteArr = ByteArray(value.len.toInt())
1187
+ value.asByteBuffer()!!.get(byteArr)
1188
+ return byteArr.toString(Charsets.UTF_8)
1189
+ } finally {
1190
+ RustBuffer.free(value)
1191
+ }
1192
+ }
1193
+
1194
+ override fun read(buf: ByteBuffer): String {
1195
+ val len = buf.getInt()
1196
+ val byteArr = ByteArray(len)
1197
+ buf.get(byteArr)
1198
+ return byteArr.toString(Charsets.UTF_8)
1199
+ }
1200
+
1201
+ fun toUtf8(value: String): ByteBuffer {
1202
+ // Make sure we don't have invalid UTF-16, check for lone surrogates.
1203
+ return Charsets.UTF_8.newEncoder().run {
1204
+ onMalformedInput(CodingErrorAction.REPORT)
1205
+ encode(CharBuffer.wrap(value))
1206
+ }
1207
+ }
1208
+
1209
+ override fun lower(value: String): RustBuffer.ByValue {
1210
+ val byteBuf = toUtf8(value)
1211
+ // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
1212
+ // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
1213
+ val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
1214
+ rbuf.asByteBuffer()!!.put(byteBuf)
1215
+ return rbuf
1216
+ }
1217
+
1218
+ // We aren't sure exactly how many bytes our string will be once it's UTF-8
1219
+ // encoded. Allocate 3 bytes per UTF-16 code unit which will always be
1220
+ // enough.
1221
+ override fun allocationSize(value: String): ULong {
1222
+ val sizeForLength = 4UL
1223
+ val sizeForString = value.length.toULong() * 3UL
1224
+ return sizeForLength + sizeForString
1225
+ }
1226
+
1227
+ override fun write(value: String, buf: ByteBuffer) {
1228
+ val byteBuf = toUtf8(value)
1229
+ buf.putInt(byteBuf.limit())
1230
+ buf.put(byteBuf)
1231
+ }
1232
+ }
1233
+
1234
+ /**
1235
+ * @suppress
1236
+ */
1237
+ public object FfiConverterByteArray: FfiConverterRustBuffer<ByteArray> {
1238
+ override fun read(buf: ByteBuffer): ByteArray {
1239
+ val len = buf.getInt()
1240
+ val byteArr = ByteArray(len)
1241
+ buf.get(byteArr)
1242
+ return byteArr
1243
+ }
1244
+ override fun allocationSize(value: ByteArray): ULong {
1245
+ return 4UL + value.size.toULong()
1246
+ }
1247
+ override fun write(value: ByteArray, buf: ByteBuffer) {
1248
+ buf.putInt(value.size)
1249
+ buf.put(value)
1250
+ }
1251
+ }
1252
+
1253
+
1254
+ // This template implements a class for working with a Rust struct via a Pointer/Arc<T>
1255
+ // to the live Rust struct on the other side of the FFI.
1256
+ //
1257
+ // Each instance implements core operations for working with the Rust `Arc<T>` and the
1258
+ // Kotlin Pointer to work with the live Rust struct on the other side of the FFI.
1259
+ //
1260
+ // There's some subtlety here, because we have to be careful not to operate on a Rust
1261
+ // struct after it has been dropped, and because we must expose a public API for freeing
1262
+ // theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
1263
+ //
1264
+ // * Each instance holds an opaque pointer to the underlying Rust struct.
1265
+ // Method calls need to read this pointer from the object's state and pass it in to
1266
+ // the Rust FFI.
1267
+ //
1268
+ // * When an instance is no longer needed, its pointer should be passed to a
1269
+ // special destructor function provided by the Rust FFI, which will drop the
1270
+ // underlying Rust struct.
1271
+ //
1272
+ // * Given an instance, calling code is expected to call the special
1273
+ // `destroy` method in order to free it after use, either by calling it explicitly
1274
+ // or by using a higher-level helper like the `use` method. Failing to do so risks
1275
+ // leaking the underlying Rust struct.
1276
+ //
1277
+ // * We can't assume that calling code will do the right thing, and must be prepared
1278
+ // to handle Kotlin method calls executing concurrently with or even after a call to
1279
+ // `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
1280
+ //
1281
+ // * We must never allow Rust code to operate on the underlying Rust struct after
1282
+ // the destructor has been called, and must never call the destructor more than once.
1283
+ // Doing so may trigger memory unsafety.
1284
+ //
1285
+ // * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
1286
+ // is implemented to call the destructor when the Kotlin object becomes unreachable.
1287
+ // This is done in a background thread. This is not a panacea, and client code should be aware that
1288
+ // 1. the thread may starve if some there are objects that have poorly performing
1289
+ // `drop` methods or do significant work in their `drop` methods.
1290
+ // 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
1291
+ // or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
1292
+ //
1293
+ // If we try to implement this with mutual exclusion on access to the pointer, there is the
1294
+ // possibility of a race between a method call and a concurrent call to `destroy`:
1295
+ //
1296
+ // * Thread A starts a method call, reads the value of the pointer, but is interrupted
1297
+ // before it can pass the pointer over the FFI to Rust.
1298
+ // * Thread B calls `destroy` and frees the underlying Rust struct.
1299
+ // * Thread A resumes, passing the already-read pointer value to Rust and triggering
1300
+ // a use-after-free.
1301
+ //
1302
+ // One possible solution would be to use a `ReadWriteLock`, with each method call taking
1303
+ // a read lock (and thus allowed to run concurrently) and the special `destroy` method
1304
+ // taking a write lock (and thus blocking on live method calls). However, we aim not to
1305
+ // generate methods with any hidden blocking semantics, and a `destroy` method that might
1306
+ // block if called incorrectly seems to meet that bar.
1307
+ //
1308
+ // So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
1309
+ // the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
1310
+ // has been called. These are updated according to the following rules:
1311
+ //
1312
+ // * The initial value of the counter is 1, indicating a live object with no in-flight calls.
1313
+ // The initial value for the flag is false.
1314
+ //
1315
+ // * At the start of each method call, we atomically check the counter.
1316
+ // If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
1317
+ // If it is nonzero them we atomically increment it by 1 and proceed with the method call.
1318
+ //
1319
+ // * At the end of each method call, we atomically decrement and check the counter.
1320
+ // If it has reached zero then we destroy the underlying Rust struct.
1321
+ //
1322
+ // * When `destroy` is called, we atomically flip the flag from false to true.
1323
+ // If the flag was already true we silently fail.
1324
+ // Otherwise we atomically decrement and check the counter.
1325
+ // If it has reached zero then we destroy the underlying Rust struct.
1326
+ //
1327
+ // Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
1328
+ // and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
1329
+ //
1330
+ // The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
1331
+ // called *and* all in-flight method calls have completed, avoiding violating any of the expectations
1332
+ // of the underlying Rust code.
1333
+ //
1334
+ // This makes a cleaner a better alternative to _not_ calling `destroy()` as
1335
+ // and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
1336
+ // method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
1337
+ // thread may be starved, and the app will leak memory.
1338
+ //
1339
+ // In this case, `destroy`ing manually may be a better solution.
1340
+ //
1341
+ // The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
1342
+ // with Rust peers are reclaimed:
1343
+ //
1344
+ // 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
1345
+ // 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
1346
+ // 3. The memory is reclaimed when the process terminates.
1347
+ //
1348
+ // [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
1349
+ //
1350
+
1351
+
1352
+ /**
1353
+ * Opaque initiator object retained by generated Swift or Kotlin bindings.
1354
+ */
1355
+ public interface MobileInitiatorInterface {
1356
+
1357
+ fun `beginHandshake`(): kotlin.ByteArray
1358
+
1359
+ fun `closeSession`()
1360
+
1361
+ fun `decrypt`(`aad`: kotlin.ByteArray, `ciphertext`: kotlin.ByteArray): kotlin.ByteArray
1362
+
1363
+ fun `encrypt`(`aad`: kotlin.ByteArray, `plaintext`: kotlin.ByteArray): kotlin.ByteArray
1364
+
1365
+ fun `finishHandshake`(`message`: kotlin.ByteArray)
1366
+
1367
+ companion object
1368
+ }
1369
+
1370
+ /**
1371
+ * Opaque initiator object retained by generated Swift or Kotlin bindings.
1372
+ */
1373
+ open class MobileInitiator: Disposable, AutoCloseable, MobileInitiatorInterface
1374
+ {
1375
+
1376
+ constructor(pointer: Pointer) {
1377
+ this.pointer = pointer
1378
+ this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
1379
+ }
1380
+
1381
+ /**
1382
+ * This constructor can be used to instantiate a fake object. Only used for tests. Any
1383
+ * attempt to actually use an object constructed this way will fail as there is no
1384
+ * connected Rust object.
1385
+ */
1386
+ @Suppress("UNUSED_PARAMETER")
1387
+ constructor(noPointer: NoPointer) {
1388
+ this.pointer = null
1389
+ this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
1390
+ }
1391
+ constructor(`prologue`: kotlin.ByteArray, `localPrivateKey`: kotlin.ByteArray, `responderPublicKey`: kotlin.ByteArray) :
1392
+ this(
1393
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1394
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_constructor_mobileinitiator_new(
1395
+ FfiConverterByteArray.lower(`prologue`),FfiConverterByteArray.lower(`localPrivateKey`),FfiConverterByteArray.lower(`responderPublicKey`),_status)
1396
+ }
1397
+ )
1398
+
1399
+ protected val pointer: Pointer?
1400
+ protected val cleanable: UniffiCleaner.Cleanable
1401
+
1402
+ private val wasDestroyed = AtomicBoolean(false)
1403
+ private val callCounter = AtomicLong(1)
1404
+
1405
+ override fun destroy() {
1406
+ // Only allow a single call to this method.
1407
+ // TODO: maybe we should log a warning if called more than once?
1408
+ if (this.wasDestroyed.compareAndSet(false, true)) {
1409
+ // This decrement always matches the initial count of 1 given at creation time.
1410
+ if (this.callCounter.decrementAndGet() == 0L) {
1411
+ cleanable.clean()
1412
+ }
1413
+ }
1414
+ }
1415
+
1416
+ @Synchronized
1417
+ override fun close() {
1418
+ this.destroy()
1419
+ }
1420
+
1421
+ internal inline fun <R> callWithPointer(block: (ptr: Pointer) -> R): R {
1422
+ // Check and increment the call counter, to keep the object alive.
1423
+ // This needs a compare-and-set retry loop in case of concurrent updates.
1424
+ do {
1425
+ val c = this.callCounter.get()
1426
+ if (c == 0L) {
1427
+ throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
1428
+ }
1429
+ if (c == Long.MAX_VALUE) {
1430
+ throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
1431
+ }
1432
+ } while (! this.callCounter.compareAndSet(c, c + 1L))
1433
+ // Now we can safely do the method call without the pointer being freed concurrently.
1434
+ try {
1435
+ return block(this.uniffiClonePointer())
1436
+ } finally {
1437
+ // This decrement always matches the increment we performed above.
1438
+ if (this.callCounter.decrementAndGet() == 0L) {
1439
+ cleanable.clean()
1440
+ }
1441
+ }
1442
+ }
1443
+
1444
+ // Use a static inner class instead of a closure so as not to accidentally
1445
+ // capture `this` as part of the cleanable's action.
1446
+ private class UniffiCleanAction(private val pointer: Pointer?) : Runnable {
1447
+ override fun run() {
1448
+ pointer?.let { ptr ->
1449
+ uniffiRustCall { status ->
1450
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_free_mobileinitiator(ptr, status)
1451
+ }
1452
+ }
1453
+ }
1454
+ }
1455
+
1456
+ fun uniffiClonePointer(): Pointer {
1457
+ return uniffiRustCall() { status ->
1458
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_clone_mobileinitiator(pointer!!, status)
1459
+ }
1460
+ }
1461
+
1462
+
1463
+ @Throws(MobileBindingException::class)override fun `beginHandshake`(): kotlin.ByteArray {
1464
+ return FfiConverterByteArray.lift(
1465
+ callWithPointer {
1466
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1467
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_begin_handshake(
1468
+ it, _status)
1469
+ }
1470
+ }
1471
+ )
1472
+ }
1473
+
1474
+
1475
+
1476
+ @Throws(MobileBindingException::class)override fun `closeSession`()
1477
+ =
1478
+ callWithPointer {
1479
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1480
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_close_session(
1481
+ it, _status)
1482
+ }
1483
+ }
1484
+
1485
+
1486
+
1487
+
1488
+ @Throws(MobileBindingException::class)override fun `decrypt`(`aad`: kotlin.ByteArray, `ciphertext`: kotlin.ByteArray): kotlin.ByteArray {
1489
+ return FfiConverterByteArray.lift(
1490
+ callWithPointer {
1491
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1492
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_decrypt(
1493
+ it, FfiConverterByteArray.lower(`aad`),FfiConverterByteArray.lower(`ciphertext`),_status)
1494
+ }
1495
+ }
1496
+ )
1497
+ }
1498
+
1499
+
1500
+
1501
+ @Throws(MobileBindingException::class)override fun `encrypt`(`aad`: kotlin.ByteArray, `plaintext`: kotlin.ByteArray): kotlin.ByteArray {
1502
+ return FfiConverterByteArray.lift(
1503
+ callWithPointer {
1504
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1505
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_encrypt(
1506
+ it, FfiConverterByteArray.lower(`aad`),FfiConverterByteArray.lower(`plaintext`),_status)
1507
+ }
1508
+ }
1509
+ )
1510
+ }
1511
+
1512
+
1513
+
1514
+ @Throws(MobileBindingException::class)override fun `finishHandshake`(`message`: kotlin.ByteArray)
1515
+ =
1516
+ callWithPointer {
1517
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1518
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_finish_handshake(
1519
+ it, FfiConverterByteArray.lower(`message`),_status)
1520
+ }
1521
+ }
1522
+
1523
+
1524
+
1525
+
1526
+
1527
+
1528
+
1529
+ companion object
1530
+
1531
+ }
1532
+
1533
+ /**
1534
+ * @suppress
1535
+ */
1536
+ public object FfiConverterTypeMobileInitiator: FfiConverter<MobileInitiator, Pointer> {
1537
+
1538
+ override fun lower(value: MobileInitiator): Pointer {
1539
+ return value.uniffiClonePointer()
1540
+ }
1541
+
1542
+ override fun lift(value: Pointer): MobileInitiator {
1543
+ return MobileInitiator(value)
1544
+ }
1545
+
1546
+ override fun read(buf: ByteBuffer): MobileInitiator {
1547
+ // The Rust code always writes pointers as 8 bytes, and will
1548
+ // fail to compile if they don't fit.
1549
+ return lift(Pointer(buf.getLong()))
1550
+ }
1551
+
1552
+ override fun allocationSize(value: MobileInitiator) = 8UL
1553
+
1554
+ override fun write(value: MobileInitiator, buf: ByteBuffer) {
1555
+ // The Rust code always expects pointers written as 8 bytes,
1556
+ // and will fail to compile if they don't fit.
1557
+ buf.putLong(Pointer.nativeValue(lower(value)))
1558
+ }
1559
+ }
1560
+
1561
+
1562
+ // This template implements a class for working with a Rust struct via a Pointer/Arc<T>
1563
+ // to the live Rust struct on the other side of the FFI.
1564
+ //
1565
+ // Each instance implements core operations for working with the Rust `Arc<T>` and the
1566
+ // Kotlin Pointer to work with the live Rust struct on the other side of the FFI.
1567
+ //
1568
+ // There's some subtlety here, because we have to be careful not to operate on a Rust
1569
+ // struct after it has been dropped, and because we must expose a public API for freeing
1570
+ // theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
1571
+ //
1572
+ // * Each instance holds an opaque pointer to the underlying Rust struct.
1573
+ // Method calls need to read this pointer from the object's state and pass it in to
1574
+ // the Rust FFI.
1575
+ //
1576
+ // * When an instance is no longer needed, its pointer should be passed to a
1577
+ // special destructor function provided by the Rust FFI, which will drop the
1578
+ // underlying Rust struct.
1579
+ //
1580
+ // * Given an instance, calling code is expected to call the special
1581
+ // `destroy` method in order to free it after use, either by calling it explicitly
1582
+ // or by using a higher-level helper like the `use` method. Failing to do so risks
1583
+ // leaking the underlying Rust struct.
1584
+ //
1585
+ // * We can't assume that calling code will do the right thing, and must be prepared
1586
+ // to handle Kotlin method calls executing concurrently with or even after a call to
1587
+ // `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
1588
+ //
1589
+ // * We must never allow Rust code to operate on the underlying Rust struct after
1590
+ // the destructor has been called, and must never call the destructor more than once.
1591
+ // Doing so may trigger memory unsafety.
1592
+ //
1593
+ // * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
1594
+ // is implemented to call the destructor when the Kotlin object becomes unreachable.
1595
+ // This is done in a background thread. This is not a panacea, and client code should be aware that
1596
+ // 1. the thread may starve if some there are objects that have poorly performing
1597
+ // `drop` methods or do significant work in their `drop` methods.
1598
+ // 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
1599
+ // or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
1600
+ //
1601
+ // If we try to implement this with mutual exclusion on access to the pointer, there is the
1602
+ // possibility of a race between a method call and a concurrent call to `destroy`:
1603
+ //
1604
+ // * Thread A starts a method call, reads the value of the pointer, but is interrupted
1605
+ // before it can pass the pointer over the FFI to Rust.
1606
+ // * Thread B calls `destroy` and frees the underlying Rust struct.
1607
+ // * Thread A resumes, passing the already-read pointer value to Rust and triggering
1608
+ // a use-after-free.
1609
+ //
1610
+ // One possible solution would be to use a `ReadWriteLock`, with each method call taking
1611
+ // a read lock (and thus allowed to run concurrently) and the special `destroy` method
1612
+ // taking a write lock (and thus blocking on live method calls). However, we aim not to
1613
+ // generate methods with any hidden blocking semantics, and a `destroy` method that might
1614
+ // block if called incorrectly seems to meet that bar.
1615
+ //
1616
+ // So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
1617
+ // the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
1618
+ // has been called. These are updated according to the following rules:
1619
+ //
1620
+ // * The initial value of the counter is 1, indicating a live object with no in-flight calls.
1621
+ // The initial value for the flag is false.
1622
+ //
1623
+ // * At the start of each method call, we atomically check the counter.
1624
+ // If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
1625
+ // If it is nonzero them we atomically increment it by 1 and proceed with the method call.
1626
+ //
1627
+ // * At the end of each method call, we atomically decrement and check the counter.
1628
+ // If it has reached zero then we destroy the underlying Rust struct.
1629
+ //
1630
+ // * When `destroy` is called, we atomically flip the flag from false to true.
1631
+ // If the flag was already true we silently fail.
1632
+ // Otherwise we atomically decrement and check the counter.
1633
+ // If it has reached zero then we destroy the underlying Rust struct.
1634
+ //
1635
+ // Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
1636
+ // and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
1637
+ //
1638
+ // The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
1639
+ // called *and* all in-flight method calls have completed, avoiding violating any of the expectations
1640
+ // of the underlying Rust code.
1641
+ //
1642
+ // This makes a cleaner a better alternative to _not_ calling `destroy()` as
1643
+ // and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
1644
+ // method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
1645
+ // thread may be starved, and the app will leak memory.
1646
+ //
1647
+ // In this case, `destroy`ing manually may be a better solution.
1648
+ //
1649
+ // The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
1650
+ // with Rust peers are reclaimed:
1651
+ //
1652
+ // 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
1653
+ // 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
1654
+ // 3. The memory is reclaimed when the process terminates.
1655
+ //
1656
+ // [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
1657
+ //
1658
+
1659
+
1660
+ /**
1661
+ * Opaque responder object retained by generated Swift or Kotlin bindings.
1662
+ */
1663
+ public interface MobileResponderInterface {
1664
+
1665
+ fun `acceptHandshake`(`message`: kotlin.ByteArray): kotlin.ByteArray
1666
+
1667
+ fun `closeSession`()
1668
+
1669
+ fun `decrypt`(`aad`: kotlin.ByteArray, `ciphertext`: kotlin.ByteArray): kotlin.ByteArray
1670
+
1671
+ fun `encrypt`(`aad`: kotlin.ByteArray, `plaintext`: kotlin.ByteArray): kotlin.ByteArray
1672
+
1673
+ companion object
1674
+ }
1675
+
1676
+ /**
1677
+ * Opaque responder object retained by generated Swift or Kotlin bindings.
1678
+ */
1679
+ open class MobileResponder: Disposable, AutoCloseable, MobileResponderInterface
1680
+ {
1681
+
1682
+ constructor(pointer: Pointer) {
1683
+ this.pointer = pointer
1684
+ this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
1685
+ }
1686
+
1687
+ /**
1688
+ * This constructor can be used to instantiate a fake object. Only used for tests. Any
1689
+ * attempt to actually use an object constructed this way will fail as there is no
1690
+ * connected Rust object.
1691
+ */
1692
+ @Suppress("UNUSED_PARAMETER")
1693
+ constructor(noPointer: NoPointer) {
1694
+ this.pointer = null
1695
+ this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
1696
+ }
1697
+ constructor(`prologue`: kotlin.ByteArray, `localPrivateKey`: kotlin.ByteArray, `initiatorPublicKey`: kotlin.ByteArray) :
1698
+ this(
1699
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1700
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_constructor_mobileresponder_new(
1701
+ FfiConverterByteArray.lower(`prologue`),FfiConverterByteArray.lower(`localPrivateKey`),FfiConverterByteArray.lower(`initiatorPublicKey`),_status)
1702
+ }
1703
+ )
1704
+
1705
+ protected val pointer: Pointer?
1706
+ protected val cleanable: UniffiCleaner.Cleanable
1707
+
1708
+ private val wasDestroyed = AtomicBoolean(false)
1709
+ private val callCounter = AtomicLong(1)
1710
+
1711
+ override fun destroy() {
1712
+ // Only allow a single call to this method.
1713
+ // TODO: maybe we should log a warning if called more than once?
1714
+ if (this.wasDestroyed.compareAndSet(false, true)) {
1715
+ // This decrement always matches the initial count of 1 given at creation time.
1716
+ if (this.callCounter.decrementAndGet() == 0L) {
1717
+ cleanable.clean()
1718
+ }
1719
+ }
1720
+ }
1721
+
1722
+ @Synchronized
1723
+ override fun close() {
1724
+ this.destroy()
1725
+ }
1726
+
1727
+ internal inline fun <R> callWithPointer(block: (ptr: Pointer) -> R): R {
1728
+ // Check and increment the call counter, to keep the object alive.
1729
+ // This needs a compare-and-set retry loop in case of concurrent updates.
1730
+ do {
1731
+ val c = this.callCounter.get()
1732
+ if (c == 0L) {
1733
+ throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
1734
+ }
1735
+ if (c == Long.MAX_VALUE) {
1736
+ throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
1737
+ }
1738
+ } while (! this.callCounter.compareAndSet(c, c + 1L))
1739
+ // Now we can safely do the method call without the pointer being freed concurrently.
1740
+ try {
1741
+ return block(this.uniffiClonePointer())
1742
+ } finally {
1743
+ // This decrement always matches the increment we performed above.
1744
+ if (this.callCounter.decrementAndGet() == 0L) {
1745
+ cleanable.clean()
1746
+ }
1747
+ }
1748
+ }
1749
+
1750
+ // Use a static inner class instead of a closure so as not to accidentally
1751
+ // capture `this` as part of the cleanable's action.
1752
+ private class UniffiCleanAction(private val pointer: Pointer?) : Runnable {
1753
+ override fun run() {
1754
+ pointer?.let { ptr ->
1755
+ uniffiRustCall { status ->
1756
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_free_mobileresponder(ptr, status)
1757
+ }
1758
+ }
1759
+ }
1760
+ }
1761
+
1762
+ fun uniffiClonePointer(): Pointer {
1763
+ return uniffiRustCall() { status ->
1764
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_clone_mobileresponder(pointer!!, status)
1765
+ }
1766
+ }
1767
+
1768
+
1769
+ @Throws(MobileBindingException::class)override fun `acceptHandshake`(`message`: kotlin.ByteArray): kotlin.ByteArray {
1770
+ return FfiConverterByteArray.lift(
1771
+ callWithPointer {
1772
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1773
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_accept_handshake(
1774
+ it, FfiConverterByteArray.lower(`message`),_status)
1775
+ }
1776
+ }
1777
+ )
1778
+ }
1779
+
1780
+
1781
+
1782
+ @Throws(MobileBindingException::class)override fun `closeSession`()
1783
+ =
1784
+ callWithPointer {
1785
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1786
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_close_session(
1787
+ it, _status)
1788
+ }
1789
+ }
1790
+
1791
+
1792
+
1793
+
1794
+ @Throws(MobileBindingException::class)override fun `decrypt`(`aad`: kotlin.ByteArray, `ciphertext`: kotlin.ByteArray): kotlin.ByteArray {
1795
+ return FfiConverterByteArray.lift(
1796
+ callWithPointer {
1797
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1798
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_decrypt(
1799
+ it, FfiConverterByteArray.lower(`aad`),FfiConverterByteArray.lower(`ciphertext`),_status)
1800
+ }
1801
+ }
1802
+ )
1803
+ }
1804
+
1805
+
1806
+
1807
+ @Throws(MobileBindingException::class)override fun `encrypt`(`aad`: kotlin.ByteArray, `plaintext`: kotlin.ByteArray): kotlin.ByteArray {
1808
+ return FfiConverterByteArray.lift(
1809
+ callWithPointer {
1810
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1811
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_encrypt(
1812
+ it, FfiConverterByteArray.lower(`aad`),FfiConverterByteArray.lower(`plaintext`),_status)
1813
+ }
1814
+ }
1815
+ )
1816
+ }
1817
+
1818
+
1819
+
1820
+
1821
+
1822
+
1823
+ companion object
1824
+
1825
+ }
1826
+
1827
+ /**
1828
+ * @suppress
1829
+ */
1830
+ public object FfiConverterTypeMobileResponder: FfiConverter<MobileResponder, Pointer> {
1831
+
1832
+ override fun lower(value: MobileResponder): Pointer {
1833
+ return value.uniffiClonePointer()
1834
+ }
1835
+
1836
+ override fun lift(value: Pointer): MobileResponder {
1837
+ return MobileResponder(value)
1838
+ }
1839
+
1840
+ override fun read(buf: ByteBuffer): MobileResponder {
1841
+ // The Rust code always writes pointers as 8 bytes, and will
1842
+ // fail to compile if they don't fit.
1843
+ return lift(Pointer(buf.getLong()))
1844
+ }
1845
+
1846
+ override fun allocationSize(value: MobileResponder) = 8UL
1847
+
1848
+ override fun write(value: MobileResponder, buf: ByteBuffer) {
1849
+ // The Rust code always expects pointers written as 8 bytes,
1850
+ // and will fail to compile if they don't fit.
1851
+ buf.putLong(Pointer.nativeValue(lower(value)))
1852
+ }
1853
+ }
1854
+
1855
+
1856
+
1857
+ /**
1858
+ * One generated private identity returned only to the native secure-store wrapper.
1859
+ */
1860
+ data class MobileIdentityMaterial (
1861
+ var `connectionPrivateKey`: kotlin.ByteArray,
1862
+ var `connectionPublicKey`: kotlin.ByteArray,
1863
+ var `noiseStaticPrivateKey`: kotlin.ByteArray,
1864
+ var `noiseStaticPublicKey`: kotlin.ByteArray
1865
+ ) {
1866
+
1867
+ companion object
1868
+ }
1869
+
1870
+ /**
1871
+ * @suppress
1872
+ */
1873
+ public object FfiConverterTypeMobileIdentityMaterial: FfiConverterRustBuffer<MobileIdentityMaterial> {
1874
+ override fun read(buf: ByteBuffer): MobileIdentityMaterial {
1875
+ return MobileIdentityMaterial(
1876
+ FfiConverterByteArray.read(buf),
1877
+ FfiConverterByteArray.read(buf),
1878
+ FfiConverterByteArray.read(buf),
1879
+ FfiConverterByteArray.read(buf),
1880
+ )
1881
+ }
1882
+
1883
+ override fun allocationSize(value: MobileIdentityMaterial) = (
1884
+ FfiConverterByteArray.allocationSize(value.`connectionPrivateKey`) +
1885
+ FfiConverterByteArray.allocationSize(value.`connectionPublicKey`) +
1886
+ FfiConverterByteArray.allocationSize(value.`noiseStaticPrivateKey`) +
1887
+ FfiConverterByteArray.allocationSize(value.`noiseStaticPublicKey`)
1888
+ )
1889
+
1890
+ override fun write(value: MobileIdentityMaterial, buf: ByteBuffer) {
1891
+ FfiConverterByteArray.write(value.`connectionPrivateKey`, buf)
1892
+ FfiConverterByteArray.write(value.`connectionPublicKey`, buf)
1893
+ FfiConverterByteArray.write(value.`noiseStaticPrivateKey`, buf)
1894
+ FfiConverterByteArray.write(value.`noiseStaticPublicKey`, buf)
1895
+ }
1896
+ }
1897
+
1898
+
1899
+
1900
+
1901
+
1902
+ /**
1903
+ * Stable native binding failures without provider or customer content.
1904
+ */
1905
+ sealed class MobileBindingException: kotlin.Exception() {
1906
+
1907
+ class InvalidKey(
1908
+ ) : MobileBindingException() {
1909
+ override val message
1910
+ get() = ""
1911
+ }
1912
+
1913
+ class InvalidState(
1914
+ ) : MobileBindingException() {
1915
+ override val message
1916
+ get() = ""
1917
+ }
1918
+
1919
+ class Crypto(
1920
+ ) : MobileBindingException() {
1921
+ override val message
1922
+ get() = ""
1923
+ }
1924
+
1925
+
1926
+ companion object ErrorHandler : UniffiRustCallStatusErrorHandler<MobileBindingException> {
1927
+ override fun lift(error_buf: RustBuffer.ByValue): MobileBindingException = FfiConverterTypeMobileBindingError.lift(error_buf)
1928
+ }
1929
+
1930
+
1931
+ }
1932
+
1933
+ /**
1934
+ * @suppress
1935
+ */
1936
+ public object FfiConverterTypeMobileBindingError : FfiConverterRustBuffer<MobileBindingException> {
1937
+ override fun read(buf: ByteBuffer): MobileBindingException {
1938
+
1939
+
1940
+ return when(buf.getInt()) {
1941
+ 1 -> MobileBindingException.InvalidKey()
1942
+ 2 -> MobileBindingException.InvalidState()
1943
+ 3 -> MobileBindingException.Crypto()
1944
+ else -> throw RuntimeException("invalid error enum value, something is very wrong!!")
1945
+ }
1946
+ }
1947
+
1948
+ override fun allocationSize(value: MobileBindingException): ULong {
1949
+ return when(value) {
1950
+ is MobileBindingException.InvalidKey -> (
1951
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1952
+ 4UL
1953
+ )
1954
+ is MobileBindingException.InvalidState -> (
1955
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1956
+ 4UL
1957
+ )
1958
+ is MobileBindingException.Crypto -> (
1959
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1960
+ 4UL
1961
+ )
1962
+ }
1963
+ }
1964
+
1965
+ override fun write(value: MobileBindingException, buf: ByteBuffer) {
1966
+ when(value) {
1967
+ is MobileBindingException.InvalidKey -> {
1968
+ buf.putInt(1)
1969
+ Unit
1970
+ }
1971
+ is MobileBindingException.InvalidState -> {
1972
+ buf.putInt(2)
1973
+ Unit
1974
+ }
1975
+ is MobileBindingException.Crypto -> {
1976
+ buf.putInt(3)
1977
+ Unit
1978
+ }
1979
+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
1980
+ }
1981
+
1982
+ }
1983
+ /**
1984
+ * Generate independent Ed25519 and X25519 private material for native persistence.
1985
+ */
1986
+ @Throws(MobileBindingException::class) fun `generateMobileIdentity`(): MobileIdentityMaterial {
1987
+ return FfiConverterTypeMobileIdentityMaterial.lift(
1988
+ uniffiRustCallWithError(MobileBindingException) { _status ->
1989
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_func_generate_mobile_identity(
1990
+ _status)
1991
+ }
1992
+ )
1993
+ }
1994
+
1995
+
1996
+ /**
1997
+ * Sign one compact-JWS signing input with native-stored Ed25519 private material.
1998
+ */
1999
+ @Throws(MobileBindingException::class) fun `signMobileEd25519`(`privateKey`: kotlin.ByteArray, `message`: kotlin.ByteArray): kotlin.ByteArray {
2000
+ return FfiConverterByteArray.lift(
2001
+ uniffiRustCallWithError(MobileBindingException) { _status ->
2002
+ UniffiLib.INSTANCE.uniffi_genation_bridge_crypto_uniffi_fn_func_sign_mobile_ed25519(
2003
+ FfiConverterByteArray.lower(`privateKey`),FfiConverterByteArray.lower(`message`),_status)
2004
+ }
2005
+ )
2006
+ }