mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-03 04:52:19 +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.
80 lines
2.3 KiB
Swift
80 lines
2.3 KiB
Swift
//
|
|
// Copyright 2020-2022 Signal Messenger, LLC.
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import SignalFfi
|
|
import Foundation
|
|
|
|
public class SenderKeyMessage: NativeHandleOwner {
|
|
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
|
|
return signal_sender_key_message_destroy(handle)
|
|
}
|
|
|
|
public convenience init<Bytes: ContiguousBytes>(bytes: Bytes) throws {
|
|
var result: OpaquePointer?
|
|
try bytes.withUnsafeBorrowedBuffer {
|
|
try checkError(signal_sender_key_message_deserialize(&result, $0))
|
|
}
|
|
self.init(owned: result!)
|
|
}
|
|
|
|
public var distributionId: UUID {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningUuid {
|
|
signal_sender_key_message_get_distribution_id($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public var chainId: UInt32 {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningInteger {
|
|
signal_sender_key_message_get_chain_id($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public var iteration: UInt32 {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningInteger {
|
|
signal_sender_key_message_get_iteration($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public func serialize() -> [UInt8] {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningArray {
|
|
signal_sender_key_message_serialize($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public var ciphertext: [UInt8] {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningArray {
|
|
signal_sender_key_message_get_cipher_text($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public func verifySignature(against key: PublicKey) throws -> Bool {
|
|
var result: Bool = false
|
|
try withNativeHandles(self, key) { messageHandle, keyHandle in
|
|
try checkError(signal_sender_key_message_verify_signature(&result, messageHandle, keyHandle))
|
|
}
|
|
return result
|
|
}
|
|
}
|