mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-02 20:42:24 +02:00
At this point, the only special behavior of bridge_fn_buffer is to support multiple return values for the C bridge (a pointer/length pair), and that doesn't pull its weight. Remove it in favor of a plain bridge_fn. This did reveal that Username_Hash was using bridge_fn_buffer and now produces a fixed-size array, imported into Swift as a tuple, so this commit also factors out a new helper invokeFnReturningFixedLengthArray.
37 lines
1.2 KiB
Swift
37 lines
1.2 KiB
Swift
//
|
|
// Copyright 2020-2022 Signal Messenger, LLC.
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import SignalFfi
|
|
import Foundation
|
|
|
|
public class SenderKeyRecord: ClonableHandleOwner {
|
|
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
|
|
return signal_sender_key_record_destroy(handle)
|
|
}
|
|
|
|
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
|
|
return signal_sender_key_record_clone(&newHandle, currentHandle)
|
|
}
|
|
|
|
public convenience init<Bytes: ContiguousBytes>(bytes: Bytes) throws {
|
|
let handle: OpaquePointer? = try bytes.withUnsafeBorrowedBuffer {
|
|
var result: OpaquePointer?
|
|
try checkError(signal_sender_key_record_deserialize(&result, $0))
|
|
return result
|
|
}
|
|
self.init(owned: handle!)
|
|
}
|
|
|
|
public func serialize() -> [UInt8] {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningArray {
|
|
signal_sender_key_record_serialize($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|