mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-03 13:02:20 +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.
88 lines
2.8 KiB
Swift
88 lines
2.8 KiB
Swift
//
|
|
// Copyright 2020-2022 Signal Messenger, LLC.
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import SignalFfi
|
|
import Foundation
|
|
|
|
public class SignalMessage: NativeHandleOwner {
|
|
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
|
|
return signal_message_destroy(handle)
|
|
}
|
|
|
|
public convenience init<Bytes: ContiguousBytes>(bytes: Bytes) throws {
|
|
var result: OpaquePointer?
|
|
try bytes.withUnsafeBorrowedBuffer {
|
|
try checkError(signal_message_deserialize(&result, $0))
|
|
}
|
|
self.init(owned: result!)
|
|
}
|
|
|
|
public var senderRatchetKey: PublicKey {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningNativeHandle {
|
|
signal_message_get_sender_ratchet_key($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public var body: [UInt8] {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningArray {
|
|
signal_message_get_body($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public func serialize() -> [UInt8] {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningArray {
|
|
signal_message_get_serialized($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public var messageVersion: UInt32 {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningInteger {
|
|
signal_message_get_message_version($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public var counter: UInt32 {
|
|
return withNativeHandle { nativeHandle in
|
|
failOnError {
|
|
try invokeFnReturningInteger {
|
|
signal_message_get_counter($0, nativeHandle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public func verifyMac<Bytes: ContiguousBytes>(sender: PublicKey,
|
|
receiver: PublicKey,
|
|
macKey: Bytes) throws -> Bool {
|
|
return try withNativeHandles(self, sender, receiver) { messageHandle, senderHandle, receiverHandle in
|
|
try macKey.withUnsafeBorrowedBuffer {
|
|
var result: Bool = false
|
|
try checkError(signal_message_verify_mac(&result,
|
|
messageHandle,
|
|
senderHandle,
|
|
receiverHandle,
|
|
$0))
|
|
return result
|
|
}
|
|
}
|
|
}
|
|
}
|