radroots_sdk.kt (88233B)
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.radroots_sdk 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 import kotlin.coroutines.resume 35 import kotlinx.coroutines.CancellableContinuation 36 import kotlinx.coroutines.DelicateCoroutinesApi 37 import kotlinx.coroutines.GlobalScope 38 import kotlinx.coroutines.Job 39 import kotlinx.coroutines.launch 40 import kotlinx.coroutines.suspendCancellableCoroutine 41 42 // This is a helper for safely working with byte buffers returned from the Rust code. 43 // A rust-owned buffer is represented by its capacity, its current length, and a 44 // pointer to the underlying data. 45 46 /** 47 * @suppress 48 */ 49 @Structure.FieldOrder("capacity", "len", "data") 50 open class RustBuffer : Structure() { 51 // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values. 52 // When dealing with these fields, make sure to call `toULong()`. 53 @JvmField var capacity: Long = 0 54 @JvmField var len: Long = 0 55 @JvmField var data: Pointer? = null 56 57 class ByValue: RustBuffer(), Structure.ByValue 58 class ByReference: RustBuffer(), Structure.ByReference 59 60 internal fun setValue(other: RustBuffer) { 61 capacity = other.capacity 62 len = other.len 63 data = other.data 64 } 65 66 companion object { 67 internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status -> 68 // Note: need to convert the size to a `Long` value to make this work with JVM. 69 UniffiLib.ffi_radroots_sdk_ffi_rustbuffer_alloc(size.toLong(), status) 70 }.also { 71 if(it.data == null) { 72 throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})") 73 } 74 } 75 76 internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue { 77 var buf = RustBuffer.ByValue() 78 buf.capacity = capacity.toLong() 79 buf.len = len.toLong() 80 buf.data = data 81 return buf 82 } 83 84 internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status -> 85 UniffiLib.ffi_radroots_sdk_ffi_rustbuffer_free(buf, status) 86 } 87 } 88 89 @Suppress("TooGenericExceptionThrown") 90 fun asByteBuffer() = 91 this.data?.getByteBuffer(0, this.len)?.also { 92 it.order(ByteOrder.BIG_ENDIAN) 93 } 94 } 95 96 // This is a helper for safely passing byte references into the rust code. 97 // It's not actually used at the moment, because there aren't many things that you 98 // can take a direct pointer to in the JVM, and if we're going to copy something 99 // then we might as well copy it into a `RustBuffer`. But it's here for API 100 // completeness. 101 102 @Structure.FieldOrder("len", "data") 103 internal open class ForeignBytes : Structure() { 104 @JvmField var len: Int = 0 105 @JvmField var data: Pointer? = null 106 107 class ByValue : ForeignBytes(), Structure.ByValue 108 } 109 110 // Converter for `&[u8]` / `[ByRef] bytes` arguments. 111 // 112 // Only `lower` is valid — zero-copy byte buffers only flow foreign -> Rust, 113 // and only in argument position. `lift`, `read`, `write`, and 114 // `allocationSize` have no sound implementation here and all panic at 115 // runtime. The `FfiConverter` interface is implemented so that the 116 // compiler enforces the full method set (rather than relying on eyeball). 117 // 118 // The provided `ByteBuffer` MUST be direct — only direct buffers have a 119 // stable native address that JNA can expose via `getDirectBufferPointer`. 120 // The returned `ForeignBytes.ByValue` is only valid for the duration of 121 // the FFI call; the Rust side treats it as a borrow. 122 internal object FfiConverterByRefBytes : FfiConverter<java.nio.ByteBuffer, ForeignBytes.ByValue> { 123 override fun lower(value: java.nio.ByteBuffer): ForeignBytes.ByValue { 124 require(value.isDirect) { "UniFFI zero-copy &[u8] requires a direct ByteBuffer. Use ByteBuffer.allocateDirect()." } 125 val remaining = value.remaining() 126 val fb = ForeignBytes.ByValue() 127 fb.len = remaining 128 // Zero-length direct buffers: skip getDirectBufferPointer (platform-variable behavior) 129 // and pass null. The Rust side treats (null, 0) as &[]. 130 fb.data = if (remaining == 0) null else com.sun.jna.Native.getDirectBufferPointer(value) 131 return fb 132 } 133 134 override fun lift(value: ForeignBytes.ByValue): java.nio.ByteBuffer = 135 error("ByRef bytes cannot be lifted: zero-copy &[u8] only flows foreign->Rust") 136 137 override fun read(buf: java.nio.ByteBuffer): java.nio.ByteBuffer = 138 error("ByRef bytes cannot be read from a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.") 139 140 override fun write(value: java.nio.ByteBuffer, buf: java.nio.ByteBuffer): Unit = 141 error("ByRef bytes cannot be written to a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.") 142 143 override fun allocationSize(value: java.nio.ByteBuffer): ULong = 144 error("ByRef bytes have no RustBuffer allocation size: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.") 145 } 146 /** 147 * The FfiConverter interface handles converter types to and from the FFI 148 * 149 * All implementing objects should be public to support external types. When a 150 * type is external we need to import it's FfiConverter. 151 * 152 * @suppress 153 */ 154 public interface FfiConverter<KotlinType, FfiType> { 155 // Convert an FFI type to a Kotlin type 156 fun lift(value: FfiType): KotlinType 157 158 // Convert an Kotlin type to an FFI type 159 fun lower(value: KotlinType): FfiType 160 161 // Read a Kotlin type from a `ByteBuffer` 162 fun read(buf: ByteBuffer): KotlinType 163 164 // Calculate bytes to allocate when creating a `RustBuffer` 165 // 166 // This must return at least as many bytes as the write() function will 167 // write. It can return more bytes than needed, for example when writing 168 // Strings we can't know the exact bytes needed until we the UTF-8 169 // encoding, so we pessimistically allocate the largest size possible (3 170 // bytes per codepoint). Allocating extra bytes is not really a big deal 171 // because the `RustBuffer` is short-lived. 172 fun allocationSize(value: KotlinType): ULong 173 174 // Write a Kotlin type to a `ByteBuffer` 175 fun write(value: KotlinType, buf: ByteBuffer) 176 177 // Lower a value into a `RustBuffer` 178 // 179 // This method lowers a value into a `RustBuffer` rather than the normal 180 // FfiType. It's used by the callback interface code. Callback interface 181 // returns are always serialized into a `RustBuffer` regardless of their 182 // normal FFI type. 183 fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue { 184 val rbuf = RustBuffer.alloc(allocationSize(value)) 185 try { 186 val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also { 187 it.order(ByteOrder.BIG_ENDIAN) 188 } 189 write(value, bbuf) 190 rbuf.writeField("len", bbuf.position().toLong()) 191 return rbuf 192 } catch (e: Throwable) { 193 RustBuffer.free(rbuf) 194 throw e 195 } 196 } 197 198 // Lift a value from a `RustBuffer`. 199 // 200 // This here mostly because of the symmetry with `lowerIntoRustBuffer()`. 201 // It's currently only used by the `FfiConverterRustBuffer` class below. 202 fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType { 203 val byteBuf = rbuf.asByteBuffer()!! 204 try { 205 val item = read(byteBuf) 206 if (byteBuf.hasRemaining()) { 207 throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!") 208 } 209 return item 210 } finally { 211 RustBuffer.free(rbuf) 212 } 213 } 214 } 215 216 /** 217 * FfiConverter that uses `RustBuffer` as the FfiType 218 * 219 * @suppress 220 */ 221 public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> { 222 override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value) 223 override fun lower(value: KotlinType) = lowerIntoRustBuffer(value) 224 } 225 // A handful of classes and functions to support the generated data structures. 226 // This would be a good candidate for isolating in its own ffi-support lib. 227 228 internal const val UNIFFI_CALL_SUCCESS = 0.toByte() 229 internal const val UNIFFI_CALL_ERROR = 1.toByte() 230 internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte() 231 232 @Structure.FieldOrder("code", "error_buf") 233 internal open class UniffiRustCallStatus : Structure() { 234 @JvmField var code: Byte = 0 235 @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue() 236 237 class ByValue: UniffiRustCallStatus(), Structure.ByValue 238 239 fun isSuccess(): Boolean { 240 return code == UNIFFI_CALL_SUCCESS 241 } 242 243 fun isError(): Boolean { 244 return code == UNIFFI_CALL_ERROR 245 } 246 247 fun isPanic(): Boolean { 248 return code == UNIFFI_CALL_UNEXPECTED_ERROR 249 } 250 251 companion object { 252 fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue { 253 val callStatus = UniffiRustCallStatus.ByValue() 254 callStatus.code = code 255 callStatus.error_buf = errorBuf 256 return callStatus 257 } 258 } 259 } 260 261 class InternalException(message: String) : kotlin.Exception(message) 262 263 /** 264 * Each top-level error class has a companion object that can lift the error from the call status's rust buffer 265 * 266 * @suppress 267 */ 268 interface UniffiRustCallStatusErrorHandler<E> { 269 fun lift(error_buf: RustBuffer.ByValue): E; 270 } 271 272 // Helpers for calling Rust 273 // In practice we usually need to be synchronized to call this safely, so it doesn't 274 // synchronize itself 275 276 // Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err 277 private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U { 278 var status = UniffiRustCallStatus() 279 val return_value = callback(status) 280 uniffiCheckCallStatus(errorHandler, status) 281 return return_value 282 } 283 284 // Check UniffiRustCallStatus and throw an error if the call wasn't successful 285 private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) { 286 if (status.isSuccess()) { 287 return 288 } else if (status.isError()) { 289 throw errorHandler.lift(status.error_buf) 290 } else if (status.isPanic()) { 291 // when the rust code sees a panic, it tries to construct a rustbuffer 292 // with the message. but if that code panics, then it just sends back 293 // an empty buffer. 294 if (status.error_buf.len > 0) { 295 throw InternalException(FfiConverterString.lift(status.error_buf)) 296 } else { 297 throw InternalException("Rust panic") 298 } 299 } else { 300 throw InternalException("Unknown rust call status: $status.code") 301 } 302 } 303 304 /** 305 * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR 306 * 307 * @suppress 308 */ 309 object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> { 310 override fun lift(error_buf: RustBuffer.ByValue): InternalException { 311 RustBuffer.free(error_buf) 312 return InternalException("Unexpected CALL_ERROR") 313 } 314 } 315 316 // Call a rust function that returns a plain value 317 private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U { 318 return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback) 319 } 320 321 internal inline fun<T> uniffiTraitInterfaceCall( 322 callStatus: UniffiRustCallStatus, 323 makeCall: () -> T, 324 writeReturn: (T) -> Unit, 325 ) { 326 try { 327 writeReturn(makeCall()) 328 } catch(e: kotlin.Exception) { 329 val err = try { e.stackTraceToString() } catch(_: Throwable) { "" } 330 callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR 331 callStatus.error_buf = FfiConverterString.lower(err) 332 } 333 } 334 335 internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError( 336 callStatus: UniffiRustCallStatus, 337 makeCall: () -> T, 338 writeReturn: (T) -> Unit, 339 lowerError: (E) -> RustBuffer.ByValue 340 ) { 341 try { 342 writeReturn(makeCall()) 343 } catch(e: kotlin.Exception) { 344 if (e is E) { 345 callStatus.code = UNIFFI_CALL_ERROR 346 callStatus.error_buf = lowerError(e) 347 } else { 348 val err = try { e.stackTraceToString() } catch(_: Throwable) { "" } 349 callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR 350 callStatus.error_buf = FfiConverterString.lower(err) 351 } 352 } 353 } 354 // Initial value and increment amount for handles. 355 // These ensure that Kotlin-generated handles always have the lowest bit set 356 private const val UNIFFI_HANDLEMAP_INITIAL = 1.toLong() 357 private const val UNIFFI_HANDLEMAP_DELTA = 2.toLong() 358 359 // Map handles to objects 360 // 361 // This is used pass an opaque 64-bit handle representing a foreign object to the Rust code. 362 internal class UniffiHandleMap<T: Any> { 363 private val map = ConcurrentHashMap<Long, T>() 364 // Start 365 private val counter = java.util.concurrent.atomic.AtomicLong(UNIFFI_HANDLEMAP_INITIAL) 366 367 val size: Int 368 get() = map.size 369 370 // Insert a new object into the handle map and get a handle for it 371 fun insert(obj: T): Long { 372 val handle = counter.getAndAdd(UNIFFI_HANDLEMAP_DELTA) 373 map.put(handle, obj) 374 return handle 375 } 376 377 // Clone a handle, creating a new one 378 fun clone(handle: Long): Long { 379 val obj = map.get(handle) ?: throw InternalException("UniffiHandleMap.clone: Invalid handle") 380 return insert(obj) 381 } 382 383 // Get an object from the handle map 384 fun get(handle: Long): T { 385 return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle") 386 } 387 388 // Remove an entry from the handlemap and get the Kotlin object back 389 fun remove(handle: Long): T { 390 return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle") 391 } 392 } 393 394 // Contains loading, initialization code, 395 // and the FFI Function declarations in a com.sun.jna.Library. 396 @Synchronized 397 private fun findLibraryName(componentName: String): String { 398 val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride") 399 if (libOverride != null) { 400 return libOverride 401 } 402 return "radroots_sdk_ffi" 403 } 404 405 // Define FFI callback types 406 internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback { 407 fun callback(`data`: Long,`pollResult`: Byte,) 408 } 409 internal interface UniffiForeignFutureDroppedCallback : com.sun.jna.Callback { 410 fun callback(`handle`: Long,) 411 } 412 internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback { 413 fun callback(`handle`: Long,) 414 } 415 internal interface UniffiCallbackInterfaceClone : com.sun.jna.Callback { 416 fun callback(`handle`: Long,) 417 : Long 418 } 419 @Structure.FieldOrder("handle", "free") 420 internal open class UniffiForeignFutureDroppedCallbackStruct( 421 @JvmField internal var `handle`: Long = 0.toLong(), 422 @JvmField internal var `free`: UniffiForeignFutureDroppedCallback? = null, 423 ) : Structure() { 424 class UniffiByValue( 425 `handle`: Long = 0.toLong(), 426 `free`: UniffiForeignFutureDroppedCallback? = null, 427 ): UniffiForeignFutureDroppedCallbackStruct(`handle`,`free`,), Structure.ByValue 428 429 internal fun uniffiSetValue(other: UniffiForeignFutureDroppedCallbackStruct) { 430 `handle` = other.`handle` 431 `free` = other.`free` 432 } 433 434 } 435 @Structure.FieldOrder("returnValue", "callStatus") 436 internal open class UniffiForeignFutureResultU8( 437 @JvmField internal var `returnValue`: Byte = 0.toByte(), 438 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 439 ) : Structure() { 440 class UniffiByValue( 441 `returnValue`: Byte = 0.toByte(), 442 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 443 ): UniffiForeignFutureResultU8(`returnValue`,`callStatus`,), Structure.ByValue 444 445 internal fun uniffiSetValue(other: UniffiForeignFutureResultU8) { 446 `returnValue` = other.`returnValue` 447 `callStatus` = other.`callStatus` 448 } 449 450 } 451 internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback { 452 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU8.UniffiByValue,) 453 } 454 @Structure.FieldOrder("returnValue", "callStatus") 455 internal open class UniffiForeignFutureResultI8( 456 @JvmField internal var `returnValue`: Byte = 0.toByte(), 457 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 458 ) : Structure() { 459 class UniffiByValue( 460 `returnValue`: Byte = 0.toByte(), 461 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 462 ): UniffiForeignFutureResultI8(`returnValue`,`callStatus`,), Structure.ByValue 463 464 internal fun uniffiSetValue(other: UniffiForeignFutureResultI8) { 465 `returnValue` = other.`returnValue` 466 `callStatus` = other.`callStatus` 467 } 468 469 } 470 internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback { 471 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI8.UniffiByValue,) 472 } 473 @Structure.FieldOrder("returnValue", "callStatus") 474 internal open class UniffiForeignFutureResultU16( 475 @JvmField internal var `returnValue`: Short = 0.toShort(), 476 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 477 ) : Structure() { 478 class UniffiByValue( 479 `returnValue`: Short = 0.toShort(), 480 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 481 ): UniffiForeignFutureResultU16(`returnValue`,`callStatus`,), Structure.ByValue 482 483 internal fun uniffiSetValue(other: UniffiForeignFutureResultU16) { 484 `returnValue` = other.`returnValue` 485 `callStatus` = other.`callStatus` 486 } 487 488 } 489 internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback { 490 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU16.UniffiByValue,) 491 } 492 @Structure.FieldOrder("returnValue", "callStatus") 493 internal open class UniffiForeignFutureResultI16( 494 @JvmField internal var `returnValue`: Short = 0.toShort(), 495 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 496 ) : Structure() { 497 class UniffiByValue( 498 `returnValue`: Short = 0.toShort(), 499 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 500 ): UniffiForeignFutureResultI16(`returnValue`,`callStatus`,), Structure.ByValue 501 502 internal fun uniffiSetValue(other: UniffiForeignFutureResultI16) { 503 `returnValue` = other.`returnValue` 504 `callStatus` = other.`callStatus` 505 } 506 507 } 508 internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback { 509 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI16.UniffiByValue,) 510 } 511 @Structure.FieldOrder("returnValue", "callStatus") 512 internal open class UniffiForeignFutureResultU32( 513 @JvmField internal var `returnValue`: Int = 0, 514 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 515 ) : Structure() { 516 class UniffiByValue( 517 `returnValue`: Int = 0, 518 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 519 ): UniffiForeignFutureResultU32(`returnValue`,`callStatus`,), Structure.ByValue 520 521 internal fun uniffiSetValue(other: UniffiForeignFutureResultU32) { 522 `returnValue` = other.`returnValue` 523 `callStatus` = other.`callStatus` 524 } 525 526 } 527 internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback { 528 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU32.UniffiByValue,) 529 } 530 @Structure.FieldOrder("returnValue", "callStatus") 531 internal open class UniffiForeignFutureResultI32( 532 @JvmField internal var `returnValue`: Int = 0, 533 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 534 ) : Structure() { 535 class UniffiByValue( 536 `returnValue`: Int = 0, 537 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 538 ): UniffiForeignFutureResultI32(`returnValue`,`callStatus`,), Structure.ByValue 539 540 internal fun uniffiSetValue(other: UniffiForeignFutureResultI32) { 541 `returnValue` = other.`returnValue` 542 `callStatus` = other.`callStatus` 543 } 544 545 } 546 internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback { 547 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI32.UniffiByValue,) 548 } 549 @Structure.FieldOrder("returnValue", "callStatus") 550 internal open class UniffiForeignFutureResultU64( 551 @JvmField internal var `returnValue`: Long = 0.toLong(), 552 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 553 ) : Structure() { 554 class UniffiByValue( 555 `returnValue`: Long = 0.toLong(), 556 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 557 ): UniffiForeignFutureResultU64(`returnValue`,`callStatus`,), Structure.ByValue 558 559 internal fun uniffiSetValue(other: UniffiForeignFutureResultU64) { 560 `returnValue` = other.`returnValue` 561 `callStatus` = other.`callStatus` 562 } 563 564 } 565 internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback { 566 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU64.UniffiByValue,) 567 } 568 @Structure.FieldOrder("returnValue", "callStatus") 569 internal open class UniffiForeignFutureResultI64( 570 @JvmField internal var `returnValue`: Long = 0.toLong(), 571 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 572 ) : Structure() { 573 class UniffiByValue( 574 `returnValue`: Long = 0.toLong(), 575 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 576 ): UniffiForeignFutureResultI64(`returnValue`,`callStatus`,), Structure.ByValue 577 578 internal fun uniffiSetValue(other: UniffiForeignFutureResultI64) { 579 `returnValue` = other.`returnValue` 580 `callStatus` = other.`callStatus` 581 } 582 583 } 584 internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback { 585 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI64.UniffiByValue,) 586 } 587 @Structure.FieldOrder("returnValue", "callStatus") 588 internal open class UniffiForeignFutureResultF32( 589 @JvmField internal var `returnValue`: Float = 0.0f, 590 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 591 ) : Structure() { 592 class UniffiByValue( 593 `returnValue`: Float = 0.0f, 594 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 595 ): UniffiForeignFutureResultF32(`returnValue`,`callStatus`,), Structure.ByValue 596 597 internal fun uniffiSetValue(other: UniffiForeignFutureResultF32) { 598 `returnValue` = other.`returnValue` 599 `callStatus` = other.`callStatus` 600 } 601 602 } 603 internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback { 604 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF32.UniffiByValue,) 605 } 606 @Structure.FieldOrder("returnValue", "callStatus") 607 internal open class UniffiForeignFutureResultF64( 608 @JvmField internal var `returnValue`: Double = 0.0, 609 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 610 ) : Structure() { 611 class UniffiByValue( 612 `returnValue`: Double = 0.0, 613 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 614 ): UniffiForeignFutureResultF64(`returnValue`,`callStatus`,), Structure.ByValue 615 616 internal fun uniffiSetValue(other: UniffiForeignFutureResultF64) { 617 `returnValue` = other.`returnValue` 618 `callStatus` = other.`callStatus` 619 } 620 621 } 622 internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback { 623 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF64.UniffiByValue,) 624 } 625 @Structure.FieldOrder("returnValue", "callStatus") 626 internal open class UniffiForeignFutureResultRustBuffer( 627 @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(), 628 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 629 ) : Structure() { 630 class UniffiByValue( 631 `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(), 632 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 633 ): UniffiForeignFutureResultRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue 634 635 internal fun uniffiSetValue(other: UniffiForeignFutureResultRustBuffer) { 636 `returnValue` = other.`returnValue` 637 `callStatus` = other.`callStatus` 638 } 639 640 } 641 internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback { 642 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultRustBuffer.UniffiByValue,) 643 } 644 @Structure.FieldOrder("callStatus") 645 internal open class UniffiForeignFutureResultVoid( 646 @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 647 ) : Structure() { 648 class UniffiByValue( 649 `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), 650 ): UniffiForeignFutureResultVoid(`callStatus`,), Structure.ByValue 651 652 internal fun uniffiSetValue(other: UniffiForeignFutureResultVoid) { 653 `callStatus` = other.`callStatus` 654 } 655 656 } 657 internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { 658 fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultVoid.UniffiByValue,) 659 } 660 661 // A JNA Library to expose the extern-C FFI definitions. 662 // This is an implementation detail which will be called internally by the public API. 663 664 // For large crates we prevent `MethodTooLargeException` (see #2340) 665 // N.B. the name of the extension is very misleading, since it is 666 // rather `InterfaceTooLargeException`, caused by too many methods 667 // in the interface for large crates. 668 // 669 // By splitting the otherwise huge interface into two parts 670 // * UniffiLib (this) 671 // * IntegrityCheckingUniffiLib 672 // And all checksum methods are put into `IntegrityCheckingUniffiLib` 673 // we allow for ~2x as many methods in the UniffiLib interface. 674 // 675 // Note: above all written when we used JNA's `loadIndirect` etc. 676 // We now use JNA's "direct mapping" - unclear if same considerations apply exactly. 677 internal object IntegrityCheckingUniffiLib { 678 init { 679 Native.register(IntegrityCheckingUniffiLib::class.java, findLibraryName(componentName = "radroots_sdk")) 680 uniffiCheckContractApiVersion(this) 681 uniffiCheckApiChecksums(this) 682 } 683 684 internal fun ensureInitialized() = Unit 685 external fun uniffi_radroots_sdk_ffi_checksum_func_parse_rhi_evidence_report( 686 ): Int 687 external fun uniffi_radroots_sdk_ffi_checksum_func_parse_trade_evidence_manifest( 688 ): Int 689 external fun uniffi_radroots_sdk_ffi_checksum_func_prepare_rhi_evidence_attestation( 690 ): Int 691 external fun uniffi_radroots_sdk_ffi_checksum_func_validate_rhi_evidence_attestation( 692 ): Int 693 external fun uniffi_radroots_sdk_ffi_checksum_method_mobileclient_capabilities( 694 ): Int 695 external fun uniffi_radroots_sdk_ffi_checksum_method_mobileclient_close( 696 ): Int 697 external fun uniffi_radroots_sdk_ffi_checksum_method_mobileclient_is_closed( 698 ): Int 699 external fun uniffi_radroots_sdk_ffi_checksum_constructor_mobileclient_memory( 700 ): Int 701 external fun ffi_radroots_sdk_ffi_uniffi_contract_version( 702 ): Int 703 704 705 } 706 707 internal object UniffiLib { 708 709 // The Cleaner for the whole library 710 internal val CLEANER: UniffiCleaner by lazy { 711 UniffiCleaner.create() 712 } 713 714 715 init { 716 Native.register(UniffiLib::class.java, findLibraryName(componentName = "radroots_sdk")) 717 718 } 719 720 internal fun ensureInitialized() = Unit 721 external fun uniffi_radroots_sdk_ffi_fn_clone_mobileclient(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 722 ): Long 723 external fun uniffi_radroots_sdk_ffi_fn_free_mobileclient(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 724 ): Unit 725 external fun uniffi_radroots_sdk_ffi_fn_constructor_mobileclient_memory(uniffi_out_err: UniffiRustCallStatus, 726 ): Long 727 external fun uniffi_radroots_sdk_ffi_fn_method_mobileclient_capabilities(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 728 ): RustBuffer.ByValue 729 external fun uniffi_radroots_sdk_ffi_fn_method_mobileclient_close(`ptr`: Long, 730 ): Long 731 external fun uniffi_radroots_sdk_ffi_fn_method_mobileclient_is_closed(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus, 732 ): Byte 733 external fun uniffi_radroots_sdk_ffi_fn_func_parse_rhi_evidence_report(`canonicalContent`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 734 ): RustBuffer.ByValue 735 external fun uniffi_radroots_sdk_ffi_fn_func_parse_trade_evidence_manifest(`canonicalBytes`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 736 ): RustBuffer.ByValue 737 external fun uniffi_radroots_sdk_ffi_fn_func_prepare_rhi_evidence_attestation(`canonicalContent`: RustBuffer.ByValue,`createdAtUnixS`: Long,uniffi_out_err: UniffiRustCallStatus, 738 ): RustBuffer.ByValue 739 external fun uniffi_radroots_sdk_ffi_fn_func_validate_rhi_evidence_attestation(`event`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 740 ): RustBuffer.ByValue 741 external fun ffi_radroots_sdk_ffi_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus, 742 ): RustBuffer.ByValue 743 external fun ffi_radroots_sdk_ffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus, 744 ): RustBuffer.ByValue 745 external fun ffi_radroots_sdk_ffi_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, 746 ): Unit 747 external fun ffi_radroots_sdk_ffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus, 748 ): RustBuffer.ByValue 749 external fun ffi_radroots_sdk_ffi_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 750 ): Unit 751 external fun ffi_radroots_sdk_ffi_rust_future_cancel_u8(`handle`: Long, 752 ): Unit 753 external fun ffi_radroots_sdk_ffi_rust_future_free_u8(`handle`: Long, 754 ): Unit 755 external fun ffi_radroots_sdk_ffi_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 756 ): Int 757 external fun ffi_radroots_sdk_ffi_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 758 ): Unit 759 external fun ffi_radroots_sdk_ffi_rust_future_cancel_i8(`handle`: Long, 760 ): Unit 761 external fun ffi_radroots_sdk_ffi_rust_future_free_i8(`handle`: Long, 762 ): Unit 763 external fun ffi_radroots_sdk_ffi_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 764 ): Byte 765 external fun ffi_radroots_sdk_ffi_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 766 ): Unit 767 external fun ffi_radroots_sdk_ffi_rust_future_cancel_u16(`handle`: Long, 768 ): Unit 769 external fun ffi_radroots_sdk_ffi_rust_future_free_u16(`handle`: Long, 770 ): Unit 771 external fun ffi_radroots_sdk_ffi_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 772 ): Int 773 external fun ffi_radroots_sdk_ffi_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 774 ): Unit 775 external fun ffi_radroots_sdk_ffi_rust_future_cancel_i16(`handle`: Long, 776 ): Unit 777 external fun ffi_radroots_sdk_ffi_rust_future_free_i16(`handle`: Long, 778 ): Unit 779 external fun ffi_radroots_sdk_ffi_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 780 ): Short 781 external fun ffi_radroots_sdk_ffi_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 782 ): Unit 783 external fun ffi_radroots_sdk_ffi_rust_future_cancel_u32(`handle`: Long, 784 ): Unit 785 external fun ffi_radroots_sdk_ffi_rust_future_free_u32(`handle`: Long, 786 ): Unit 787 external fun ffi_radroots_sdk_ffi_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 788 ): Int 789 external fun ffi_radroots_sdk_ffi_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 790 ): Unit 791 external fun ffi_radroots_sdk_ffi_rust_future_cancel_i32(`handle`: Long, 792 ): Unit 793 external fun ffi_radroots_sdk_ffi_rust_future_free_i32(`handle`: Long, 794 ): Unit 795 external fun ffi_radroots_sdk_ffi_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 796 ): Int 797 external fun ffi_radroots_sdk_ffi_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 798 ): Unit 799 external fun ffi_radroots_sdk_ffi_rust_future_cancel_u64(`handle`: Long, 800 ): Unit 801 external fun ffi_radroots_sdk_ffi_rust_future_free_u64(`handle`: Long, 802 ): Unit 803 external fun ffi_radroots_sdk_ffi_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 804 ): Long 805 external fun ffi_radroots_sdk_ffi_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 806 ): Unit 807 external fun ffi_radroots_sdk_ffi_rust_future_cancel_i64(`handle`: Long, 808 ): Unit 809 external fun ffi_radroots_sdk_ffi_rust_future_free_i64(`handle`: Long, 810 ): Unit 811 external fun ffi_radroots_sdk_ffi_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 812 ): Long 813 external fun ffi_radroots_sdk_ffi_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 814 ): Unit 815 external fun ffi_radroots_sdk_ffi_rust_future_cancel_f32(`handle`: Long, 816 ): Unit 817 external fun ffi_radroots_sdk_ffi_rust_future_free_f32(`handle`: Long, 818 ): Unit 819 external fun ffi_radroots_sdk_ffi_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 820 ): Float 821 external fun ffi_radroots_sdk_ffi_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 822 ): Unit 823 external fun ffi_radroots_sdk_ffi_rust_future_cancel_f64(`handle`: Long, 824 ): Unit 825 external fun ffi_radroots_sdk_ffi_rust_future_free_f64(`handle`: Long, 826 ): Unit 827 external fun ffi_radroots_sdk_ffi_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 828 ): Double 829 external fun ffi_radroots_sdk_ffi_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 830 ): Unit 831 external fun ffi_radroots_sdk_ffi_rust_future_cancel_rust_buffer(`handle`: Long, 832 ): Unit 833 external fun ffi_radroots_sdk_ffi_rust_future_free_rust_buffer(`handle`: Long, 834 ): Unit 835 external fun ffi_radroots_sdk_ffi_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 836 ): RustBuffer.ByValue 837 external fun ffi_radroots_sdk_ffi_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, 838 ): Unit 839 external fun ffi_radroots_sdk_ffi_rust_future_cancel_void(`handle`: Long, 840 ): Unit 841 external fun ffi_radroots_sdk_ffi_rust_future_free_void(`handle`: Long, 842 ): Unit 843 external fun ffi_radroots_sdk_ffi_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, 844 ): Unit 845 846 847 } 848 849 private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) { 850 // Get the bindings contract version from our ComponentInterface 851 val bindings_contract_version = 30 852 // Get the scaffolding contract version by calling the into the dylib 853 val scaffolding_contract_version = lib.ffi_radroots_sdk_ffi_uniffi_contract_version() 854 if (bindings_contract_version != scaffolding_contract_version) { 855 throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project") 856 } 857 } 858 @Suppress("UNUSED_PARAMETER") 859 private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { 860 if ((lib.uniffi_radroots_sdk_ffi_checksum_func_parse_rhi_evidence_report() and 0xFFFF) != 10431) { 861 throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") 862 } 863 if ((lib.uniffi_radroots_sdk_ffi_checksum_func_parse_trade_evidence_manifest() and 0xFFFF) != 17039) { 864 throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") 865 } 866 if ((lib.uniffi_radroots_sdk_ffi_checksum_func_prepare_rhi_evidence_attestation() and 0xFFFF) != 35556) { 867 throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") 868 } 869 if ((lib.uniffi_radroots_sdk_ffi_checksum_func_validate_rhi_evidence_attestation() and 0xFFFF) != 64772) { 870 throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") 871 } 872 if ((lib.uniffi_radroots_sdk_ffi_checksum_method_mobileclient_capabilities() and 0xFFFF) != 35060) { 873 throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") 874 } 875 if ((lib.uniffi_radroots_sdk_ffi_checksum_method_mobileclient_close() and 0xFFFF) != 34026) { 876 throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") 877 } 878 if ((lib.uniffi_radroots_sdk_ffi_checksum_method_mobileclient_is_closed() and 0xFFFF) != 56426) { 879 throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") 880 } 881 if ((lib.uniffi_radroots_sdk_ffi_checksum_constructor_mobileclient_memory() and 0xFFFF) != 5837) { 882 throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") 883 } 884 } 885 886 /** 887 * @suppress 888 */ 889 public fun uniffiEnsureInitialized() { 890 // Call arbitrary methods on IntegrityCheckingUniffiLib and UniffiLib to ensure that 891 // their init blocks run. This ensures initialization across crates works as expected. 892 IntegrityCheckingUniffiLib.ensureInitialized() 893 UniffiLib.ensureInitialized() 894 } 895 896 // Async support 897 // Async return type handlers 898 899 internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toByte() 900 internal const val UNIFFI_RUST_FUTURE_POLL_WAKE = 1.toByte() 901 902 internal val uniffiContinuationHandleMap = UniffiHandleMap<CancellableContinuation<Byte>>() 903 904 // FFI type for Rust future continuations 905 internal object uniffiRustFutureContinuationCallbackImpl: UniffiRustFutureContinuationCallback { 906 override fun callback(data: Long, pollResult: Byte) { 907 uniffiContinuationHandleMap.remove(data).resume(pollResult) 908 } 909 } 910 911 internal suspend fun<T, F, E: kotlin.Exception> uniffiRustCallAsync( 912 rustFuture: Long, 913 pollFunc: (Long, UniffiRustFutureContinuationCallback, Long) -> Unit, 914 completeFunc: (Long, UniffiRustCallStatus) -> F, 915 freeFunc: (Long) -> Unit, 916 liftFunc: (F) -> T, 917 errorHandler: UniffiRustCallStatusErrorHandler<E> 918 ): T { 919 try { 920 do { 921 val pollResult = suspendCancellableCoroutine<Byte> { continuation -> 922 pollFunc( 923 rustFuture, 924 uniffiRustFutureContinuationCallbackImpl, 925 uniffiContinuationHandleMap.insert(continuation) 926 ) 927 } 928 } while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY); 929 930 return liftFunc( 931 uniffiRustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) }) 932 ) 933 } finally { 934 freeFunc(rustFuture) 935 } 936 } 937 938 // Public interface members begin here. 939 940 941 // Interface implemented by anything that can contain an object reference. 942 // 943 // Such types expose a `destroy()` method that must be called to cleanly 944 // dispose of the contained objects. Failure to call this method may result 945 // in memory leaks. 946 // 947 // The easiest way to ensure this method is called is to use the `.use` 948 // helper method to execute a block and destroy the object at the end. 949 interface Disposable { 950 fun destroy() 951 companion object { 952 fun destroy(vararg args: Any?) { 953 for (arg in args) { 954 when (arg) { 955 is Disposable -> arg.destroy() 956 is ArrayList<*> -> { 957 for (idx in arg.indices) { 958 val element = arg[idx] 959 if (element is Disposable) { 960 element.destroy() 961 } 962 } 963 } 964 is Map<*, *> -> { 965 for (element in arg.values) { 966 if (element is Disposable) { 967 element.destroy() 968 } 969 } 970 } 971 is Iterable<*> -> { 972 for (element in arg) { 973 if (element is Disposable) { 974 element.destroy() 975 } 976 } 977 } 978 } 979 } 980 } 981 } 982 } 983 984 /** 985 * @suppress 986 */ 987 inline fun <T : Disposable?, R> T.use(block: (T) -> R) = 988 try { 989 block(this) 990 } finally { 991 try { 992 // N.B. our implementation is on the nullable type `Disposable?`. 993 this?.destroy() 994 } catch (e: Throwable) { 995 // swallow 996 } 997 } 998 999 /** 1000 * Placeholder object used to signal that we're constructing an interface with a FFI handle. 1001 * 1002 * This is the first argument for interface constructors that input a raw handle. It exists is that 1003 * so we can avoid signature conflicts when an interface has a regular constructor than inputs a 1004 * Long. 1005 * 1006 * @suppress 1007 * */ 1008 object UniffiWithHandle 1009 1010 /** 1011 * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly. 1012 * 1013 * @suppress 1014 * */ 1015 object NoHandle 1016 /** 1017 * The cleaner interface for Object finalization code to run. 1018 * This is the entry point to any implementation that we're using. 1019 * 1020 * The cleaner registers objects and returns cleanables, so now we are 1021 * defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the 1022 * different implmentations available at compile time. 1023 * 1024 * @suppress 1025 */ 1026 interface UniffiCleaner { 1027 interface Cleanable { 1028 fun clean() 1029 } 1030 1031 fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable 1032 1033 companion object 1034 } 1035 1036 // The fallback Jna cleaner, which is available for both Android, and the JVM. 1037 private class UniffiJnaCleaner : UniffiCleaner { 1038 private val cleaner = com.sun.jna.internal.Cleaner.getCleaner() 1039 1040 override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable = 1041 UniffiJnaCleanable(cleaner.register(value, cleanUpTask)) 1042 } 1043 1044 private class UniffiJnaCleanable( 1045 private val cleanable: com.sun.jna.internal.Cleaner.Cleanable, 1046 ) : UniffiCleaner.Cleanable { 1047 override fun clean() = cleanable.clean() 1048 } 1049 1050 1051 // We decide at uniffi binding generation time whether we were 1052 // using Android or not. 1053 // There are further runtime checks to chose the correct implementation 1054 // of the cleaner. 1055 private fun UniffiCleaner.Companion.create(): UniffiCleaner = 1056 try { 1057 // For safety's sake: if the library hasn't been run in android_cleaner = true 1058 // mode, but is being run on Android, then we still need to think about 1059 // Android API versions. 1060 // So we check if java.lang.ref.Cleaner is there, and use that… 1061 java.lang.Class.forName("java.lang.ref.Cleaner") 1062 JavaLangRefCleaner() 1063 } catch (e: ClassNotFoundException) { 1064 // … otherwise, fallback to the JNA cleaner. 1065 UniffiJnaCleaner() 1066 } 1067 1068 private class JavaLangRefCleaner : UniffiCleaner { 1069 val cleaner = java.lang.ref.Cleaner.create() 1070 1071 override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable = 1072 JavaLangRefCleanable(cleaner.register(value, cleanUpTask)) 1073 } 1074 1075 private class JavaLangRefCleanable( 1076 val cleanable: java.lang.ref.Cleaner.Cleanable 1077 ) : UniffiCleaner.Cleanable { 1078 override fun clean() = cleanable.clean() 1079 } 1080 1081 /** 1082 * @suppress 1083 */ 1084 public object FfiConverterUShort: FfiConverter<UShort, Short> { 1085 override fun lift(value: Short): UShort { 1086 return value.toUShort() 1087 } 1088 1089 fun lift(value: Int): UShort { 1090 return value.toUShort() 1091 } 1092 1093 override fun read(buf: ByteBuffer): UShort { 1094 return lift(buf.getShort()) 1095 } 1096 1097 override fun lower(value: UShort): Short { 1098 return value.toShort() 1099 } 1100 1101 override fun allocationSize(value: UShort) = 2UL 1102 1103 override fun write(value: UShort, buf: ByteBuffer) { 1104 buf.putShort(value.toShort()) 1105 } 1106 } 1107 1108 /** 1109 * @suppress 1110 */ 1111 public object FfiConverterUInt: FfiConverter<UInt, Int> { 1112 override fun lift(value: Int): UInt { 1113 return value.toUInt() 1114 } 1115 1116 override fun read(buf: ByteBuffer): UInt { 1117 return lift(buf.getInt()) 1118 } 1119 1120 override fun lower(value: UInt): Int { 1121 return value.toInt() 1122 } 1123 1124 override fun allocationSize(value: UInt) = 4UL 1125 1126 override fun write(value: UInt, buf: ByteBuffer) { 1127 buf.putInt(value.toInt()) 1128 } 1129 } 1130 1131 /** 1132 * @suppress 1133 */ 1134 public object FfiConverterULong: FfiConverter<ULong, Long> { 1135 override fun lift(value: Long): ULong { 1136 return value.toULong() 1137 } 1138 1139 override fun read(buf: ByteBuffer): ULong { 1140 return lift(buf.getLong()) 1141 } 1142 1143 override fun lower(value: ULong): Long { 1144 return value.toLong() 1145 } 1146 1147 override fun allocationSize(value: ULong) = 8UL 1148 1149 override fun write(value: ULong, buf: ByteBuffer) { 1150 buf.putLong(value.toLong()) 1151 } 1152 } 1153 1154 /** 1155 * @suppress 1156 */ 1157 public object FfiConverterBoolean: FfiConverter<Boolean, Byte> { 1158 override fun lift(value: Byte): Boolean { 1159 return value.toInt() != 0 1160 } 1161 1162 override fun read(buf: ByteBuffer): Boolean { 1163 return lift(buf.get()) 1164 } 1165 1166 override fun lower(value: Boolean): Byte { 1167 return if (value) 1.toByte() else 0.toByte() 1168 } 1169 1170 override fun allocationSize(value: Boolean) = 1UL 1171 1172 override fun write(value: Boolean, buf: ByteBuffer) { 1173 buf.put(lower(value)) 1174 } 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 handle 1255 // to the live Rust struct on the other side of the FFI. 1256 // 1257 // There's some subtlety here, because we have to be careful not to operate on a Rust 1258 // struct after it has been dropped, and because we must expose a public API for freeing 1259 // theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: 1260 // 1261 // * Each instance holds an opaque handle to the underlying Rust struct. 1262 // Method calls need to read this handle from the object's state and pass it in to 1263 // the Rust FFI. 1264 // 1265 // * When an instance is no longer needed, its handle should be passed to a 1266 // special destructor function provided by the Rust FFI, which will drop the 1267 // underlying Rust struct. 1268 // 1269 // * Given an instance, calling code is expected to call the special 1270 // `destroy` method in order to free it after use, either by calling it explicitly 1271 // or by using a higher-level helper like the `use` method. Failing to do so risks 1272 // leaking the underlying Rust struct. 1273 // 1274 // * We can't assume that calling code will do the right thing, and must be prepared 1275 // to handle Kotlin method calls executing concurrently with or even after a call to 1276 // `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. 1277 // 1278 // * We must never allow Rust code to operate on the underlying Rust struct after 1279 // the destructor has been called, and must never call the destructor more than once. 1280 // Doing so may trigger memory unsafety. 1281 // 1282 // * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` 1283 // is implemented to call the destructor when the Kotlin object becomes unreachable. 1284 // This is done in a background thread. This is not a panacea, and client code should be aware that 1285 // 1. the thread may starve if some there are objects that have poorly performing 1286 // `drop` methods or do significant work in their `drop` methods. 1287 // 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, 1288 // or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). 1289 // 1290 // If we try to implement this with mutual exclusion on access to the handle, there is the 1291 // possibility of a race between a method call and a concurrent call to `destroy`: 1292 // 1293 // * Thread A starts a method call, reads the value of the handle, but is interrupted 1294 // before it can pass the handle over the FFI to Rust. 1295 // * Thread B calls `destroy` and frees the underlying Rust struct. 1296 // * Thread A resumes, passing the already-read handle value to Rust and triggering 1297 // a use-after-free. 1298 // 1299 // One possible solution would be to use a `ReadWriteLock`, with each method call taking 1300 // a read lock (and thus allowed to run concurrently) and the special `destroy` method 1301 // taking a write lock (and thus blocking on live method calls). However, we aim not to 1302 // generate methods with any hidden blocking semantics, and a `destroy` method that might 1303 // block if called incorrectly seems to meet that bar. 1304 // 1305 // So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track 1306 // the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` 1307 // has been called. These are updated according to the following rules: 1308 // 1309 // * The initial value of the counter is 1, indicating a live object with no in-flight calls. 1310 // The initial value for the flag is false. 1311 // 1312 // * At the start of each method call, we atomically check the counter. 1313 // If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. 1314 // If it is nonzero them we atomically increment it by 1 and proceed with the method call. 1315 // 1316 // * At the end of each method call, we atomically decrement and check the counter. 1317 // If it has reached zero then we destroy the underlying Rust struct. 1318 // 1319 // * When `destroy` is called, we atomically flip the flag from false to true. 1320 // If the flag was already true we silently fail. 1321 // Otherwise we atomically decrement and check the counter. 1322 // If it has reached zero then we destroy the underlying Rust struct. 1323 // 1324 // Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works, 1325 // and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. 1326 // 1327 // The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been 1328 // called *and* all in-flight method calls have completed, avoiding violating any of the expectations 1329 // of the underlying Rust code. 1330 // 1331 // This makes a cleaner a better alternative to _not_ calling `destroy()` as 1332 // and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` 1333 // method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner 1334 // thread may be starved, and the app will leak memory. 1335 // 1336 // In this case, `destroy`ing manually may be a better solution. 1337 // 1338 // The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects 1339 // with Rust peers are reclaimed: 1340 // 1341 // 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: 1342 // 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: 1343 // 3. The memory is reclaimed when the process terminates. 1344 // 1345 // [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 1346 // 1347 1348 1349 /** 1350 * Thread-safe mobile handle delegating lifecycle to [`radroots_sdk::Client`]. 1351 */ 1352 public interface MobileClientInterface { 1353 1354 /** 1355 * Returns stable capability DTOs without probing host resources. 1356 */ 1357 fun `capabilities`(): List<CapabilityStatus> 1358 1359 /** 1360 * Explicitly closes SDK-owned resources without installing a runtime. 1361 */ 1362 suspend fun `close`() 1363 1364 /** 1365 * Returns whether explicit SDK close completed across all clones. 1366 */ 1367 fun `isClosed`(): kotlin.Boolean 1368 1369 companion object 1370 } 1371 1372 /** 1373 * Thread-safe mobile handle delegating lifecycle to [`radroots_sdk::Client`]. 1374 */ 1375 open class MobileClient: Disposable, MobileClientInterface 1376 { 1377 1378 @Suppress("UNUSED_PARAMETER") 1379 /** 1380 * @suppress 1381 */ 1382 constructor(withHandle: UniffiWithHandle, handle: Long) { 1383 this.handle = handle 1384 this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle)) 1385 } 1386 1387 /** 1388 * @suppress 1389 * 1390 * This constructor can be used to instantiate a fake object. Only used for tests. Any 1391 * attempt to actually use an object constructed this way will fail as there is no 1392 * connected Rust object. 1393 */ 1394 @Suppress("UNUSED_PARAMETER") 1395 constructor(noHandle: NoHandle) { 1396 this.handle = 0 1397 this.cleanable = null 1398 } 1399 1400 protected val handle: Long 1401 protected val cleanable: UniffiCleaner.Cleanable? 1402 1403 private val wasDestroyed = AtomicBoolean(false) 1404 private val callCounter = AtomicLong(1) 1405 1406 /** 1407 * Whether the current object has been destroyed and its reference is gone in the Rust side. 1408 */ 1409 val uniffiIsDestroyed: Boolean get() = wasDestroyed.get() 1410 1411 override fun destroy() { 1412 // Only allow a single call to this method. 1413 // TODO: maybe we should log a warning if called more than once? 1414 if (this.wasDestroyed.compareAndSet(false, true)) { 1415 // This decrement always matches the initial count of 1 given at creation time. 1416 if (this.callCounter.decrementAndGet() == 0L) { 1417 cleanable?.clean() 1418 } 1419 } 1420 } 1421 1422 1423 internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R { 1424 // Check and increment the call counter, to keep the object alive. 1425 // This needs a compare-and-set retry loop in case of concurrent updates. 1426 do { 1427 val c = this.callCounter.get() 1428 if (c == 0L) { 1429 throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") 1430 } 1431 if (c == Long.MAX_VALUE) { 1432 throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") 1433 } 1434 } while (! this.callCounter.compareAndSet(c, c + 1L)) 1435 // Now we can safely do the method call without the handle being freed concurrently. 1436 try { 1437 return block(this.uniffiCloneHandle()) 1438 } finally { 1439 // This decrement always matches the increment we performed above. 1440 if (this.callCounter.decrementAndGet() == 0L) { 1441 cleanable?.clean() 1442 } 1443 } 1444 } 1445 1446 // Use a static inner class instead of a closure so as not to accidentally 1447 // capture `this` as part of the cleanable's action. 1448 private class UniffiCleanAction(private val handle: Long) : Runnable { 1449 override fun run() { 1450 if (handle == 0.toLong()) { 1451 // Fake object created with `NoHandle`, don't try to free. 1452 return; 1453 } 1454 uniffiRustCall { status -> 1455 UniffiLib.uniffi_radroots_sdk_ffi_fn_free_mobileclient(handle, status) 1456 } 1457 } 1458 } 1459 1460 /** 1461 * @suppress 1462 */ 1463 fun uniffiCloneHandle(): Long { 1464 if (handle == 0.toLong()) { 1465 throw InternalException("uniffiCloneHandle() called on NoHandle object"); 1466 } 1467 return uniffiRustCall() { status -> 1468 UniffiLib.uniffi_radroots_sdk_ffi_fn_clone_mobileclient(handle, status) 1469 } 1470 } 1471 1472 1473 /** 1474 * Returns stable capability DTOs without probing host resources. 1475 */override fun `capabilities`(): List<CapabilityStatus> { 1476 return FfiConverterSequenceTypeCapabilityStatus.lift( 1477 callWithHandle { 1478 uniffiRustCall() { _status -> 1479 UniffiLib.uniffi_radroots_sdk_ffi_fn_method_mobileclient_capabilities( 1480 it, 1481 _status) 1482 } 1483 } 1484 ) 1485 } 1486 1487 1488 1489 /** 1490 * Explicitly closes SDK-owned resources without installing a runtime. 1491 */ 1492 @Throws(Exception::class) 1493 @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") 1494 override suspend fun `close`() { 1495 return uniffiRustCallAsync( 1496 callWithHandle { uniffiHandle -> 1497 UniffiLib.uniffi_radroots_sdk_ffi_fn_method_mobileclient_close( 1498 uniffiHandle, 1499 1500 ) 1501 }, 1502 { future, callback, continuation -> UniffiLib.ffi_radroots_sdk_ffi_rust_future_poll_void(future, callback, continuation) }, 1503 { future, continuation -> UniffiLib.ffi_radroots_sdk_ffi_rust_future_complete_void(future, continuation) }, 1504 { future -> UniffiLib.ffi_radroots_sdk_ffi_rust_future_free_void(future) }, 1505 // lift function 1506 { }, 1507 1508 // Error FFI converter 1509 Exception.ErrorHandler, 1510 ) 1511 } 1512 1513 1514 /** 1515 * Returns whether explicit SDK close completed across all clones. 1516 */override fun `isClosed`(): kotlin.Boolean { 1517 return FfiConverterBoolean.lift( 1518 callWithHandle { 1519 uniffiRustCall() { _status -> 1520 UniffiLib.uniffi_radroots_sdk_ffi_fn_method_mobileclient_is_closed( 1521 it, 1522 _status) 1523 } 1524 } 1525 ) 1526 } 1527 1528 1529 1530 1531 1532 1533 1534 1535 companion object { 1536 1537 /** 1538 * Creates a deterministic, local-only memory client without I/O. 1539 */ 1540 @Throws(Exception::class) fun `memory`(): MobileClient { 1541 return FfiConverterTypeMobileClient.lift( 1542 uniffiRustCallWithError(Exception) { _status -> 1543 UniffiLib.uniffi_radroots_sdk_ffi_fn_constructor_mobileclient_memory( 1544 1545 _status) 1546 } 1547 ) 1548 } 1549 1550 1551 1552 } 1553 1554 } 1555 1556 1557 /** 1558 * @suppress 1559 */ 1560 public object FfiConverterTypeMobileClient: FfiConverter<MobileClient, Long> { 1561 override fun lower(value: MobileClient): Long { 1562 return value.uniffiCloneHandle() 1563 } 1564 1565 override fun lift(value: Long): MobileClient { 1566 return MobileClient(UniffiWithHandle, value) 1567 } 1568 1569 override fun read(buf: ByteBuffer): MobileClient { 1570 return lift(buf.getLong()) 1571 } 1572 1573 override fun allocationSize(value: MobileClient) = 8UL 1574 1575 override fun write(value: MobileClient, buf: ByteBuffer) { 1576 buf.putLong(lower(value)) 1577 } 1578 } 1579 1580 1581 1582 /** 1583 * Versioned, presentation-independent capability observation. 1584 */ 1585 data class CapabilityStatus ( 1586 var `id`: kotlin.String 1587 , 1588 var `compiled`: kotlin.Boolean 1589 , 1590 var `configured`: kotlin.Boolean 1591 , 1592 var `availability`: CapabilityAvailability 1593 , 1594 var `maturity`: CapabilityMaturity 1595 1596 ){ 1597 1598 1599 1600 1601 1602 companion object 1603 } 1604 1605 /** 1606 * @suppress 1607 */ 1608 public object FfiConverterTypeCapabilityStatus: FfiConverterRustBuffer<CapabilityStatus> { 1609 override fun read(buf: ByteBuffer): CapabilityStatus { 1610 return CapabilityStatus( 1611 FfiConverterString.read(buf), 1612 FfiConverterBoolean.read(buf), 1613 FfiConverterBoolean.read(buf), 1614 FfiConverterTypeCapabilityAvailability.read(buf), 1615 FfiConverterTypeCapabilityMaturity.read(buf), 1616 ) 1617 } 1618 1619 override fun allocationSize(value: CapabilityStatus) = ( 1620 FfiConverterString.allocationSize(value.`id`) + 1621 FfiConverterBoolean.allocationSize(value.`compiled`) + 1622 FfiConverterBoolean.allocationSize(value.`configured`) + 1623 FfiConverterTypeCapabilityAvailability.allocationSize(value.`availability`) + 1624 FfiConverterTypeCapabilityMaturity.allocationSize(value.`maturity`) 1625 ) 1626 1627 override fun write(value: CapabilityStatus, buf: ByteBuffer) { 1628 FfiConverterString.write(value.`id`, buf) 1629 FfiConverterBoolean.write(value.`compiled`, buf) 1630 FfiConverterBoolean.write(value.`configured`, buf) 1631 FfiConverterTypeCapabilityAvailability.write(value.`availability`, buf) 1632 FfiConverterTypeCapabilityMaturity.write(value.`maturity`, buf) 1633 } 1634 } 1635 1636 1637 1638 /** 1639 * Verified final RHI attestation projection. 1640 */ 1641 data class RhiEvidenceAttestation ( 1642 var `issuerPubkey`: kotlin.String 1643 , 1644 var `tradeId`: kotlin.String 1645 , 1646 var `claimMutationId`: kotlin.String 1647 , 1648 var `outcome`: TradeEvidenceOutcome 1649 , 1650 var `observedAtUnixS`: kotlin.String 1651 , 1652 var `tradeGeneration`: kotlin.String 1653 , 1654 var `statementDigest`: kotlin.String 1655 , 1656 var `supersession`: RhiEvidenceSupersession? 1657 , 1658 var `canonicalContent`: kotlin.String 1659 1660 ){ 1661 1662 1663 1664 1665 1666 companion object 1667 } 1668 1669 /** 1670 * @suppress 1671 */ 1672 public object FfiConverterTypeRhiEvidenceAttestation: FfiConverterRustBuffer<RhiEvidenceAttestation> { 1673 override fun read(buf: ByteBuffer): RhiEvidenceAttestation { 1674 return RhiEvidenceAttestation( 1675 FfiConverterString.read(buf), 1676 FfiConverterString.read(buf), 1677 FfiConverterString.read(buf), 1678 FfiConverterTypeTradeEvidenceOutcome.read(buf), 1679 FfiConverterString.read(buf), 1680 FfiConverterString.read(buf), 1681 FfiConverterString.read(buf), 1682 FfiConverterOptionalTypeRhiEvidenceSupersession.read(buf), 1683 FfiConverterString.read(buf), 1684 ) 1685 } 1686 1687 override fun allocationSize(value: RhiEvidenceAttestation) = ( 1688 FfiConverterString.allocationSize(value.`issuerPubkey`) + 1689 FfiConverterString.allocationSize(value.`tradeId`) + 1690 FfiConverterString.allocationSize(value.`claimMutationId`) + 1691 FfiConverterTypeTradeEvidenceOutcome.allocationSize(value.`outcome`) + 1692 FfiConverterString.allocationSize(value.`observedAtUnixS`) + 1693 FfiConverterString.allocationSize(value.`tradeGeneration`) + 1694 FfiConverterString.allocationSize(value.`statementDigest`) + 1695 FfiConverterOptionalTypeRhiEvidenceSupersession.allocationSize(value.`supersession`) + 1696 FfiConverterString.allocationSize(value.`canonicalContent`) 1697 ) 1698 1699 override fun write(value: RhiEvidenceAttestation, buf: ByteBuffer) { 1700 FfiConverterString.write(value.`issuerPubkey`, buf) 1701 FfiConverterString.write(value.`tradeId`, buf) 1702 FfiConverterString.write(value.`claimMutationId`, buf) 1703 FfiConverterTypeTradeEvidenceOutcome.write(value.`outcome`, buf) 1704 FfiConverterString.write(value.`observedAtUnixS`, buf) 1705 FfiConverterString.write(value.`tradeGeneration`, buf) 1706 FfiConverterString.write(value.`statementDigest`, buf) 1707 FfiConverterOptionalTypeRhiEvidenceSupersession.write(value.`supersession`, buf) 1708 FfiConverterString.write(value.`canonicalContent`, buf) 1709 } 1710 } 1711 1712 1713 1714 /** 1715 * Bounded projection of one canonical RHI evidence report. 1716 */ 1717 data class RhiEvidenceReport ( 1718 var `contractId`: kotlin.String 1719 , 1720 var `contractVersion`: kotlin.UShort 1721 , 1722 var `issuerPubkey`: kotlin.String 1723 , 1724 var `tradeId`: kotlin.String 1725 , 1726 var `claimMutationId`: kotlin.String 1727 , 1728 var `outcome`: TradeEvidenceOutcome 1729 , 1730 var `reasonCodes`: List<kotlin.String> 1731 , 1732 var `projectionDigest`: kotlin.String 1733 , 1734 var `evidenceManifestDigest`: kotlin.String 1735 , 1736 var `evidencePolicyDigest`: kotlin.String 1737 , 1738 var `observedAtUnixS`: kotlin.String 1739 , 1740 var `tradeGeneration`: kotlin.String 1741 , 1742 var `statementDigest`: kotlin.String 1743 , 1744 var `supersession`: RhiEvidenceSupersession? 1745 , 1746 var `canonicalContent`: kotlin.String 1747 1748 ){ 1749 1750 1751 1752 1753 1754 companion object 1755 } 1756 1757 /** 1758 * @suppress 1759 */ 1760 public object FfiConverterTypeRhiEvidenceReport: FfiConverterRustBuffer<RhiEvidenceReport> { 1761 override fun read(buf: ByteBuffer): RhiEvidenceReport { 1762 return RhiEvidenceReport( 1763 FfiConverterString.read(buf), 1764 FfiConverterUShort.read(buf), 1765 FfiConverterString.read(buf), 1766 FfiConverterString.read(buf), 1767 FfiConverterString.read(buf), 1768 FfiConverterTypeTradeEvidenceOutcome.read(buf), 1769 FfiConverterSequenceString.read(buf), 1770 FfiConverterString.read(buf), 1771 FfiConverterString.read(buf), 1772 FfiConverterString.read(buf), 1773 FfiConverterString.read(buf), 1774 FfiConverterString.read(buf), 1775 FfiConverterString.read(buf), 1776 FfiConverterOptionalTypeRhiEvidenceSupersession.read(buf), 1777 FfiConverterString.read(buf), 1778 ) 1779 } 1780 1781 override fun allocationSize(value: RhiEvidenceReport) = ( 1782 FfiConverterString.allocationSize(value.`contractId`) + 1783 FfiConverterUShort.allocationSize(value.`contractVersion`) + 1784 FfiConverterString.allocationSize(value.`issuerPubkey`) + 1785 FfiConverterString.allocationSize(value.`tradeId`) + 1786 FfiConverterString.allocationSize(value.`claimMutationId`) + 1787 FfiConverterTypeTradeEvidenceOutcome.allocationSize(value.`outcome`) + 1788 FfiConverterSequenceString.allocationSize(value.`reasonCodes`) + 1789 FfiConverterString.allocationSize(value.`projectionDigest`) + 1790 FfiConverterString.allocationSize(value.`evidenceManifestDigest`) + 1791 FfiConverterString.allocationSize(value.`evidencePolicyDigest`) + 1792 FfiConverterString.allocationSize(value.`observedAtUnixS`) + 1793 FfiConverterString.allocationSize(value.`tradeGeneration`) + 1794 FfiConverterString.allocationSize(value.`statementDigest`) + 1795 FfiConverterOptionalTypeRhiEvidenceSupersession.allocationSize(value.`supersession`) + 1796 FfiConverterString.allocationSize(value.`canonicalContent`) 1797 ) 1798 1799 override fun write(value: RhiEvidenceReport, buf: ByteBuffer) { 1800 FfiConverterString.write(value.`contractId`, buf) 1801 FfiConverterUShort.write(value.`contractVersion`, buf) 1802 FfiConverterString.write(value.`issuerPubkey`, buf) 1803 FfiConverterString.write(value.`tradeId`, buf) 1804 FfiConverterString.write(value.`claimMutationId`, buf) 1805 FfiConverterTypeTradeEvidenceOutcome.write(value.`outcome`, buf) 1806 FfiConverterSequenceString.write(value.`reasonCodes`, buf) 1807 FfiConverterString.write(value.`projectionDigest`, buf) 1808 FfiConverterString.write(value.`evidenceManifestDigest`, buf) 1809 FfiConverterString.write(value.`evidencePolicyDigest`, buf) 1810 FfiConverterString.write(value.`observedAtUnixS`, buf) 1811 FfiConverterString.write(value.`tradeGeneration`, buf) 1812 FfiConverterString.write(value.`statementDigest`, buf) 1813 FfiConverterOptionalTypeRhiEvidenceSupersession.write(value.`supersession`, buf) 1814 FfiConverterString.write(value.`canonicalContent`, buf) 1815 } 1816 } 1817 1818 1819 1820 /** 1821 * Exact immutable RHI supersession reference. 1822 */ 1823 data class RhiEvidenceSupersession ( 1824 var `reportId`: kotlin.String 1825 , 1826 var `eventId`: kotlin.String 1827 1828 ){ 1829 1830 1831 1832 1833 1834 companion object 1835 } 1836 1837 /** 1838 * @suppress 1839 */ 1840 public object FfiConverterTypeRhiEvidenceSupersession: FfiConverterRustBuffer<RhiEvidenceSupersession> { 1841 override fun read(buf: ByteBuffer): RhiEvidenceSupersession { 1842 return RhiEvidenceSupersession( 1843 FfiConverterString.read(buf), 1844 FfiConverterString.read(buf), 1845 ) 1846 } 1847 1848 override fun allocationSize(value: RhiEvidenceSupersession) = ( 1849 FfiConverterString.allocationSize(value.`reportId`) + 1850 FfiConverterString.allocationSize(value.`eventId`) 1851 ) 1852 1853 override fun write(value: RhiEvidenceSupersession, buf: ByteBuffer) { 1854 FfiConverterString.write(value.`reportId`, buf) 1855 FfiConverterString.write(value.`eventId`, buf) 1856 } 1857 } 1858 1859 1860 1861 /** 1862 * Signed NIP-01 event input for verified attestation admission. 1863 */ 1864 data class SignedEvent ( 1865 var `id`: kotlin.String 1866 , 1867 var `authorPubkey`: kotlin.String 1868 , 1869 var `createdAtUnixS`: kotlin.ULong 1870 , 1871 var `kind`: kotlin.UInt 1872 , 1873 var `tags`: List<List<kotlin.String>> 1874 , 1875 var `content`: kotlin.String 1876 , 1877 var `signature`: kotlin.String 1878 1879 ){ 1880 1881 1882 1883 1884 1885 companion object 1886 } 1887 1888 /** 1889 * @suppress 1890 */ 1891 public object FfiConverterTypeSignedEvent: FfiConverterRustBuffer<SignedEvent> { 1892 override fun read(buf: ByteBuffer): SignedEvent { 1893 return SignedEvent( 1894 FfiConverterString.read(buf), 1895 FfiConverterString.read(buf), 1896 FfiConverterULong.read(buf), 1897 FfiConverterUInt.read(buf), 1898 FfiConverterSequenceSequenceString.read(buf), 1899 FfiConverterString.read(buf), 1900 FfiConverterString.read(buf), 1901 ) 1902 } 1903 1904 override fun allocationSize(value: SignedEvent) = ( 1905 FfiConverterString.allocationSize(value.`id`) + 1906 FfiConverterString.allocationSize(value.`authorPubkey`) + 1907 FfiConverterULong.allocationSize(value.`createdAtUnixS`) + 1908 FfiConverterUInt.allocationSize(value.`kind`) + 1909 FfiConverterSequenceSequenceString.allocationSize(value.`tags`) + 1910 FfiConverterString.allocationSize(value.`content`) + 1911 FfiConverterString.allocationSize(value.`signature`) 1912 ) 1913 1914 override fun write(value: SignedEvent, buf: ByteBuffer) { 1915 FfiConverterString.write(value.`id`, buf) 1916 FfiConverterString.write(value.`authorPubkey`, buf) 1917 FfiConverterULong.write(value.`createdAtUnixS`, buf) 1918 FfiConverterUInt.write(value.`kind`, buf) 1919 FfiConverterSequenceSequenceString.write(value.`tags`, buf) 1920 FfiConverterString.write(value.`content`, buf) 1921 FfiConverterString.write(value.`signature`, buf) 1922 } 1923 } 1924 1925 1926 1927 /** 1928 * Bounded projection of one canonical evidence manifest. 1929 */ 1930 data class TradeEvidenceManifest ( 1931 var `contractId`: kotlin.String 1932 , 1933 var `contractVersion`: kotlin.UShort 1934 , 1935 var `tradeId`: kotlin.String 1936 , 1937 var `tradeGeneration`: kotlin.String 1938 , 1939 var `observedAtUnixS`: kotlin.String 1940 , 1941 var `coverage`: TradeEvidenceCoverage 1942 , 1943 var `evidencePolicyDigest`: kotlin.String 1944 , 1945 var `manifestDigest`: kotlin.String 1946 , 1947 var `canonicalBytesHex`: kotlin.String 1948 1949 ){ 1950 1951 1952 1953 1954 1955 companion object 1956 } 1957 1958 /** 1959 * @suppress 1960 */ 1961 public object FfiConverterTypeTradeEvidenceManifest: FfiConverterRustBuffer<TradeEvidenceManifest> { 1962 override fun read(buf: ByteBuffer): TradeEvidenceManifest { 1963 return TradeEvidenceManifest( 1964 FfiConverterString.read(buf), 1965 FfiConverterUShort.read(buf), 1966 FfiConverterString.read(buf), 1967 FfiConverterString.read(buf), 1968 FfiConverterString.read(buf), 1969 FfiConverterTypeTradeEvidenceCoverage.read(buf), 1970 FfiConverterString.read(buf), 1971 FfiConverterString.read(buf), 1972 FfiConverterString.read(buf), 1973 ) 1974 } 1975 1976 override fun allocationSize(value: TradeEvidenceManifest) = ( 1977 FfiConverterString.allocationSize(value.`contractId`) + 1978 FfiConverterUShort.allocationSize(value.`contractVersion`) + 1979 FfiConverterString.allocationSize(value.`tradeId`) + 1980 FfiConverterString.allocationSize(value.`tradeGeneration`) + 1981 FfiConverterString.allocationSize(value.`observedAtUnixS`) + 1982 FfiConverterTypeTradeEvidenceCoverage.allocationSize(value.`coverage`) + 1983 FfiConverterString.allocationSize(value.`evidencePolicyDigest`) + 1984 FfiConverterString.allocationSize(value.`manifestDigest`) + 1985 FfiConverterString.allocationSize(value.`canonicalBytesHex`) 1986 ) 1987 1988 override fun write(value: TradeEvidenceManifest, buf: ByteBuffer) { 1989 FfiConverterString.write(value.`contractId`, buf) 1990 FfiConverterUShort.write(value.`contractVersion`, buf) 1991 FfiConverterString.write(value.`tradeId`, buf) 1992 FfiConverterString.write(value.`tradeGeneration`, buf) 1993 FfiConverterString.write(value.`observedAtUnixS`, buf) 1994 FfiConverterTypeTradeEvidenceCoverage.write(value.`coverage`, buf) 1995 FfiConverterString.write(value.`evidencePolicyDigest`, buf) 1996 FfiConverterString.write(value.`manifestDigest`, buf) 1997 FfiConverterString.write(value.`canonicalBytesHex`, buf) 1998 } 1999 } 2000 2001 2002 2003 /** 2004 * One unsigned typed event plan ready for host-owned signing. 2005 */ 2006 data class TypedEvidenceEventPlan ( 2007 var `contractId`: kotlin.String 2008 , 2009 var `kind`: kotlin.UInt 2010 , 2011 var `authorPubkey`: kotlin.String 2012 , 2013 var `createdAtUnixS`: kotlin.String 2014 , 2015 var `expectedEventId`: kotlin.String 2016 , 2017 var `tags`: List<List<kotlin.String>> 2018 , 2019 var `content`: kotlin.String 2020 2021 ){ 2022 2023 2024 2025 2026 2027 companion object 2028 } 2029 2030 /** 2031 * @suppress 2032 */ 2033 public object FfiConverterTypeTypedEvidenceEventPlan: FfiConverterRustBuffer<TypedEvidenceEventPlan> { 2034 override fun read(buf: ByteBuffer): TypedEvidenceEventPlan { 2035 return TypedEvidenceEventPlan( 2036 FfiConverterString.read(buf), 2037 FfiConverterUInt.read(buf), 2038 FfiConverterString.read(buf), 2039 FfiConverterString.read(buf), 2040 FfiConverterString.read(buf), 2041 FfiConverterSequenceSequenceString.read(buf), 2042 FfiConverterString.read(buf), 2043 ) 2044 } 2045 2046 override fun allocationSize(value: TypedEvidenceEventPlan) = ( 2047 FfiConverterString.allocationSize(value.`contractId`) + 2048 FfiConverterUInt.allocationSize(value.`kind`) + 2049 FfiConverterString.allocationSize(value.`authorPubkey`) + 2050 FfiConverterString.allocationSize(value.`createdAtUnixS`) + 2051 FfiConverterString.allocationSize(value.`expectedEventId`) + 2052 FfiConverterSequenceSequenceString.allocationSize(value.`tags`) + 2053 FfiConverterString.allocationSize(value.`content`) 2054 ) 2055 2056 override fun write(value: TypedEvidenceEventPlan, buf: ByteBuffer) { 2057 FfiConverterString.write(value.`contractId`, buf) 2058 FfiConverterUInt.write(value.`kind`, buf) 2059 FfiConverterString.write(value.`authorPubkey`, buf) 2060 FfiConverterString.write(value.`createdAtUnixS`, buf) 2061 FfiConverterString.write(value.`expectedEventId`, buf) 2062 FfiConverterSequenceSequenceString.write(value.`tags`, buf) 2063 FfiConverterString.write(value.`content`, buf) 2064 } 2065 } 2066 2067 2068 2069 /** 2070 * Current side-effect-free capability availability. 2071 */ 2072 2073 enum class CapabilityAvailability { 2074 2075 AVAILABLE, 2076 DEGRADED, 2077 UNAVAILABLE, 2078 UNSUPPORTED; 2079 2080 2081 2082 2083 companion object 2084 } 2085 2086 2087 /** 2088 * @suppress 2089 */ 2090 public object FfiConverterTypeCapabilityAvailability: FfiConverterRustBuffer<CapabilityAvailability> { 2091 override fun read(buf: ByteBuffer) = try { 2092 CapabilityAvailability.values()[buf.getInt() - 1] 2093 } catch (e: IndexOutOfBoundsException) { 2094 throw RuntimeException("invalid enum value, something is very wrong!!", e) 2095 } 2096 2097 override fun allocationSize(value: CapabilityAvailability) = 4UL 2098 2099 override fun write(value: CapabilityAvailability, buf: ByteBuffer) { 2100 buf.putInt(value.ordinal + 1) 2101 } 2102 } 2103 2104 2105 2106 2107 2108 /** 2109 * Stable capability maturity independent of runtime availability. 2110 */ 2111 2112 enum class CapabilityMaturity { 2113 2114 STABLE, 2115 PREVIEW, 2116 EXPERIMENTAL; 2117 2118 2119 2120 2121 companion object 2122 } 2123 2124 2125 /** 2126 * @suppress 2127 */ 2128 public object FfiConverterTypeCapabilityMaturity: FfiConverterRustBuffer<CapabilityMaturity> { 2129 override fun read(buf: ByteBuffer) = try { 2130 CapabilityMaturity.values()[buf.getInt() - 1] 2131 } catch (e: IndexOutOfBoundsException) { 2132 throw RuntimeException("invalid enum value, something is very wrong!!", e) 2133 } 2134 2135 override fun allocationSize(value: CapabilityMaturity) = 4UL 2136 2137 override fun write(value: CapabilityMaturity, buf: ByteBuffer) { 2138 buf.putInt(value.ordinal + 1) 2139 } 2140 } 2141 2142 2143 2144 2145 2146 2147 2148 /** 2149 * Secret-safe SDK failure at the language boundary. 2150 */ 2151 sealed class Exception: kotlin.Exception() { 2152 2153 class Sdk( 2154 2155 val `code`: kotlin.String, 2156 2157 override val `message`: kotlin.String, 2158 2159 val `retryable`: kotlin.Boolean 2160 ) : Exception() { 2161 2162 } 2163 2164 2165 2166 2167 2168 companion object ErrorHandler : UniffiRustCallStatusErrorHandler<Exception> { 2169 override fun lift(error_buf: RustBuffer.ByValue): Exception = FfiConverterTypeError.lift(error_buf) 2170 } 2171 2172 2173 } 2174 2175 /** 2176 * @suppress 2177 */ 2178 public object FfiConverterTypeError : FfiConverterRustBuffer<Exception> { 2179 override fun read(buf: ByteBuffer): Exception { 2180 2181 2182 return when(buf.getInt()) { 2183 1 -> Exception.Sdk( 2184 FfiConverterString.read(buf), 2185 FfiConverterString.read(buf), 2186 FfiConverterBoolean.read(buf), 2187 ) 2188 else -> throw RuntimeException("invalid error enum value, something is very wrong!!") 2189 } 2190 } 2191 2192 override fun allocationSize(value: Exception): ULong { 2193 return when(value) { 2194 is Exception.Sdk -> ( 2195 // Add the size for the Int that specifies the variant plus the size needed for all fields 2196 4UL 2197 + FfiConverterString.allocationSize(value.`code`) 2198 + FfiConverterString.allocationSize(value.`message`) 2199 + FfiConverterBoolean.allocationSize(value.`retryable`) 2200 ) 2201 } 2202 } 2203 2204 override fun write(value: Exception, buf: ByteBuffer) { 2205 when(value) { 2206 is Exception.Sdk -> { 2207 buf.putInt(1) 2208 FfiConverterString.write(value.`code`, buf) 2209 FfiConverterString.write(value.`message`, buf) 2210 FfiConverterBoolean.write(value.`retryable`, buf) 2211 Unit 2212 } 2213 }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } 2214 } 2215 2216 } 2217 2218 2219 2220 /** 2221 * Final evidence coverage vocabulary. 2222 */ 2223 2224 enum class TradeEvidenceCoverage { 2225 2226 MISSING, 2227 PARTIAL, 2228 SCOPE_SATISFIED, 2229 UNSUPPORTED; 2230 2231 2232 2233 2234 companion object 2235 } 2236 2237 2238 /** 2239 * @suppress 2240 */ 2241 public object FfiConverterTypeTradeEvidenceCoverage: FfiConverterRustBuffer<TradeEvidenceCoverage> { 2242 override fun read(buf: ByteBuffer) = try { 2243 TradeEvidenceCoverage.values()[buf.getInt() - 1] 2244 } catch (e: IndexOutOfBoundsException) { 2245 throw RuntimeException("invalid enum value, something is very wrong!!", e) 2246 } 2247 2248 override fun allocationSize(value: TradeEvidenceCoverage) = 4UL 2249 2250 override fun write(value: TradeEvidenceCoverage, buf: ByteBuffer) { 2251 buf.putInt(value.ordinal + 1) 2252 } 2253 } 2254 2255 2256 2257 2258 2259 /** 2260 * Final evidence outcome vocabulary. 2261 */ 2262 2263 enum class TradeEvidenceOutcome { 2264 2265 VALID, 2266 INVALID, 2267 INDETERMINATE; 2268 2269 2270 2271 2272 companion object 2273 } 2274 2275 2276 /** 2277 * @suppress 2278 */ 2279 public object FfiConverterTypeTradeEvidenceOutcome: FfiConverterRustBuffer<TradeEvidenceOutcome> { 2280 override fun read(buf: ByteBuffer) = try { 2281 TradeEvidenceOutcome.values()[buf.getInt() - 1] 2282 } catch (e: IndexOutOfBoundsException) { 2283 throw RuntimeException("invalid enum value, something is very wrong!!", e) 2284 } 2285 2286 override fun allocationSize(value: TradeEvidenceOutcome) = 4UL 2287 2288 override fun write(value: TradeEvidenceOutcome, buf: ByteBuffer) { 2289 buf.putInt(value.ordinal + 1) 2290 } 2291 } 2292 2293 2294 2295 2296 2297 2298 /** 2299 * @suppress 2300 */ 2301 public object FfiConverterOptionalTypeRhiEvidenceSupersession: FfiConverterRustBuffer<RhiEvidenceSupersession?> { 2302 override fun read(buf: ByteBuffer): RhiEvidenceSupersession? { 2303 if (buf.get().toInt() == 0) { 2304 return null 2305 } 2306 return FfiConverterTypeRhiEvidenceSupersession.read(buf) 2307 } 2308 2309 override fun allocationSize(value: RhiEvidenceSupersession?): ULong { 2310 if (value == null) { 2311 return 1UL 2312 } else { 2313 return 1UL + FfiConverterTypeRhiEvidenceSupersession.allocationSize(value) 2314 } 2315 } 2316 2317 override fun write(value: RhiEvidenceSupersession?, buf: ByteBuffer) { 2318 if (value == null) { 2319 buf.put(0) 2320 } else { 2321 buf.put(1) 2322 FfiConverterTypeRhiEvidenceSupersession.write(value, buf) 2323 } 2324 } 2325 } 2326 2327 2328 2329 2330 /** 2331 * @suppress 2332 */ 2333 public object FfiConverterSequenceString: FfiConverterRustBuffer<List<kotlin.String>> { 2334 override fun read(buf: ByteBuffer): List<kotlin.String> { 2335 val len = buf.getInt() 2336 return List<kotlin.String>(len) { 2337 FfiConverterString.read(buf) 2338 } 2339 } 2340 2341 override fun allocationSize(value: List<kotlin.String>): ULong { 2342 val sizeForLength = 4UL 2343 val sizeForItems = value.map { FfiConverterString.allocationSize(it) }.sum() 2344 return sizeForLength + sizeForItems 2345 } 2346 2347 override fun write(value: List<kotlin.String>, buf: ByteBuffer) { 2348 buf.putInt(value.size) 2349 value.iterator().forEach { 2350 FfiConverterString.write(it, buf) 2351 } 2352 } 2353 } 2354 2355 2356 2357 2358 /** 2359 * @suppress 2360 */ 2361 public object FfiConverterSequenceTypeCapabilityStatus: FfiConverterRustBuffer<List<CapabilityStatus>> { 2362 override fun read(buf: ByteBuffer): List<CapabilityStatus> { 2363 val len = buf.getInt() 2364 return List<CapabilityStatus>(len) { 2365 FfiConverterTypeCapabilityStatus.read(buf) 2366 } 2367 } 2368 2369 override fun allocationSize(value: List<CapabilityStatus>): ULong { 2370 val sizeForLength = 4UL 2371 val sizeForItems = value.map { FfiConverterTypeCapabilityStatus.allocationSize(it) }.sum() 2372 return sizeForLength + sizeForItems 2373 } 2374 2375 override fun write(value: List<CapabilityStatus>, buf: ByteBuffer) { 2376 buf.putInt(value.size) 2377 value.iterator().forEach { 2378 FfiConverterTypeCapabilityStatus.write(it, buf) 2379 } 2380 } 2381 } 2382 2383 2384 2385 2386 /** 2387 * @suppress 2388 */ 2389 public object FfiConverterSequenceSequenceString: FfiConverterRustBuffer<List<List<kotlin.String>>> { 2390 override fun read(buf: ByteBuffer): List<List<kotlin.String>> { 2391 val len = buf.getInt() 2392 return List<List<kotlin.String>>(len) { 2393 FfiConverterSequenceString.read(buf) 2394 } 2395 } 2396 2397 override fun allocationSize(value: List<List<kotlin.String>>): ULong { 2398 val sizeForLength = 4UL 2399 val sizeForItems = value.map { FfiConverterSequenceString.allocationSize(it) }.sum() 2400 return sizeForLength + sizeForItems 2401 } 2402 2403 override fun write(value: List<List<kotlin.String>>, buf: ByteBuffer) { 2404 buf.putInt(value.size) 2405 value.iterator().forEach { 2406 FfiConverterSequenceString.write(it, buf) 2407 } 2408 } 2409 } 2410 2411 2412 2413 2414 2415 2416 2417 2418 @Throws(Exception::class) fun `parseRhiEvidenceReport`(`canonicalContent`: kotlin.String): RhiEvidenceReport { 2419 return FfiConverterTypeRhiEvidenceReport.lift( 2420 uniffiRustCallWithError(Exception) { _status -> 2421 UniffiLib.uniffi_radroots_sdk_ffi_fn_func_parse_rhi_evidence_report( 2422 2423 2424 FfiConverterString.lower(`canonicalContent`),_status) 2425 } 2426 ) 2427 } 2428 2429 2430 @Throws(Exception::class) fun `parseTradeEvidenceManifest`(`canonicalBytes`: kotlin.ByteArray): TradeEvidenceManifest { 2431 return FfiConverterTypeTradeEvidenceManifest.lift( 2432 uniffiRustCallWithError(Exception) { _status -> 2433 UniffiLib.uniffi_radroots_sdk_ffi_fn_func_parse_trade_evidence_manifest( 2434 2435 2436 FfiConverterByteArray.lower(`canonicalBytes`),_status) 2437 } 2438 ) 2439 } 2440 2441 2442 @Throws(Exception::class) fun `prepareRhiEvidenceAttestation`(`canonicalContent`: kotlin.String, `createdAtUnixS`: kotlin.ULong): TypedEvidenceEventPlan { 2443 return FfiConverterTypeTypedEvidenceEventPlan.lift( 2444 uniffiRustCallWithError(Exception) { _status -> 2445 UniffiLib.uniffi_radroots_sdk_ffi_fn_func_prepare_rhi_evidence_attestation( 2446 2447 2448 FfiConverterString.lower(`canonicalContent`), 2449 FfiConverterULong.lower(`createdAtUnixS`),_status) 2450 } 2451 ) 2452 } 2453 2454 2455 @Throws(Exception::class) fun `validateRhiEvidenceAttestation`(`event`: SignedEvent): RhiEvidenceAttestation { 2456 return FfiConverterTypeRhiEvidenceAttestation.lift( 2457 uniffiRustCallWithError(Exception) { _status -> 2458 UniffiLib.uniffi_radroots_sdk_ffi_fn_func_validate_rhi_evidence_attestation( 2459 2460 2461 FfiConverterTypeSignedEvent.lower(`event`),_status) 2462 } 2463 ) 2464 }