@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.
- package/GenationBridgePeer.podspec +17 -0
- package/LICENSE +190 -0
- package/README.md +66 -0
- package/package.json +59 -0
- package/react-native/android/build.gradle +24 -0
- package/react-native/android/src/main/java/com/genation/bridge/GenationBridgePeerModule.kt +182 -0
- package/react-native/android/src/main/java/com/genation/bridge/GenationBridgePeerPackage.kt +15 -0
- package/react-native/android/src/main/jniLibs/arm64-v8a/libgenation_bridge_crypto_uniffi.so +0 -0
- package/react-native/android/src/main/jniLibs/armeabi-v7a/libgenation_bridge_crypto_uniffi.so +0 -0
- package/react-native/android/src/main/jniLibs/x86/libgenation_bridge_crypto_uniffi.so +0 -0
- package/react-native/android/src/main/jniLibs/x86_64/libgenation_bridge_crypto_uniffi.so +0 -0
- package/react-native/generated/kotlin/uniffi/genation_bridge_crypto_uniffi/genation_bridge_crypto_uniffi.kt +2006 -0
- package/react-native/generated/swift/GenationBridgeCryptoMobile.swift +1072 -0
- package/react-native/generated/swift/GenationBridgeCryptoMobileFFI.h +703 -0
- package/react-native/generated/swift/GenationBridgeCryptoMobileFFI.modulemap +7 -0
- package/react-native/ios/GenationBridgePeer.m +14 -0
- package/react-native/ios/GenationBridgePeer.swift +234 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/Info.plist +48 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64/Headers/GenationBridgeCryptoMobileFFI.h +703 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64/Headers/module.modulemap +7 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64/libgenation_bridge_crypto_uniffi.a +0 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64_x86_64-simulator/Headers/GenationBridgeCryptoMobileFFI.h +703 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap +7 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64_x86_64-simulator/libgenation_bridge_crypto_uniffi.a +0 -0
- package/react-native.config.js +8 -0
- package/src/core/codec.d.ts +5 -0
- package/src/core/codec.js +46 -0
- package/src/core/errors.d.ts +11 -0
- package/src/core/errors.js +27 -0
- package/src/core/identity.d.ts +16 -0
- package/src/core/identity.js +1 -0
- package/src/core/lifecycle.d.ts +4 -0
- package/src/core/lifecycle.js +1 -0
- package/src/core/mod.d.ts +6 -0
- package/src/core/mod.js +3 -0
- package/src/core/peer.d.ts +67 -0
- package/src/core/peer.js +373 -0
- package/src/core/runtime.d.ts +78 -0
- package/src/core/runtime.js +0 -0
- package/src/node/crypto-core/javascript/mod.d.ts +8 -0
- package/src/node/crypto-core/javascript/mod.js +24 -0
- package/src/node/crypto-core/javascript/provider.d.ts +2 -0
- package/src/node/crypto-core/javascript/provider.js +43 -0
- package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm.d.ts +122 -0
- package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm.js +433 -0
- package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm_bg.wasm +0 -0
- package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm_bg.wasm.d.ts +25 -0
- package/src/node/encoding.js +1 -0
- package/src/node/file-key-store.d.ts +6 -0
- package/src/node/file-key-store.js +111 -0
- package/src/node/identity-provider.d.ts +8 -0
- package/src/node/identity-provider.js +57 -0
- package/src/node/identity.js +45 -0
- package/src/node/mod.d.ts +16 -0
- package/src/node/mod.js +17 -0
- package/src/node/relay-runtime.d.ts +11 -0
- package/src/node/relay-runtime.js +11 -0
- package/src/react-native/identity-provider.d.ts +4 -0
- package/src/react-native/identity-provider.js +125 -0
- package/src/react-native/lifecycle.d.ts +8 -0
- package/src/react-native/lifecycle.js +9 -0
- package/src/react-native/mod.d.ts +20 -0
- package/src/react-native/mod.js +36 -0
- package/src/react-native/native-module.d.ts +17 -0
- package/src/react-native/native-module.js +9 -0
- package/src/relay/encoding.js +32 -0
- package/src/relay/frame-channel.d.ts +1 -0
- package/src/relay/frame-channel.js +110 -0
- package/src/relay/identity.d.ts +27 -0
- package/src/relay/identity.js +0 -0
- package/src/relay/runtime.d.ts +8 -0
- package/src/relay/runtime.js +900 -0
|
@@ -0,0 +1,1072 @@
|
|
|
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
|
+
// swiftlint:disable all
|
|
5
|
+
import Foundation
|
|
6
|
+
|
|
7
|
+
// Depending on the consumer's build setup, the low-level FFI code
|
|
8
|
+
// might be in a separate module, or it might be compiled inline into
|
|
9
|
+
// this module. This is a bit of light hackery to work with both.
|
|
10
|
+
#if canImport(GenationBridgeCryptoMobileFFI)
|
|
11
|
+
import GenationBridgeCryptoMobileFFI
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
fileprivate extension RustBuffer {
|
|
15
|
+
// Allocate a new buffer, copying the contents of a `UInt8` array.
|
|
16
|
+
init(bytes: [UInt8]) {
|
|
17
|
+
let rbuf = bytes.withUnsafeBufferPointer { ptr in
|
|
18
|
+
RustBuffer.from(ptr)
|
|
19
|
+
}
|
|
20
|
+
self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static func empty() -> RustBuffer {
|
|
24
|
+
RustBuffer(capacity: 0, len:0, data: nil)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
|
|
28
|
+
try! rustCall { ffi_genation_bridge_crypto_uniffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Frees the buffer in place.
|
|
32
|
+
// The buffer must not be used after this is called.
|
|
33
|
+
func deallocate() {
|
|
34
|
+
try! rustCall { ffi_genation_bridge_crypto_uniffi_rustbuffer_free(self, $0) }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fileprivate extension ForeignBytes {
|
|
39
|
+
init(bufferPointer: UnsafeBufferPointer<UInt8>) {
|
|
40
|
+
self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// For every type used in the interface, we provide helper methods for conveniently
|
|
45
|
+
// lifting and lowering that type from C-compatible data, and for reading and writing
|
|
46
|
+
// values of that type in a buffer.
|
|
47
|
+
|
|
48
|
+
// Helper classes/extensions that don't change.
|
|
49
|
+
// Someday, this will be in a library of its own.
|
|
50
|
+
|
|
51
|
+
fileprivate extension Data {
|
|
52
|
+
init(rustBuffer: RustBuffer) {
|
|
53
|
+
self.init(
|
|
54
|
+
bytesNoCopy: rustBuffer.data!,
|
|
55
|
+
count: Int(rustBuffer.len),
|
|
56
|
+
deallocator: .none
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Define reader functionality. Normally this would be defined in a class or
|
|
62
|
+
// struct, but we use standalone functions instead in order to make external
|
|
63
|
+
// types work.
|
|
64
|
+
//
|
|
65
|
+
// With external types, one swift source file needs to be able to call the read
|
|
66
|
+
// method on another source file's FfiConverter, but then what visibility
|
|
67
|
+
// should Reader have?
|
|
68
|
+
// - If Reader is fileprivate, then this means the read() must also
|
|
69
|
+
// be fileprivate, which doesn't work with external types.
|
|
70
|
+
// - If Reader is internal/public, we'll get compile errors since both source
|
|
71
|
+
// files will try define the same type.
|
|
72
|
+
//
|
|
73
|
+
// Instead, the read() method and these helper functions input a tuple of data
|
|
74
|
+
|
|
75
|
+
fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
|
|
76
|
+
(data: data, offset: 0)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Reads an integer at the current offset, in big-endian order, and advances
|
|
80
|
+
// the offset on success. Throws if reading the integer would move the
|
|
81
|
+
// offset past the end of the buffer.
|
|
82
|
+
fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
|
|
83
|
+
let range = reader.offset..<reader.offset + MemoryLayout<T>.size
|
|
84
|
+
guard reader.data.count >= range.upperBound else {
|
|
85
|
+
throw UniffiInternalError.bufferOverflow
|
|
86
|
+
}
|
|
87
|
+
if T.self == UInt8.self {
|
|
88
|
+
let value = reader.data[reader.offset]
|
|
89
|
+
reader.offset += 1
|
|
90
|
+
return value as! T
|
|
91
|
+
}
|
|
92
|
+
var value: T = 0
|
|
93
|
+
let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
|
|
94
|
+
reader.offset = range.upperBound
|
|
95
|
+
return value.bigEndian
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Reads an arbitrary number of bytes, to be used to read
|
|
99
|
+
// raw bytes, this is useful when lifting strings
|
|
100
|
+
fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
|
|
101
|
+
let range = reader.offset..<(reader.offset+count)
|
|
102
|
+
guard reader.data.count >= range.upperBound else {
|
|
103
|
+
throw UniffiInternalError.bufferOverflow
|
|
104
|
+
}
|
|
105
|
+
var value = [UInt8](repeating: 0, count: count)
|
|
106
|
+
value.withUnsafeMutableBufferPointer({ buffer in
|
|
107
|
+
reader.data.copyBytes(to: buffer, from: range)
|
|
108
|
+
})
|
|
109
|
+
reader.offset = range.upperBound
|
|
110
|
+
return value
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Reads a float at the current offset.
|
|
114
|
+
fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
|
|
115
|
+
return Float(bitPattern: try readInt(&reader))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Reads a float at the current offset.
|
|
119
|
+
fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
|
|
120
|
+
return Double(bitPattern: try readInt(&reader))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Indicates if the offset has reached the end of the buffer.
|
|
124
|
+
fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
|
|
125
|
+
return reader.offset < reader.data.count
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Define writer functionality. Normally this would be defined in a class or
|
|
129
|
+
// struct, but we use standalone functions instead in order to make external
|
|
130
|
+
// types work. See the above discussion on Readers for details.
|
|
131
|
+
|
|
132
|
+
fileprivate func createWriter() -> [UInt8] {
|
|
133
|
+
return []
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
|
|
137
|
+
writer.append(contentsOf: byteArr)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Writes an integer in big-endian order.
|
|
141
|
+
//
|
|
142
|
+
// Warning: make sure what you are trying to write
|
|
143
|
+
// is in the correct type!
|
|
144
|
+
fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
|
|
145
|
+
var value = value.bigEndian
|
|
146
|
+
withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
|
|
150
|
+
writeInt(&writer, value.bitPattern)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
|
|
154
|
+
writeInt(&writer, value.bitPattern)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Protocol for types that transfer other types across the FFI. This is
|
|
158
|
+
// analogous to the Rust trait of the same name.
|
|
159
|
+
fileprivate protocol FfiConverter {
|
|
160
|
+
associatedtype FfiType
|
|
161
|
+
associatedtype SwiftType
|
|
162
|
+
|
|
163
|
+
static func lift(_ value: FfiType) throws -> SwiftType
|
|
164
|
+
static func lower(_ value: SwiftType) -> FfiType
|
|
165
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
|
|
166
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8])
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Types conforming to `Primitive` pass themselves directly over the FFI.
|
|
170
|
+
fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
|
|
171
|
+
|
|
172
|
+
extension FfiConverterPrimitive {
|
|
173
|
+
#if swift(>=5.8)
|
|
174
|
+
@_documentation(visibility: private)
|
|
175
|
+
#endif
|
|
176
|
+
public static func lift(_ value: FfiType) throws -> SwiftType {
|
|
177
|
+
return value
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#if swift(>=5.8)
|
|
181
|
+
@_documentation(visibility: private)
|
|
182
|
+
#endif
|
|
183
|
+
public static func lower(_ value: SwiftType) -> FfiType {
|
|
184
|
+
return value
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
|
|
189
|
+
// Used for complex types where it's hard to write a custom lift/lower.
|
|
190
|
+
fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
|
|
191
|
+
|
|
192
|
+
extension FfiConverterRustBuffer {
|
|
193
|
+
#if swift(>=5.8)
|
|
194
|
+
@_documentation(visibility: private)
|
|
195
|
+
#endif
|
|
196
|
+
public static func lift(_ buf: RustBuffer) throws -> SwiftType {
|
|
197
|
+
var reader = createReader(data: Data(rustBuffer: buf))
|
|
198
|
+
let value = try read(from: &reader)
|
|
199
|
+
if hasRemaining(reader) {
|
|
200
|
+
throw UniffiInternalError.incompleteData
|
|
201
|
+
}
|
|
202
|
+
buf.deallocate()
|
|
203
|
+
return value
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
#if swift(>=5.8)
|
|
207
|
+
@_documentation(visibility: private)
|
|
208
|
+
#endif
|
|
209
|
+
public static func lower(_ value: SwiftType) -> RustBuffer {
|
|
210
|
+
var writer = createWriter()
|
|
211
|
+
write(value, into: &writer)
|
|
212
|
+
return RustBuffer(bytes: writer)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// An error type for FFI errors. These errors occur at the UniFFI level, not
|
|
216
|
+
// the library level.
|
|
217
|
+
fileprivate enum UniffiInternalError: LocalizedError {
|
|
218
|
+
case bufferOverflow
|
|
219
|
+
case incompleteData
|
|
220
|
+
case unexpectedOptionalTag
|
|
221
|
+
case unexpectedEnumCase
|
|
222
|
+
case unexpectedNullPointer
|
|
223
|
+
case unexpectedRustCallStatusCode
|
|
224
|
+
case unexpectedRustCallError
|
|
225
|
+
case unexpectedStaleHandle
|
|
226
|
+
case rustPanic(_ message: String)
|
|
227
|
+
|
|
228
|
+
public var errorDescription: String? {
|
|
229
|
+
switch self {
|
|
230
|
+
case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
|
|
231
|
+
case .incompleteData: return "The buffer still has data after lifting its containing value"
|
|
232
|
+
case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
|
|
233
|
+
case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
|
|
234
|
+
case .unexpectedNullPointer: return "Raw pointer value was null"
|
|
235
|
+
case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
|
|
236
|
+
case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
|
|
237
|
+
case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
|
|
238
|
+
case let .rustPanic(message): return message
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
fileprivate extension NSLock {
|
|
244
|
+
func withLock<T>(f: () throws -> T) rethrows -> T {
|
|
245
|
+
self.lock()
|
|
246
|
+
defer { self.unlock() }
|
|
247
|
+
return try f()
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
fileprivate let CALL_SUCCESS: Int8 = 0
|
|
252
|
+
fileprivate let CALL_ERROR: Int8 = 1
|
|
253
|
+
fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
|
|
254
|
+
fileprivate let CALL_CANCELLED: Int8 = 3
|
|
255
|
+
|
|
256
|
+
fileprivate extension RustCallStatus {
|
|
257
|
+
init() {
|
|
258
|
+
self.init(
|
|
259
|
+
code: CALL_SUCCESS,
|
|
260
|
+
errorBuf: RustBuffer.init(
|
|
261
|
+
capacity: 0,
|
|
262
|
+
len: 0,
|
|
263
|
+
data: nil
|
|
264
|
+
)
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
270
|
+
let neverThrow: ((RustBuffer) throws -> Never)? = nil
|
|
271
|
+
return try makeRustCall(callback, errorHandler: neverThrow)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private func rustCallWithError<T, E: Swift.Error>(
|
|
275
|
+
_ errorHandler: @escaping (RustBuffer) throws -> E,
|
|
276
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
277
|
+
try makeRustCall(callback, errorHandler: errorHandler)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private func makeRustCall<T, E: Swift.Error>(
|
|
281
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
|
|
282
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
283
|
+
) throws -> T {
|
|
284
|
+
uniffiEnsureGenationBridgeCryptoUniffiInitialized()
|
|
285
|
+
var callStatus = RustCallStatus.init()
|
|
286
|
+
let returnedVal = callback(&callStatus)
|
|
287
|
+
try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
|
|
288
|
+
return returnedVal
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private func uniffiCheckCallStatus<E: Swift.Error>(
|
|
292
|
+
callStatus: RustCallStatus,
|
|
293
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
294
|
+
) throws {
|
|
295
|
+
switch callStatus.code {
|
|
296
|
+
case CALL_SUCCESS:
|
|
297
|
+
return
|
|
298
|
+
|
|
299
|
+
case CALL_ERROR:
|
|
300
|
+
if let errorHandler = errorHandler {
|
|
301
|
+
throw try errorHandler(callStatus.errorBuf)
|
|
302
|
+
} else {
|
|
303
|
+
callStatus.errorBuf.deallocate()
|
|
304
|
+
throw UniffiInternalError.unexpectedRustCallError
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
case CALL_UNEXPECTED_ERROR:
|
|
308
|
+
// When the rust code sees a panic, it tries to construct a RustBuffer
|
|
309
|
+
// with the message. But if that code panics, then it just sends back
|
|
310
|
+
// an empty buffer.
|
|
311
|
+
if callStatus.errorBuf.len > 0 {
|
|
312
|
+
throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
|
|
313
|
+
} else {
|
|
314
|
+
callStatus.errorBuf.deallocate()
|
|
315
|
+
throw UniffiInternalError.rustPanic("Rust panic")
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
case CALL_CANCELLED:
|
|
319
|
+
fatalError("Cancellation not supported yet")
|
|
320
|
+
|
|
321
|
+
default:
|
|
322
|
+
throw UniffiInternalError.unexpectedRustCallStatusCode
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private func uniffiTraitInterfaceCall<T>(
|
|
327
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
328
|
+
makeCall: () throws -> T,
|
|
329
|
+
writeReturn: (T) -> ()
|
|
330
|
+
) {
|
|
331
|
+
do {
|
|
332
|
+
try writeReturn(makeCall())
|
|
333
|
+
} catch let error {
|
|
334
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
335
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private func uniffiTraitInterfaceCallWithError<T, E>(
|
|
340
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
341
|
+
makeCall: () throws -> T,
|
|
342
|
+
writeReturn: (T) -> (),
|
|
343
|
+
lowerError: (E) -> RustBuffer
|
|
344
|
+
) {
|
|
345
|
+
do {
|
|
346
|
+
try writeReturn(makeCall())
|
|
347
|
+
} catch let error as E {
|
|
348
|
+
callStatus.pointee.code = CALL_ERROR
|
|
349
|
+
callStatus.pointee.errorBuf = lowerError(error)
|
|
350
|
+
} catch {
|
|
351
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
352
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
|
|
356
|
+
// All mutation happens with this lock held, which is why we implement @unchecked Sendable.
|
|
357
|
+
private let lock = NSLock()
|
|
358
|
+
private var map: [UInt64: T] = [:]
|
|
359
|
+
private var currentHandle: UInt64 = 1
|
|
360
|
+
|
|
361
|
+
func insert(obj: T) -> UInt64 {
|
|
362
|
+
lock.withLock {
|
|
363
|
+
let handle = currentHandle
|
|
364
|
+
currentHandle += 1
|
|
365
|
+
map[handle] = obj
|
|
366
|
+
return handle
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
func get(handle: UInt64) throws -> T {
|
|
371
|
+
try lock.withLock {
|
|
372
|
+
guard let obj = map[handle] else {
|
|
373
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
374
|
+
}
|
|
375
|
+
return obj
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
@discardableResult
|
|
380
|
+
func remove(handle: UInt64) throws -> T {
|
|
381
|
+
try lock.withLock {
|
|
382
|
+
guard let obj = map.removeValue(forKey: handle) else {
|
|
383
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
384
|
+
}
|
|
385
|
+
return obj
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
var count: Int {
|
|
390
|
+
get {
|
|
391
|
+
map.count
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
// Public interface members begin here.
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
#if swift(>=5.8)
|
|
401
|
+
@_documentation(visibility: private)
|
|
402
|
+
#endif
|
|
403
|
+
fileprivate struct FfiConverterString: FfiConverter {
|
|
404
|
+
typealias SwiftType = String
|
|
405
|
+
typealias FfiType = RustBuffer
|
|
406
|
+
|
|
407
|
+
public static func lift(_ value: RustBuffer) throws -> String {
|
|
408
|
+
defer {
|
|
409
|
+
value.deallocate()
|
|
410
|
+
}
|
|
411
|
+
if value.data == nil {
|
|
412
|
+
return String()
|
|
413
|
+
}
|
|
414
|
+
let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
|
|
415
|
+
return String(bytes: bytes, encoding: String.Encoding.utf8)!
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
public static func lower(_ value: String) -> RustBuffer {
|
|
419
|
+
return value.utf8CString.withUnsafeBufferPointer { ptr in
|
|
420
|
+
// The swift string gives us int8_t, we want uint8_t.
|
|
421
|
+
ptr.withMemoryRebound(to: UInt8.self) { ptr in
|
|
422
|
+
// The swift string gives us a trailing null byte, we don't want it.
|
|
423
|
+
let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
|
|
424
|
+
return RustBuffer.from(buf)
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
|
|
430
|
+
let len: Int32 = try readInt(&buf)
|
|
431
|
+
return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
public static func write(_ value: String, into buf: inout [UInt8]) {
|
|
435
|
+
let len = Int32(value.utf8.count)
|
|
436
|
+
writeInt(&buf, len)
|
|
437
|
+
writeBytes(&buf, value.utf8)
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
#if swift(>=5.8)
|
|
442
|
+
@_documentation(visibility: private)
|
|
443
|
+
#endif
|
|
444
|
+
fileprivate struct FfiConverterData: FfiConverterRustBuffer {
|
|
445
|
+
typealias SwiftType = Data
|
|
446
|
+
|
|
447
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
|
|
448
|
+
let len: Int32 = try readInt(&buf)
|
|
449
|
+
return Data(try readBytes(&buf, count: Int(len)))
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
public static func write(_ value: Data, into buf: inout [UInt8]) {
|
|
453
|
+
let len = Int32(value.count)
|
|
454
|
+
writeInt(&buf, len)
|
|
455
|
+
writeBytes(&buf, value)
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Opaque initiator object retained by generated Swift or Kotlin bindings.
|
|
464
|
+
*/
|
|
465
|
+
public protocol MobileInitiatorProtocol: AnyObject, Sendable {
|
|
466
|
+
|
|
467
|
+
func beginHandshake() throws -> Data
|
|
468
|
+
|
|
469
|
+
func closeSession() throws
|
|
470
|
+
|
|
471
|
+
func decrypt(aad: Data, ciphertext: Data) throws -> Data
|
|
472
|
+
|
|
473
|
+
func encrypt(aad: Data, plaintext: Data) throws -> Data
|
|
474
|
+
|
|
475
|
+
func finishHandshake(message: Data) throws
|
|
476
|
+
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Opaque initiator object retained by generated Swift or Kotlin bindings.
|
|
480
|
+
*/
|
|
481
|
+
open class MobileInitiator: MobileInitiatorProtocol, @unchecked Sendable {
|
|
482
|
+
fileprivate let pointer: UnsafeMutableRawPointer!
|
|
483
|
+
|
|
484
|
+
/// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
|
|
485
|
+
#if swift(>=5.8)
|
|
486
|
+
@_documentation(visibility: private)
|
|
487
|
+
#endif
|
|
488
|
+
public struct NoPointer {
|
|
489
|
+
public init() {}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
493
|
+
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
494
|
+
// make it `required` without making it `public`.
|
|
495
|
+
#if swift(>=5.8)
|
|
496
|
+
@_documentation(visibility: private)
|
|
497
|
+
#endif
|
|
498
|
+
required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
499
|
+
self.pointer = pointer
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// This constructor can be used to instantiate a fake object.
|
|
503
|
+
// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
|
|
504
|
+
//
|
|
505
|
+
// - Warning:
|
|
506
|
+
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash.
|
|
507
|
+
#if swift(>=5.8)
|
|
508
|
+
@_documentation(visibility: private)
|
|
509
|
+
#endif
|
|
510
|
+
public init(noPointer: NoPointer) {
|
|
511
|
+
self.pointer = nil
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
#if swift(>=5.8)
|
|
515
|
+
@_documentation(visibility: private)
|
|
516
|
+
#endif
|
|
517
|
+
public func uniffiClonePointer() -> UnsafeMutableRawPointer {
|
|
518
|
+
return try! rustCall { uniffi_genation_bridge_crypto_uniffi_fn_clone_mobileinitiator(self.pointer, $0) }
|
|
519
|
+
}
|
|
520
|
+
public convenience init(prologue: Data, localPrivateKey: Data, responderPublicKey: Data)throws {
|
|
521
|
+
let pointer =
|
|
522
|
+
try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
523
|
+
uniffi_genation_bridge_crypto_uniffi_fn_constructor_mobileinitiator_new(
|
|
524
|
+
FfiConverterData.lower(prologue),
|
|
525
|
+
FfiConverterData.lower(localPrivateKey),
|
|
526
|
+
FfiConverterData.lower(responderPublicKey),$0
|
|
527
|
+
)
|
|
528
|
+
}
|
|
529
|
+
self.init(unsafeFromRawPointer: pointer)
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
deinit {
|
|
533
|
+
guard let pointer = pointer else {
|
|
534
|
+
return
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
try! rustCall { uniffi_genation_bridge_crypto_uniffi_fn_free_mobileinitiator(pointer, $0) }
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
open func beginHandshake()throws -> Data {
|
|
544
|
+
return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
545
|
+
uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_begin_handshake(self.uniffiClonePointer(),$0
|
|
546
|
+
)
|
|
547
|
+
})
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
open func closeSession()throws {try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
551
|
+
uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_close_session(self.uniffiClonePointer(),$0
|
|
552
|
+
)
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
open func decrypt(aad: Data, ciphertext: Data)throws -> Data {
|
|
557
|
+
return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
558
|
+
uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_decrypt(self.uniffiClonePointer(),
|
|
559
|
+
FfiConverterData.lower(aad),
|
|
560
|
+
FfiConverterData.lower(ciphertext),$0
|
|
561
|
+
)
|
|
562
|
+
})
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
open func encrypt(aad: Data, plaintext: Data)throws -> Data {
|
|
566
|
+
return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
567
|
+
uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_encrypt(self.uniffiClonePointer(),
|
|
568
|
+
FfiConverterData.lower(aad),
|
|
569
|
+
FfiConverterData.lower(plaintext),$0
|
|
570
|
+
)
|
|
571
|
+
})
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
open func finishHandshake(message: Data)throws {try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
575
|
+
uniffi_genation_bridge_crypto_uniffi_fn_method_mobileinitiator_finish_handshake(self.uniffiClonePointer(),
|
|
576
|
+
FfiConverterData.lower(message),$0
|
|
577
|
+
)
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
#if swift(>=5.8)
|
|
586
|
+
@_documentation(visibility: private)
|
|
587
|
+
#endif
|
|
588
|
+
public struct FfiConverterTypeMobileInitiator: FfiConverter {
|
|
589
|
+
|
|
590
|
+
typealias FfiType = UnsafeMutableRawPointer
|
|
591
|
+
typealias SwiftType = MobileInitiator
|
|
592
|
+
|
|
593
|
+
public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MobileInitiator {
|
|
594
|
+
return MobileInitiator(unsafeFromRawPointer: pointer)
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
public static func lower(_ value: MobileInitiator) -> UnsafeMutableRawPointer {
|
|
598
|
+
return value.uniffiClonePointer()
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MobileInitiator {
|
|
602
|
+
let v: UInt64 = try readInt(&buf)
|
|
603
|
+
// The Rust code won't compile if a pointer won't fit in a UInt64.
|
|
604
|
+
// We have to go via `UInt` because that's the thing that's the size of a pointer.
|
|
605
|
+
let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
|
|
606
|
+
if (ptr == nil) {
|
|
607
|
+
throw UniffiInternalError.unexpectedNullPointer
|
|
608
|
+
}
|
|
609
|
+
return try lift(ptr!)
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
public static func write(_ value: MobileInitiator, into buf: inout [UInt8]) {
|
|
613
|
+
// This fiddling is because `Int` is the thing that's the same size as a pointer.
|
|
614
|
+
// The Rust code won't compile if a pointer won't fit in a `UInt64`.
|
|
615
|
+
writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
#if swift(>=5.8)
|
|
621
|
+
@_documentation(visibility: private)
|
|
622
|
+
#endif
|
|
623
|
+
public func FfiConverterTypeMobileInitiator_lift(_ pointer: UnsafeMutableRawPointer) throws -> MobileInitiator {
|
|
624
|
+
return try FfiConverterTypeMobileInitiator.lift(pointer)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
#if swift(>=5.8)
|
|
628
|
+
@_documentation(visibility: private)
|
|
629
|
+
#endif
|
|
630
|
+
public func FfiConverterTypeMobileInitiator_lower(_ value: MobileInitiator) -> UnsafeMutableRawPointer {
|
|
631
|
+
return FfiConverterTypeMobileInitiator.lower(value)
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Opaque responder object retained by generated Swift or Kotlin bindings.
|
|
641
|
+
*/
|
|
642
|
+
public protocol MobileResponderProtocol: AnyObject, Sendable {
|
|
643
|
+
|
|
644
|
+
func acceptHandshake(message: Data) throws -> Data
|
|
645
|
+
|
|
646
|
+
func closeSession() throws
|
|
647
|
+
|
|
648
|
+
func decrypt(aad: Data, ciphertext: Data) throws -> Data
|
|
649
|
+
|
|
650
|
+
func encrypt(aad: Data, plaintext: Data) throws -> Data
|
|
651
|
+
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Opaque responder object retained by generated Swift or Kotlin bindings.
|
|
655
|
+
*/
|
|
656
|
+
open class MobileResponder: MobileResponderProtocol, @unchecked Sendable {
|
|
657
|
+
fileprivate let pointer: UnsafeMutableRawPointer!
|
|
658
|
+
|
|
659
|
+
/// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
|
|
660
|
+
#if swift(>=5.8)
|
|
661
|
+
@_documentation(visibility: private)
|
|
662
|
+
#endif
|
|
663
|
+
public struct NoPointer {
|
|
664
|
+
public init() {}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
668
|
+
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
669
|
+
// make it `required` without making it `public`.
|
|
670
|
+
#if swift(>=5.8)
|
|
671
|
+
@_documentation(visibility: private)
|
|
672
|
+
#endif
|
|
673
|
+
required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
674
|
+
self.pointer = pointer
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// This constructor can be used to instantiate a fake object.
|
|
678
|
+
// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
|
|
679
|
+
//
|
|
680
|
+
// - Warning:
|
|
681
|
+
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash.
|
|
682
|
+
#if swift(>=5.8)
|
|
683
|
+
@_documentation(visibility: private)
|
|
684
|
+
#endif
|
|
685
|
+
public init(noPointer: NoPointer) {
|
|
686
|
+
self.pointer = nil
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
#if swift(>=5.8)
|
|
690
|
+
@_documentation(visibility: private)
|
|
691
|
+
#endif
|
|
692
|
+
public func uniffiClonePointer() -> UnsafeMutableRawPointer {
|
|
693
|
+
return try! rustCall { uniffi_genation_bridge_crypto_uniffi_fn_clone_mobileresponder(self.pointer, $0) }
|
|
694
|
+
}
|
|
695
|
+
public convenience init(prologue: Data, localPrivateKey: Data, initiatorPublicKey: Data)throws {
|
|
696
|
+
let pointer =
|
|
697
|
+
try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
698
|
+
uniffi_genation_bridge_crypto_uniffi_fn_constructor_mobileresponder_new(
|
|
699
|
+
FfiConverterData.lower(prologue),
|
|
700
|
+
FfiConverterData.lower(localPrivateKey),
|
|
701
|
+
FfiConverterData.lower(initiatorPublicKey),$0
|
|
702
|
+
)
|
|
703
|
+
}
|
|
704
|
+
self.init(unsafeFromRawPointer: pointer)
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
deinit {
|
|
708
|
+
guard let pointer = pointer else {
|
|
709
|
+
return
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
try! rustCall { uniffi_genation_bridge_crypto_uniffi_fn_free_mobileresponder(pointer, $0) }
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
open func acceptHandshake(message: Data)throws -> Data {
|
|
719
|
+
return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
720
|
+
uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_accept_handshake(self.uniffiClonePointer(),
|
|
721
|
+
FfiConverterData.lower(message),$0
|
|
722
|
+
)
|
|
723
|
+
})
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
open func closeSession()throws {try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
727
|
+
uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_close_session(self.uniffiClonePointer(),$0
|
|
728
|
+
)
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
open func decrypt(aad: Data, ciphertext: Data)throws -> Data {
|
|
733
|
+
return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
734
|
+
uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_decrypt(self.uniffiClonePointer(),
|
|
735
|
+
FfiConverterData.lower(aad),
|
|
736
|
+
FfiConverterData.lower(ciphertext),$0
|
|
737
|
+
)
|
|
738
|
+
})
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
open func encrypt(aad: Data, plaintext: Data)throws -> Data {
|
|
742
|
+
return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
743
|
+
uniffi_genation_bridge_crypto_uniffi_fn_method_mobileresponder_encrypt(self.uniffiClonePointer(),
|
|
744
|
+
FfiConverterData.lower(aad),
|
|
745
|
+
FfiConverterData.lower(plaintext),$0
|
|
746
|
+
)
|
|
747
|
+
})
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
#if swift(>=5.8)
|
|
755
|
+
@_documentation(visibility: private)
|
|
756
|
+
#endif
|
|
757
|
+
public struct FfiConverterTypeMobileResponder: FfiConverter {
|
|
758
|
+
|
|
759
|
+
typealias FfiType = UnsafeMutableRawPointer
|
|
760
|
+
typealias SwiftType = MobileResponder
|
|
761
|
+
|
|
762
|
+
public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MobileResponder {
|
|
763
|
+
return MobileResponder(unsafeFromRawPointer: pointer)
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
public static func lower(_ value: MobileResponder) -> UnsafeMutableRawPointer {
|
|
767
|
+
return value.uniffiClonePointer()
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MobileResponder {
|
|
771
|
+
let v: UInt64 = try readInt(&buf)
|
|
772
|
+
// The Rust code won't compile if a pointer won't fit in a UInt64.
|
|
773
|
+
// We have to go via `UInt` because that's the thing that's the size of a pointer.
|
|
774
|
+
let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
|
|
775
|
+
if (ptr == nil) {
|
|
776
|
+
throw UniffiInternalError.unexpectedNullPointer
|
|
777
|
+
}
|
|
778
|
+
return try lift(ptr!)
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
public static func write(_ value: MobileResponder, into buf: inout [UInt8]) {
|
|
782
|
+
// This fiddling is because `Int` is the thing that's the same size as a pointer.
|
|
783
|
+
// The Rust code won't compile if a pointer won't fit in a `UInt64`.
|
|
784
|
+
writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
#if swift(>=5.8)
|
|
790
|
+
@_documentation(visibility: private)
|
|
791
|
+
#endif
|
|
792
|
+
public func FfiConverterTypeMobileResponder_lift(_ pointer: UnsafeMutableRawPointer) throws -> MobileResponder {
|
|
793
|
+
return try FfiConverterTypeMobileResponder.lift(pointer)
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
#if swift(>=5.8)
|
|
797
|
+
@_documentation(visibility: private)
|
|
798
|
+
#endif
|
|
799
|
+
public func FfiConverterTypeMobileResponder_lower(_ value: MobileResponder) -> UnsafeMutableRawPointer {
|
|
800
|
+
return FfiConverterTypeMobileResponder.lower(value)
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* One generated private identity returned only to the native secure-store wrapper.
|
|
808
|
+
*/
|
|
809
|
+
public struct MobileIdentityMaterial {
|
|
810
|
+
public var connectionPrivateKey: Data
|
|
811
|
+
public var connectionPublicKey: Data
|
|
812
|
+
public var noiseStaticPrivateKey: Data
|
|
813
|
+
public var noiseStaticPublicKey: Data
|
|
814
|
+
|
|
815
|
+
// Default memberwise initializers are never public by default, so we
|
|
816
|
+
// declare one manually.
|
|
817
|
+
public init(connectionPrivateKey: Data, connectionPublicKey: Data, noiseStaticPrivateKey: Data, noiseStaticPublicKey: Data) {
|
|
818
|
+
self.connectionPrivateKey = connectionPrivateKey
|
|
819
|
+
self.connectionPublicKey = connectionPublicKey
|
|
820
|
+
self.noiseStaticPrivateKey = noiseStaticPrivateKey
|
|
821
|
+
self.noiseStaticPublicKey = noiseStaticPublicKey
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
#if compiler(>=6)
|
|
826
|
+
extension MobileIdentityMaterial: Sendable {}
|
|
827
|
+
#endif
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
extension MobileIdentityMaterial: Equatable, Hashable {
|
|
831
|
+
public static func ==(lhs: MobileIdentityMaterial, rhs: MobileIdentityMaterial) -> Bool {
|
|
832
|
+
if lhs.connectionPrivateKey != rhs.connectionPrivateKey {
|
|
833
|
+
return false
|
|
834
|
+
}
|
|
835
|
+
if lhs.connectionPublicKey != rhs.connectionPublicKey {
|
|
836
|
+
return false
|
|
837
|
+
}
|
|
838
|
+
if lhs.noiseStaticPrivateKey != rhs.noiseStaticPrivateKey {
|
|
839
|
+
return false
|
|
840
|
+
}
|
|
841
|
+
if lhs.noiseStaticPublicKey != rhs.noiseStaticPublicKey {
|
|
842
|
+
return false
|
|
843
|
+
}
|
|
844
|
+
return true
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
public func hash(into hasher: inout Hasher) {
|
|
848
|
+
hasher.combine(connectionPrivateKey)
|
|
849
|
+
hasher.combine(connectionPublicKey)
|
|
850
|
+
hasher.combine(noiseStaticPrivateKey)
|
|
851
|
+
hasher.combine(noiseStaticPublicKey)
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
#if swift(>=5.8)
|
|
858
|
+
@_documentation(visibility: private)
|
|
859
|
+
#endif
|
|
860
|
+
public struct FfiConverterTypeMobileIdentityMaterial: FfiConverterRustBuffer {
|
|
861
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MobileIdentityMaterial {
|
|
862
|
+
return
|
|
863
|
+
try MobileIdentityMaterial(
|
|
864
|
+
connectionPrivateKey: FfiConverterData.read(from: &buf),
|
|
865
|
+
connectionPublicKey: FfiConverterData.read(from: &buf),
|
|
866
|
+
noiseStaticPrivateKey: FfiConverterData.read(from: &buf),
|
|
867
|
+
noiseStaticPublicKey: FfiConverterData.read(from: &buf)
|
|
868
|
+
)
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
public static func write(_ value: MobileIdentityMaterial, into buf: inout [UInt8]) {
|
|
872
|
+
FfiConverterData.write(value.connectionPrivateKey, into: &buf)
|
|
873
|
+
FfiConverterData.write(value.connectionPublicKey, into: &buf)
|
|
874
|
+
FfiConverterData.write(value.noiseStaticPrivateKey, into: &buf)
|
|
875
|
+
FfiConverterData.write(value.noiseStaticPublicKey, into: &buf)
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
#if swift(>=5.8)
|
|
881
|
+
@_documentation(visibility: private)
|
|
882
|
+
#endif
|
|
883
|
+
public func FfiConverterTypeMobileIdentityMaterial_lift(_ buf: RustBuffer) throws -> MobileIdentityMaterial {
|
|
884
|
+
return try FfiConverterTypeMobileIdentityMaterial.lift(buf)
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
#if swift(>=5.8)
|
|
888
|
+
@_documentation(visibility: private)
|
|
889
|
+
#endif
|
|
890
|
+
public func FfiConverterTypeMobileIdentityMaterial_lower(_ value: MobileIdentityMaterial) -> RustBuffer {
|
|
891
|
+
return FfiConverterTypeMobileIdentityMaterial.lower(value)
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Stable native binding failures without provider or customer content.
|
|
897
|
+
*/
|
|
898
|
+
public enum MobileBindingError: Swift.Error {
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
case InvalidKey
|
|
903
|
+
case InvalidState
|
|
904
|
+
case Crypto
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
#if swift(>=5.8)
|
|
909
|
+
@_documentation(visibility: private)
|
|
910
|
+
#endif
|
|
911
|
+
public struct FfiConverterTypeMobileBindingError: FfiConverterRustBuffer {
|
|
912
|
+
typealias SwiftType = MobileBindingError
|
|
913
|
+
|
|
914
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MobileBindingError {
|
|
915
|
+
let variant: Int32 = try readInt(&buf)
|
|
916
|
+
switch variant {
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
case 1: return .InvalidKey
|
|
922
|
+
case 2: return .InvalidState
|
|
923
|
+
case 3: return .Crypto
|
|
924
|
+
|
|
925
|
+
default: throw UniffiInternalError.unexpectedEnumCase
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
public static func write(_ value: MobileBindingError, into buf: inout [UInt8]) {
|
|
930
|
+
switch value {
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
case .InvalidKey:
|
|
937
|
+
writeInt(&buf, Int32(1))
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
case .InvalidState:
|
|
941
|
+
writeInt(&buf, Int32(2))
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
case .Crypto:
|
|
945
|
+
writeInt(&buf, Int32(3))
|
|
946
|
+
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
#if swift(>=5.8)
|
|
953
|
+
@_documentation(visibility: private)
|
|
954
|
+
#endif
|
|
955
|
+
public func FfiConverterTypeMobileBindingError_lift(_ buf: RustBuffer) throws -> MobileBindingError {
|
|
956
|
+
return try FfiConverterTypeMobileBindingError.lift(buf)
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
#if swift(>=5.8)
|
|
960
|
+
@_documentation(visibility: private)
|
|
961
|
+
#endif
|
|
962
|
+
public func FfiConverterTypeMobileBindingError_lower(_ value: MobileBindingError) -> RustBuffer {
|
|
963
|
+
return FfiConverterTypeMobileBindingError.lower(value)
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
extension MobileBindingError: Equatable, Hashable {}
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
extension MobileBindingError: Foundation.LocalizedError {
|
|
973
|
+
public var errorDescription: String? {
|
|
974
|
+
String(reflecting: self)
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Generate independent Ed25519 and X25519 private material for native persistence.
|
|
982
|
+
*/
|
|
983
|
+
public func generateMobileIdentity()throws -> MobileIdentityMaterial {
|
|
984
|
+
return try FfiConverterTypeMobileIdentityMaterial_lift(try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
985
|
+
uniffi_genation_bridge_crypto_uniffi_fn_func_generate_mobile_identity($0
|
|
986
|
+
)
|
|
987
|
+
})
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Sign one compact-JWS signing input with native-stored Ed25519 private material.
|
|
991
|
+
*/
|
|
992
|
+
public func signMobileEd25519(privateKey: Data, message: Data)throws -> Data {
|
|
993
|
+
return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeMobileBindingError_lift) {
|
|
994
|
+
uniffi_genation_bridge_crypto_uniffi_fn_func_sign_mobile_ed25519(
|
|
995
|
+
FfiConverterData.lower(privateKey),
|
|
996
|
+
FfiConverterData.lower(message),$0
|
|
997
|
+
)
|
|
998
|
+
})
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
private enum InitializationResult {
|
|
1002
|
+
case ok
|
|
1003
|
+
case contractVersionMismatch
|
|
1004
|
+
case apiChecksumMismatch
|
|
1005
|
+
}
|
|
1006
|
+
// Use a global variable to perform the versioning checks. Swift ensures that
|
|
1007
|
+
// the code inside is only computed once.
|
|
1008
|
+
private let initializationResult: InitializationResult = {
|
|
1009
|
+
// Get the bindings contract version from our ComponentInterface
|
|
1010
|
+
let bindings_contract_version = 29
|
|
1011
|
+
// Get the scaffolding contract version by calling the into the dylib
|
|
1012
|
+
let scaffolding_contract_version = ffi_genation_bridge_crypto_uniffi_uniffi_contract_version()
|
|
1013
|
+
if bindings_contract_version != scaffolding_contract_version {
|
|
1014
|
+
return InitializationResult.contractVersionMismatch
|
|
1015
|
+
}
|
|
1016
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_func_generate_mobile_identity() != 57168) {
|
|
1017
|
+
return InitializationResult.apiChecksumMismatch
|
|
1018
|
+
}
|
|
1019
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_func_sign_mobile_ed25519() != 51877) {
|
|
1020
|
+
return InitializationResult.apiChecksumMismatch
|
|
1021
|
+
}
|
|
1022
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_begin_handshake() != 65237) {
|
|
1023
|
+
return InitializationResult.apiChecksumMismatch
|
|
1024
|
+
}
|
|
1025
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_close_session() != 30071) {
|
|
1026
|
+
return InitializationResult.apiChecksumMismatch
|
|
1027
|
+
}
|
|
1028
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_decrypt() != 20411) {
|
|
1029
|
+
return InitializationResult.apiChecksumMismatch
|
|
1030
|
+
}
|
|
1031
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_encrypt() != 51395) {
|
|
1032
|
+
return InitializationResult.apiChecksumMismatch
|
|
1033
|
+
}
|
|
1034
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileinitiator_finish_handshake() != 42193) {
|
|
1035
|
+
return InitializationResult.apiChecksumMismatch
|
|
1036
|
+
}
|
|
1037
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_accept_handshake() != 15954) {
|
|
1038
|
+
return InitializationResult.apiChecksumMismatch
|
|
1039
|
+
}
|
|
1040
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_close_session() != 32745) {
|
|
1041
|
+
return InitializationResult.apiChecksumMismatch
|
|
1042
|
+
}
|
|
1043
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_decrypt() != 7094) {
|
|
1044
|
+
return InitializationResult.apiChecksumMismatch
|
|
1045
|
+
}
|
|
1046
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_method_mobileresponder_encrypt() != 32833) {
|
|
1047
|
+
return InitializationResult.apiChecksumMismatch
|
|
1048
|
+
}
|
|
1049
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_constructor_mobileinitiator_new() != 58460) {
|
|
1050
|
+
return InitializationResult.apiChecksumMismatch
|
|
1051
|
+
}
|
|
1052
|
+
if (uniffi_genation_bridge_crypto_uniffi_checksum_constructor_mobileresponder_new() != 14675) {
|
|
1053
|
+
return InitializationResult.apiChecksumMismatch
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
return InitializationResult.ok
|
|
1057
|
+
}()
|
|
1058
|
+
|
|
1059
|
+
// Make the ensure init function public so that other modules which have external type references to
|
|
1060
|
+
// our types can call it.
|
|
1061
|
+
public func uniffiEnsureGenationBridgeCryptoUniffiInitialized() {
|
|
1062
|
+
switch initializationResult {
|
|
1063
|
+
case .ok:
|
|
1064
|
+
break
|
|
1065
|
+
case .contractVersionMismatch:
|
|
1066
|
+
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
|
|
1067
|
+
case .apiChecksumMismatch:
|
|
1068
|
+
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// swiftlint:enable all
|