0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-19 11:32:17 +02:00

Enforce Swift code formatting

This commit is contained in:
moiseev-signal 2024-02-23 09:56:38 -08:00 committed by GitHub
parent 4f4d21a8ca
commit 58f43107ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
126 changed files with 3121 additions and 2738 deletions

View File

@ -34,3 +34,6 @@ max_line_length = 80
[*.sh]
indent_size = 4
[*.swift]
indent_size = 4

View File

@ -353,6 +353,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Check formatting
run: swiftformat --swiftversion 5 --reporter github-actions-log --lint .
working-directory: swift
- name: Run lint
run: swiftlint lint --strict --reporter github-actions-logging
working-directory: swift

25
.swiftformat Normal file
View File

@ -0,0 +1,25 @@
#--header "\nCopyright {created.year} Signal Messenger, LLC.\nSPDX-License-Identifier: AGPL-3.0-only\n"
--disable hoistPatternLet
# Explicit self is better than implicit self.
--self insert
# Some arguments that it considers unused are used in doc comments, and replacing them with '_' is an error.
--stripunusedargs unnamed-only
--wraparguments before-first
--wrapcollections before-first
# Libsignal is a collection of many languages, remembering specific of each one is hard. Make it explicit.
--disable redundantinternal
# Ranges look better without spaces
--ranges no-space
# Pragmas should start at the begining of line.
--ifdef outdent
--indent 4
# Patters are not redundant, they show the shape of thing, they show the shape of things.
--disable redundantPattern
# Leave try in the innermost position.
--disable hoistTry
# Explicit ACL even in extensions.
--extensionacl "on-declarations"
# Explicit is better than implicit.
--disable redundantNilInit
# Indentation for multi-line string literals.
--indentstrings true

View File

@ -12,13 +12,13 @@ let rustBuildDir = "../target/debug/"
let package = Package(
name: "LibSignalClient",
platforms: [
.macOS(.v10_15), .iOS(.v13)
.macOS(.v10_15), .iOS(.v13),
],
products: [
.library(
name: "LibSignalClient",
targets: ["LibSignalClient"]
)
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
@ -34,6 +34,6 @@ let package = Package(
name: "LibSignalClientTests",
dependencies: ["LibSignalClient"],
linkerSettings: [.unsafeFlags(["-L\(rustBuildDir)"])]
)
),
]
)

View File

@ -8,9 +8,11 @@ import SignalFfi
public class ProtocolAddress: ClonableHandleOwner {
public convenience init(name: String, deviceId: UInt32) throws {
var handle: OpaquePointer?
try checkError(signal_address_new(&handle,
name,
deviceId))
try checkError(signal_address_new(
&handle,
name,
deviceId
))
self.init(owned: handle!)
}
@ -25,11 +27,11 @@ public class ProtocolAddress: ClonableHandleOwner {
}
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_address_clone(&newHandle, currentHandle)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_address_destroy(handle)
}
@ -47,7 +49,7 @@ public class ProtocolAddress: ClonableHandleOwner {
///
/// In a future release ProtocolAddresses will *only* support ServiceIds.
public var serviceId: ServiceId! {
return try? ServiceId.parseFrom(serviceIdString: name)
return try? ServiceId.parseFrom(serviceIdString: self.name)
}
public var deviceId: UInt32 {
@ -63,7 +65,7 @@ public class ProtocolAddress: ClonableHandleOwner {
extension ProtocolAddress: CustomDebugStringConvertible {
public var debugDescription: String {
return "\(name).\(deviceId)"
return "\(self.name).\(self.deviceId)"
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class Aes256Ctr32: NativeHandleOwner {
public static let keyLength: Int = 32
@ -27,27 +27,31 @@ public class Aes256Ctr32: NativeHandleOwner {
var nonceBufferWithoutCounter = SignalBorrowedBuffer(nonceBytes)
nonceBufferWithoutCounter.length -= 4
var result: OpaquePointer?
try checkError(signal_aes256_ctr32_new(&result,
keyBuffer,
nonceBufferWithoutCounter,
initialCounter))
try checkError(signal_aes256_ctr32_new(
&result,
keyBuffer,
nonceBufferWithoutCounter,
initialCounter
))
return result
}
}
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_aes256_ctr32_destroy(handle)
}
public func process(_ message: inout Data) throws {
try withNativeHandle { nativeHandle in
try message.withUnsafeMutableBytes { messageBytes in
try checkError(signal_aes256_ctr32_process(nativeHandle,
SignalBorrowedMutableBuffer(messageBytes),
0,
UInt32(messageBytes.count)))
try checkError(signal_aes256_ctr32_process(
nativeHandle,
SignalBorrowedMutableBuffer(messageBytes),
0,
UInt32(messageBytes.count)
))
}
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public struct Aes256GcmEncryptedData {
public static let keyLength: Int = 32
@ -33,19 +33,18 @@ public struct Aes256GcmEncryptedData {
}
public func concatenate() -> Data {
var result = Data(capacity: nonce.count + ciphertext.count + authenticationTag.count)
result += nonce
result += ciphertext
result += authenticationTag
var result = Data(capacity: nonce.count + self.ciphertext.count + self.authenticationTag.count)
result += self.nonce
result += self.ciphertext
result += self.authenticationTag
return result
}
public static func encrypt<KeyBytes, AssociatedDataBytes>(
public static func encrypt(
_ message: Data,
key: KeyBytes,
associatedData: AssociatedDataBytes
) throws -> Self
where KeyBytes: ContiguousBytes, AssociatedDataBytes: ContiguousBytes {
key: some ContiguousBytes,
associatedData: some ContiguousBytes
) throws -> Self {
var nonce = Data(count: Self.nonceLength)
try nonce.withUnsafeMutableBytes { try fillRandom($0) }
@ -57,17 +56,16 @@ public struct Aes256GcmEncryptedData {
return Self(nonce: nonce, ciphertext: ciphertext, authenticationTag: tag)
}
public static func encrypt<KeyBytes: ContiguousBytes>(_ message: Data, key: KeyBytes) throws -> Self {
return try encrypt(message, key: key, associatedData: [])
public static func encrypt(_ message: Data, key: some ContiguousBytes) throws -> Self {
return try self.encrypt(message, key: key, associatedData: [])
}
// Inlinable here specifically to avoid copying the ciphertext again if the struct is no longer used.
@inlinable
public func decrypt<KeyBytes, AssociatedDataBytes>(
key: KeyBytes,
associatedData: AssociatedDataBytes
) throws -> Data
where KeyBytes: ContiguousBytes, AssociatedDataBytes: ContiguousBytes {
public func decrypt(
key: some ContiguousBytes,
associatedData: some ContiguousBytes
) throws -> Data {
let cipher = try Aes256GcmDecryption(key: key, nonce: self.nonce, associatedData: associatedData)
var plaintext = self.ciphertext
try cipher.decrypt(&plaintext)
@ -78,26 +76,28 @@ public struct Aes256GcmEncryptedData {
}
@inlinable
public func decrypt<KeyBytes: ContiguousBytes>(key: KeyBytes) throws -> Data {
return try decrypt(key: key, associatedData: [])
public func decrypt(key: some ContiguousBytes) throws -> Data {
return try self.decrypt(key: key, associatedData: [])
}
}
/// Supports streamed encryption and custom nonces. Use Aes256GcmEncryptedData if you don't need either.
public class Aes256GcmEncryption: NativeHandleOwner {
public convenience init<KeyBytes, NonceBytes, AssociatedDataBytes>(
key: KeyBytes,
nonce: NonceBytes,
associatedData: AssociatedDataBytes
) throws where KeyBytes: ContiguousBytes, NonceBytes: ContiguousBytes, AssociatedDataBytes: ContiguousBytes {
public convenience init(
key: some ContiguousBytes,
nonce: some ContiguousBytes,
associatedData: some ContiguousBytes
) throws {
let handle: OpaquePointer? = try key.withUnsafeBorrowedBuffer { keyBuffer in
try nonce.withUnsafeBorrowedBuffer { nonceBuffer in
try associatedData.withUnsafeBorrowedBuffer { adBuffer in
var result: OpaquePointer?
try checkError(signal_aes256_gcm_encryption_new(&result,
keyBuffer,
nonceBuffer,
adBuffer))
try checkError(signal_aes256_gcm_encryption_new(
&result,
keyBuffer,
nonceBuffer,
adBuffer
))
return result
}
}
@ -105,17 +105,19 @@ public class Aes256GcmEncryption: NativeHandleOwner {
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_aes256_gcm_encryption_destroy(handle)
}
public func encrypt(_ message: inout Data) throws {
try withNativeHandle { nativeHandle in
try message.withUnsafeMutableBytes { messageBytes in
try checkError(signal_aes256_gcm_encryption_update(nativeHandle,
SignalBorrowedMutableBuffer(messageBytes),
0,
UInt32(messageBytes.count)))
try checkError(signal_aes256_gcm_encryption_update(
nativeHandle,
SignalBorrowedMutableBuffer(messageBytes),
0,
UInt32(messageBytes.count)
))
}
}
}
@ -131,19 +133,21 @@ public class Aes256GcmEncryption: NativeHandleOwner {
/// Supports streamed decryption. Use Aes256GcmEncryptedData if you don't need streamed decryption.
public class Aes256GcmDecryption: NativeHandleOwner {
public convenience init<KeyBytes, NonceBytes, AssociatedDataBytes>(
key: KeyBytes,
nonce: NonceBytes,
associatedData: AssociatedDataBytes
) throws where KeyBytes: ContiguousBytes, NonceBytes: ContiguousBytes, AssociatedDataBytes: ContiguousBytes {
public convenience init(
key: some ContiguousBytes,
nonce: some ContiguousBytes,
associatedData: some ContiguousBytes
) throws {
let handle: OpaquePointer? = try key.withUnsafeBorrowedBuffer { keyBuffer in
try nonce.withUnsafeBorrowedBuffer { nonceBuffer in
try associatedData.withUnsafeBorrowedBuffer { adBuffer in
var result: OpaquePointer?
try checkError(signal_aes256_gcm_decryption_new(&result,
keyBuffer,
nonceBuffer,
adBuffer))
try checkError(signal_aes256_gcm_decryption_new(
&result,
keyBuffer,
nonceBuffer,
adBuffer
))
return result
}
}
@ -151,28 +155,32 @@ public class Aes256GcmDecryption: NativeHandleOwner {
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_aes256_gcm_decryption_destroy(handle)
}
public func decrypt(_ message: inout Data) throws {
try withNativeHandle { nativeHandle in
try message.withUnsafeMutableBytes { messageBytes in
try checkError(signal_aes256_gcm_decryption_update(nativeHandle,
SignalBorrowedMutableBuffer(messageBytes),
0,
UInt32(messageBytes.count)))
try checkError(signal_aes256_gcm_decryption_update(
nativeHandle,
SignalBorrowedMutableBuffer(messageBytes),
0,
UInt32(messageBytes.count)
))
}
}
}
public func verifyTag<Bytes: ContiguousBytes>(_ tag: Bytes) throws -> Bool {
public func verifyTag(_ tag: some ContiguousBytes) throws -> Bool {
return try withNativeHandle { nativeHandle in
try tag.withUnsafeBorrowedBuffer { tagBuffer in
var result = false
try checkError(signal_aes256_gcm_decryption_verify_tag(&result,
nativeHandle,
tagBuffer))
try checkError(signal_aes256_gcm_decryption_verify_tag(
&result,
nativeHandle,
tagBuffer
))
return result
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class Aes256GcmSiv: NativeHandleOwner {
public convenience init<Bytes: ContiguousBytes>(key bytes: Bytes) throws {
@ -16,29 +16,27 @@ public class Aes256GcmSiv: NativeHandleOwner {
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_aes256_gcm_siv_destroy(handle)
}
public func encrypt<MessageBytes, NonceBytes, AssociatedDataBytes>(
_ message: MessageBytes,
nonce: NonceBytes,
associatedData: AssociatedDataBytes
) throws -> [UInt8]
where MessageBytes: ContiguousBytes,
NonceBytes: ContiguousBytes,
AssociatedDataBytes: ContiguousBytes {
public func encrypt(
_ message: some ContiguousBytes,
nonce: some ContiguousBytes,
associatedData: some ContiguousBytes
) throws -> [UInt8] {
try withNativeHandle { nativeHandle in
try message.withUnsafeBorrowedBuffer { messageBuffer in
try nonce.withUnsafeBorrowedBuffer { nonceBuffer in
try associatedData.withUnsafeBorrowedBuffer { adBuffer in
try invokeFnReturningArray {
signal_aes256_gcm_siv_encrypt($0,
nativeHandle,
messageBuffer,
nonceBuffer,
adBuffer)
signal_aes256_gcm_siv_encrypt(
$0,
nativeHandle,
messageBuffer,
nonceBuffer,
adBuffer
)
}
}
}
@ -46,29 +44,27 @@ public class Aes256GcmSiv: NativeHandleOwner {
}
}
public func decrypt<MessageBytes, NonceBytes, AssociatedDataBytes> (
_ message: MessageBytes,
nonce: NonceBytes,
associatedData: AssociatedDataBytes) throws -> [UInt8]
where MessageBytes: ContiguousBytes,
NonceBytes: ContiguousBytes,
AssociatedDataBytes: ContiguousBytes {
public func decrypt(
_ message: some ContiguousBytes,
nonce: some ContiguousBytes,
associatedData: some ContiguousBytes
) throws -> [UInt8] {
try withNativeHandle { nativeHandle in
try message.withUnsafeBorrowedBuffer { messageBuffer in
try nonce.withUnsafeBorrowedBuffer { nonceBuffer in
try associatedData.withUnsafeBorrowedBuffer { adBuffer in
try invokeFnReturningArray {
signal_aes256_gcm_siv_decrypt($0,
nativeHandle,
messageBuffer,
nonceBuffer,
adBuffer)
signal_aes256_gcm_siv_decrypt(
$0,
nativeHandle,
messageBuffer,
nonceBuffer,
adBuffer
)
}
}
}
}
}
}
}

View File

@ -28,12 +28,14 @@ extension Int32: Completable {
extension UnsafeRawPointer: Completable {
typealias PromiseCallback = SignalCPromiseRawPointer
}
extension OpaquePointer: Completable {
// C function pointer that takes two output arguments and one input argument.
typealias PromiseCallback = (@convention(c) (
_ error: SignalFfiErrorRef?,
_ value: UnsafePointer<OpaquePointer?>?,
_ context: UnsafeRawPointer?) -> Void)?
_ context: UnsafeRawPointer?
) -> Void)?
}
extension SignalFfiCdsiLookupResponse: Completable {

View File

@ -3,24 +3,28 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
///
/// Cds2Client provides bindings to interact with Signal's v2 Contact Discovery Service.
///
/// See ``SgxClient``
public class Cds2Client: SgxClient {
public convenience init<MrenclaveBytes, AttestationBytes>(mrenclave: MrenclaveBytes, attestationMessage: AttestationBytes, currentDate: Date) throws
where MrenclaveBytes: ContiguousBytes, AttestationBytes: ContiguousBytes {
public convenience init(
mrenclave: some ContiguousBytes,
attestationMessage: some ContiguousBytes,
currentDate: Date
) throws {
let handle: OpaquePointer? = try attestationMessage.withUnsafeBorrowedBuffer { attestationMessageBuffer in
try mrenclave.withUnsafeBorrowedBuffer { mrenclaveBuffer in
var result: OpaquePointer?
try checkError(signal_cds2_client_state_new(&result,
mrenclaveBuffer,
attestationMessageBuffer,
UInt64(currentDate.timeIntervalSince1970 * 1000)))
try checkError(signal_cds2_client_state_new(
&result,
mrenclaveBuffer,
attestationMessageBuffer,
UInt64(currentDate.timeIntervalSince1970 * 1000)
))
return result
}
}

View File

@ -27,8 +27,8 @@ open class InMemorySignalProtocolStore: IdentityKeyStore, PreKeyStore, SignedPre
private var senderKeyMap: [SenderKeyName: SenderKeyRecord] = [:]
public init() {
privateKey = IdentityKeyPair.generate()
registrationId = UInt32.random(in: 0...0x3FFF)
self.privateKey = IdentityKeyPair.generate()
self.registrationId = UInt32.random(in: 0...0x3FFF)
}
public init(identity: IdentityKeyPair, registrationId: UInt32) {
@ -37,15 +37,15 @@ open class InMemorySignalProtocolStore: IdentityKeyStore, PreKeyStore, SignedPre
}
open func identityKeyPair(context: StoreContext) throws -> IdentityKeyPair {
return privateKey
return self.privateKey
}
open func localRegistrationId(context: StoreContext) throws -> UInt32 {
return registrationId
return self.registrationId
}
open func saveIdentity(_ identity: IdentityKey, for address: ProtocolAddress, context: StoreContext) throws -> Bool {
if publicKeys.updateValue(identity, forKey: address) == nil {
if self.publicKeys.updateValue(identity, forKey: address) == nil {
return false // newly created
} else {
return true
@ -61,7 +61,7 @@ open class InMemorySignalProtocolStore: IdentityKeyStore, PreKeyStore, SignedPre
}
open func identity(for address: ProtocolAddress, context: StoreContext) throws -> IdentityKey? {
return publicKeys[address]
return self.publicKeys[address]
}
open func loadPreKey(id: UInt32, context: StoreContext) throws -> PreKeyRecord {
@ -73,11 +73,11 @@ open class InMemorySignalProtocolStore: IdentityKeyStore, PreKeyStore, SignedPre
}
open func storePreKey(_ record: PreKeyRecord, id: UInt32, context: StoreContext) throws {
prekeyMap[id] = record
self.prekeyMap[id] = record
}
open func removePreKey(id: UInt32, context: StoreContext) throws {
prekeyMap.removeValue(forKey: id)
self.prekeyMap.removeValue(forKey: id)
}
open func loadSignedPreKey(id: UInt32, context: StoreContext) throws -> SignedPreKeyRecord {
@ -89,7 +89,7 @@ open class InMemorySignalProtocolStore: IdentityKeyStore, PreKeyStore, SignedPre
}
open func storeSignedPreKey(_ record: SignedPreKeyRecord, id: UInt32, context: StoreContext) throws {
signedPrekeyMap[id] = record
self.signedPrekeyMap[id] = record
}
open func loadKyberPreKey(id: UInt32, context: StoreContext) throws -> KyberPreKeyRecord {
@ -101,15 +101,15 @@ open class InMemorySignalProtocolStore: IdentityKeyStore, PreKeyStore, SignedPre
}
open func storeKyberPreKey(_ record: KyberPreKeyRecord, id: UInt32, context: StoreContext) throws {
kyberPrekeyMap[id] = record
self.kyberPrekeyMap[id] = record
}
open func markKyberPreKeyUsed(id: UInt32, context: StoreContext) throws {
kyberPrekeysUsed.insert(id)
self.kyberPrekeysUsed.insert(id)
}
open func loadSession(for address: ProtocolAddress, context: StoreContext) throws -> SessionRecord? {
return sessionMap[address]
return self.sessionMap[address]
}
open func loadExistingSessions(for addresses: [ProtocolAddress], context: StoreContext) throws -> [SessionRecord] {
@ -122,14 +122,14 @@ open class InMemorySignalProtocolStore: IdentityKeyStore, PreKeyStore, SignedPre
}
open func storeSession(_ record: SessionRecord, for address: ProtocolAddress, context: StoreContext) throws {
sessionMap[address] = record
self.sessionMap[address] = record
}
open func storeSenderKey(from sender: ProtocolAddress, distributionId: UUID, record: SenderKeyRecord, context: StoreContext) throws {
senderKeyMap[SenderKeyName(sender: sender, distributionId: distributionId)] = record
self.senderKeyMap[SenderKeyName(sender: sender, distributionId: distributionId)] = record
}
open func loadSenderKey(from sender: ProtocolAddress, distributionId: UUID, context: StoreContext) throws -> SenderKeyRecord? {
return senderKeyMap[SenderKeyName(sender: sender, distributionId: distributionId)]
return self.senderKeyMap[SenderKeyName(sender: sender, distributionId: distributionId)]
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public enum Direction {
case sending

View File

@ -3,12 +3,14 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
internal func withIdentityKeyStore<Result>(_ store: IdentityKeyStore, _ context: StoreContext, _ body: (UnsafePointer<SignalIdentityKeyStore>) throws -> Result) throws -> Result {
func ffiShimGetIdentityKeyPair(storeCtx: UnsafeMutableRawPointer?,
keyp: UnsafeMutablePointer<OpaquePointer?>?) -> Int32 {
func ffiShimGetIdentityKeyPair(
storeCtx: UnsafeMutableRawPointer?,
keyp: UnsafeMutablePointer<OpaquePointer?>?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(IdentityKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var privateKey = try store.identityKeyPair(context: context).privateKey
@ -17,8 +19,10 @@ internal func withIdentityKeyStore<Result>(_ store: IdentityKeyStore, _ context:
}
}
func ffiShimGetLocalRegistrationId(storeCtx: UnsafeMutableRawPointer?,
idp: UnsafeMutablePointer<UInt32>?) -> Int32 {
func ffiShimGetLocalRegistrationId(
storeCtx: UnsafeMutableRawPointer?,
idp: UnsafeMutablePointer<UInt32>?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(IdentityKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
let id = try store.localRegistrationId(context: context)
@ -27,9 +31,11 @@ internal func withIdentityKeyStore<Result>(_ store: IdentityKeyStore, _ context:
}
}
func ffiShimSaveIdentity(storeCtx: UnsafeMutableRawPointer?,
address: OpaquePointer?,
public_key: OpaquePointer?) -> Int32 {
func ffiShimSaveIdentity(
storeCtx: UnsafeMutableRawPointer?,
address: OpaquePointer?,
public_key: OpaquePointer?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(IdentityKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var address = ProtocolAddress(borrowing: address)
@ -46,9 +52,11 @@ internal func withIdentityKeyStore<Result>(_ store: IdentityKeyStore, _ context:
}
}
func ffiShimGetIdentity(storeCtx: UnsafeMutableRawPointer?,
public_key: UnsafeMutablePointer<OpaquePointer?>?,
address: OpaquePointer?) -> Int32 {
func ffiShimGetIdentity(
storeCtx: UnsafeMutableRawPointer?,
public_key: UnsafeMutablePointer<OpaquePointer?>?,
address: OpaquePointer?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(IdentityKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var address = ProtocolAddress(borrowing: address)
@ -63,10 +71,12 @@ internal func withIdentityKeyStore<Result>(_ store: IdentityKeyStore, _ context:
}
}
func ffiShimIsTrustedIdentity(storeCtx: UnsafeMutableRawPointer?,
address: OpaquePointer?,
public_key: OpaquePointer?,
raw_direction: UInt32) -> Int32 {
func ffiShimIsTrustedIdentity(
storeCtx: UnsafeMutableRawPointer?,
address: OpaquePointer?,
public_key: OpaquePointer?,
raw_direction: UInt32
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(IdentityKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var address = ProtocolAddress(borrowing: address)
@ -96,15 +106,18 @@ internal func withIdentityKeyStore<Result>(_ store: IdentityKeyStore, _ context:
get_local_registration_id: ffiShimGetLocalRegistrationId,
save_identity: ffiShimSaveIdentity,
get_identity: ffiShimGetIdentity,
is_trusted_identity: ffiShimIsTrustedIdentity)
is_trusted_identity: ffiShimIsTrustedIdentity
)
return try body(&ffiStore)
}
}
internal func withPreKeyStore<Result>(_ store: PreKeyStore, _ context: StoreContext, _ body: (UnsafePointer<SignalPreKeyStore>) throws -> Result) throws -> Result {
func ffiShimStorePreKey(storeCtx: UnsafeMutableRawPointer?,
id: UInt32,
record: OpaquePointer?) -> Int32 {
func ffiShimStorePreKey(
storeCtx: UnsafeMutableRawPointer?,
id: UInt32,
record: OpaquePointer?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(PreKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var record = PreKeyRecord(borrowing: record)
@ -114,9 +127,11 @@ internal func withPreKeyStore<Result>(_ store: PreKeyStore, _ context: StoreCont
}
}
func ffiShimLoadPreKey(storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
id: UInt32) -> Int32 {
func ffiShimLoadPreKey(
storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
id: UInt32
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(PreKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var record = try store.loadPreKey(id: id, context: context)
@ -125,8 +140,10 @@ internal func withPreKeyStore<Result>(_ store: PreKeyStore, _ context: StoreCont
}
}
func ffiShimRemovePreKey(storeCtx: UnsafeMutableRawPointer?,
id: UInt32) -> Int32 {
func ffiShimRemovePreKey(
storeCtx: UnsafeMutableRawPointer?,
id: UInt32
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(PreKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
try store.removePreKey(id: id, context: context)
@ -139,15 +156,18 @@ internal func withPreKeyStore<Result>(_ store: PreKeyStore, _ context: StoreCont
ctx: $0,
load_pre_key: ffiShimLoadPreKey,
store_pre_key: ffiShimStorePreKey,
remove_pre_key: ffiShimRemovePreKey)
remove_pre_key: ffiShimRemovePreKey
)
return try body(&ffiStore)
}
}
internal func withSignedPreKeyStore<Result>(_ store: SignedPreKeyStore, _ context: StoreContext, _ body: (UnsafePointer<SignalSignedPreKeyStore>) throws -> Result) throws -> Result {
func ffiShimStoreSignedPreKey(storeCtx: UnsafeMutableRawPointer?,
id: UInt32,
record: OpaquePointer?) -> Int32 {
func ffiShimStoreSignedPreKey(
storeCtx: UnsafeMutableRawPointer?,
id: UInt32,
record: OpaquePointer?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(SignedPreKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var record = SignedPreKeyRecord(borrowing: record)
@ -157,9 +177,11 @@ internal func withSignedPreKeyStore<Result>(_ store: SignedPreKeyStore, _ contex
}
}
func ffiShimLoadSignedPreKey(storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
id: UInt32) -> Int32 {
func ffiShimLoadSignedPreKey(
storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
id: UInt32
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(SignedPreKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var record = try store.loadSignedPreKey(id: id, context: context)
@ -172,15 +194,18 @@ internal func withSignedPreKeyStore<Result>(_ store: SignedPreKeyStore, _ contex
var ffiStore = SignalSignedPreKeyStore(
ctx: $0,
load_signed_pre_key: ffiShimLoadSignedPreKey,
store_signed_pre_key: ffiShimStoreSignedPreKey)
store_signed_pre_key: ffiShimStoreSignedPreKey
)
return try body(&ffiStore)
}
}
internal func withKyberPreKeyStore<Result>(_ store: KyberPreKeyStore, _ context: StoreContext, _ body: (UnsafePointer<SignalKyberPreKeyStore>) throws -> Result) throws -> Result {
func ffiShimStoreKyberPreKey(storeCtx: UnsafeMutableRawPointer?,
id: UInt32,
record: OpaquePointer?) -> Int32 {
func ffiShimStoreKyberPreKey(
storeCtx: UnsafeMutableRawPointer?,
id: UInt32,
record: OpaquePointer?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(KyberPreKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var record = KyberPreKeyRecord(borrowing: record)
@ -190,9 +215,11 @@ internal func withKyberPreKeyStore<Result>(_ store: KyberPreKeyStore, _ context:
}
}
func ffiShimLoadKyberPreKey(storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
id: UInt32) -> Int32 {
func ffiShimLoadKyberPreKey(
storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
id: UInt32
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(KyberPreKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var record = try store.loadKyberPreKey(id: id, context: context)
@ -201,8 +228,10 @@ internal func withKyberPreKeyStore<Result>(_ store: KyberPreKeyStore, _ context:
}
}
func ffiShimMarkKyberPreKeyUsed(storeCtx: UnsafeMutableRawPointer?,
id: UInt32) -> Int32 {
func ffiShimMarkKyberPreKeyUsed(
storeCtx: UnsafeMutableRawPointer?,
id: UInt32
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(KyberPreKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
try store.markKyberPreKeyUsed(id: id, context: context)
@ -215,15 +244,18 @@ internal func withKyberPreKeyStore<Result>(_ store: KyberPreKeyStore, _ context:
ctx: $0,
load_kyber_pre_key: ffiShimLoadKyberPreKey,
store_kyber_pre_key: ffiShimStoreKyberPreKey,
mark_kyber_pre_key_used: ffiShimMarkKyberPreKeyUsed)
mark_kyber_pre_key_used: ffiShimMarkKyberPreKeyUsed
)
return try body(&ffiStore)
}
}
internal func withSessionStore<Result>(_ store: SessionStore, _ context: StoreContext, _ body: (UnsafePointer<SignalSessionStore>) throws -> Result) throws -> Result {
func ffiShimStoreSession(storeCtx: UnsafeMutableRawPointer?,
address: OpaquePointer?,
record: OpaquePointer?) -> Int32 {
func ffiShimStoreSession(
storeCtx: UnsafeMutableRawPointer?,
address: OpaquePointer?,
record: OpaquePointer?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(SessionStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var address = ProtocolAddress(borrowing: address)
@ -235,9 +267,11 @@ internal func withSessionStore<Result>(_ store: SessionStore, _ context: StoreCo
}
}
func ffiShimLoadSession(storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
address: OpaquePointer?) -> Int32 {
func ffiShimLoadSession(
storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
address: OpaquePointer?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(SessionStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var address = ProtocolAddress(borrowing: address)
@ -255,16 +289,19 @@ internal func withSessionStore<Result>(_ store: SessionStore, _ context: StoreCo
var ffiStore = SignalSessionStore(
ctx: $0,
load_session: ffiShimLoadSession,
store_session: ffiShimStoreSession)
store_session: ffiShimStoreSession
)
return try body(&ffiStore)
}
}
internal func withSenderKeyStore<Result>(_ store: SenderKeyStore, _ context: StoreContext, _ body: (UnsafePointer<SignalSenderKeyStore>) throws -> Result) rethrows -> Result {
func ffiShimStoreSenderKey(storeCtx: UnsafeMutableRawPointer?,
sender: OpaquePointer?,
distributionId: UnsafePointer<uuid_t>?,
record: OpaquePointer?) -> Int32 {
func ffiShimStoreSenderKey(
storeCtx: UnsafeMutableRawPointer?,
sender: OpaquePointer?,
distributionId: UnsafePointer<uuid_t>?,
record: OpaquePointer?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(SenderKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var sender = ProtocolAddress(borrowing: sender)
@ -277,10 +314,12 @@ internal func withSenderKeyStore<Result>(_ store: SenderKeyStore, _ context: Sto
}
}
func ffiShimLoadSenderKey(storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
sender: OpaquePointer?,
distributionId: UnsafePointer<uuid_t>?) -> Int32 {
func ffiShimLoadSenderKey(
storeCtx: UnsafeMutableRawPointer?,
recordp: UnsafeMutablePointer<OpaquePointer?>?,
sender: OpaquePointer?,
distributionId: UnsafePointer<uuid_t>?
) -> Int32 {
let storeContext = storeCtx!.assumingMemoryBound(to: ErrorHandlingContext<(SenderKeyStore, StoreContext)>.self)
return storeContext.pointee.catchCallbackErrors { store, context in
var sender = ProtocolAddress(borrowing: sender)
@ -299,7 +338,8 @@ internal func withSenderKeyStore<Result>(_ store: SenderKeyStore, _ context: Sto
var ffiStore = SignalSenderKeyStore(
ctx: $0,
load_sender_key: ffiShimLoadSenderKey,
store_sender_key: ffiShimStoreSenderKey)
store_sender_key: ffiShimStoreSenderKey
)
return try body(&ffiStore)
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public enum KeyFormat: UInt8, CaseIterable {
// PKCS#8 is the default for backward compatibility
@ -30,13 +30,15 @@ public struct DeviceTransferKey {
}
public func generateCertificate(_ name: String, _ daysTilExpire: Int) -> [UInt8] {
return privateKey.withUnsafeBorrowedBuffer { privateKeyBuffer in
return self.privateKey.withUnsafeBorrowedBuffer { privateKeyBuffer in
failOnError {
try invokeFnReturningArray {
signal_device_transfer_generate_certificate($0,
privateKeyBuffer,
name,
UInt32(daysTilExpire))
signal_device_transfer_generate_certificate(
$0,
privateKeyBuffer,
name,
UInt32(daysTilExpire)
)
}
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
#if canImport(SignalCoreKit)
import SignalCoreKit

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public struct DisplayableFingerprint {
public let formatted: String
@ -18,7 +18,7 @@ public struct ScannableFingerprint {
/// Throws an error if `other` is not a valid fingerprint encoding, or if it uses an
/// incompatible encoding version.
public func compare<Other: ContiguousBytes>(againstEncoding other: Other) throws -> Bool {
var result: Bool = false
var result = false
try encoding.withUnsafeBorrowedBuffer { encodingBuffer in
try other.withUnsafeBorrowedBuffer { otherBuffer in
try checkError(signal_fingerprint_compare(&result, encodingBuffer, otherBuffer))
@ -45,21 +45,26 @@ public struct NumericFingerprintGenerator {
self.iterations = iterations
}
public func create<LocalBytes, RemoteBytes>(version: Int,
localIdentifier: LocalBytes,
localKey: PublicKey,
remoteIdentifier: RemoteBytes,
remoteKey: PublicKey) throws -> Fingerprint
where LocalBytes: ContiguousBytes, RemoteBytes: ContiguousBytes {
public func create(
version: Int,
localIdentifier: some ContiguousBytes,
localKey: PublicKey,
remoteIdentifier: some ContiguousBytes,
remoteKey: PublicKey
) throws -> Fingerprint {
var obj: OpaquePointer?
try withNativeHandles(localKey, remoteKey) { localKeyHandle, remoteKeyHandle in
try localIdentifier.withUnsafeBorrowedBuffer { localBuffer in
try remoteIdentifier.withUnsafeBorrowedBuffer { remoteBuffer in
try checkError(signal_fingerprint_new(&obj, UInt32(iterations), UInt32(version),
localBuffer,
localKeyHandle,
remoteBuffer,
remoteKeyHandle))
try checkError(signal_fingerprint_new(
&obj,
UInt32(self.iterations),
UInt32(version),
localBuffer,
localKeyHandle,
remoteBuffer,
remoteKeyHandle
))
}
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
/// The HsmCodeHashList is a wrapper around a flat UInt8 array to make it more
/// convenient to send code hashes to initialize the client.
@ -15,7 +15,7 @@ public struct HsmCodeHashList {
var codeHashes: [UInt8]
public init() {
codeHashes = []
self.codeHashes = []
}
public mutating func append(_ codeHash: [UInt8]) throws {
@ -23,11 +23,11 @@ public struct HsmCodeHashList {
fatalError("code hash length must be 32")
}
codeHashes.append(contentsOf: codeHash)
self.codeHashes.append(contentsOf: codeHash)
}
func flatten() -> [UInt8] {
return codeHashes
return self.codeHashes
}
}
@ -48,16 +48,17 @@ public struct HsmCodeHashList {
/// which decrypts and verifies it, passing the plaintext back to the client for processing.
///
public class HsmEnclaveClient: NativeHandleOwner {
public convenience init<Bytes: ContiguousBytes>(publicKey: Bytes, codeHashes: HsmCodeHashList) throws {
let codeHashBytes = codeHashes.flatten()
let handle: OpaquePointer? = try publicKey.withUnsafeBorrowedBuffer { publicKeyBuffer in
try codeHashBytes.withUnsafeBorrowedBuffer { codeHashBuffer in
var result: OpaquePointer?
try checkError(signal_hsm_enclave_client_new(&result,
publicKeyBuffer,
codeHashBuffer))
try checkError(signal_hsm_enclave_client_new(
&result,
publicKeyBuffer,
codeHashBuffer
))
return result
}
}
@ -65,7 +66,7 @@ public class HsmEnclaveClient: NativeHandleOwner {
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_hsm_enclave_client_destroy(handle)
}

View File

@ -7,7 +7,6 @@ import Foundation
import SignalFfi
public enum Ias {
public static func verify<
Signature: ContiguousBytes,
Body: ContiguousBytes,

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public struct IdentityKey: Equatable {
public let publicKey: PublicKey
@ -14,22 +14,21 @@ public struct IdentityKey: Equatable {
}
public init<Bytes: ContiguousBytes>(bytes: Bytes) throws {
publicKey = try PublicKey(bytes)
self.publicKey = try PublicKey(bytes)
}
public func serialize() -> [UInt8] {
return publicKey.serialize()
return self.publicKey.serialize()
}
public func verifyAlternateIdentity<Bytes: ContiguousBytes>(_ other: IdentityKey, signature: Bytes) throws -> Bool {
var result: Bool = false
var result = false
try withNativeHandles(publicKey, other.publicKey) { selfHandle, otherHandle in
try signature.withUnsafeBorrowedBuffer { signatureBuffer in
try checkError(signal_identitykey_verify_alternate_identity(&result, selfHandle, otherHandle, signatureBuffer))
}
}
return result
}
}
@ -50,8 +49,8 @@ public struct IdentityKeyPair {
try checkError(signal_identitykeypair_deserialize(&privkeyPtr, &pubkeyPtr, $0))
}
publicKey = PublicKey(owned: pubkeyPtr!)
privateKey = PrivateKey(owned: privkeyPtr!)
self.publicKey = PublicKey(owned: pubkeyPtr!)
self.privateKey = PrivateKey(owned: privkeyPtr!)
}
public init(publicKey: PublicKey, privateKey: PrivateKey) {
@ -60,7 +59,7 @@ public struct IdentityKeyPair {
}
public func serialize() -> [UInt8] {
return withNativeHandles(publicKey, privateKey) { publicKey, privateKey in
return withNativeHandles(self.publicKey, self.privateKey) { publicKey, privateKey in
failOnError {
try invokeFnReturningArray {
signal_identitykeypair_serialize($0, publicKey, privateKey)
@ -70,11 +69,11 @@ public struct IdentityKeyPair {
}
public var identityKey: IdentityKey {
return IdentityKey(publicKey: publicKey)
return IdentityKey(publicKey: self.publicKey)
}
public func signAlternateIdentity(_ other: IdentityKey) -> [UInt8] {
return withNativeHandles(publicKey, privateKey, other.publicKey) { publicKey, privateKey, other in
return withNativeHandles(self.publicKey, self.privateKey, other.publicKey) { publicKey, privateKey, other in
failOnError {
try invokeFnReturningArray {
signal_identitykeypair_sign_alternate_identity($0, publicKey, privateKey, other)

View File

@ -23,7 +23,7 @@ public enum SizeChoice {
}
public class IncrementalMacContext: NativeHandleOwner {
private var _digest: Data = Data()
private var _digest: Data = .init()
public convenience init<Key: ContiguousBytes>(key: Key, chunkSize sizeChoice: SizeChoice) throws {
let chunkSize = try sizeChoice.sizeInBytes()
@ -35,14 +35,14 @@ public class IncrementalMacContext: NativeHandleOwner {
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_incremental_mac_destroy(handle)
}
public func update<Bytes: ContiguousBytes>(_ bytes: Bytes) throws {
let digest = try bytes.withUnsafeBorrowedBuffer { bytesPtr in
return try invokeFnReturningArray {
return signal_incremental_mac_update($0, unsafeNativeHandle, bytesPtr, 0, UInt32(bytesPtr.length))
try invokeFnReturningArray {
signal_incremental_mac_update($0, unsafeNativeHandle, bytesPtr, 0, UInt32(bytesPtr.length))
}
}
self._digest.append(contentsOf: digest)
@ -50,7 +50,7 @@ public class IncrementalMacContext: NativeHandleOwner {
public func finalize() throws -> [UInt8] {
let digest = try invokeFnReturningArray {
return signal_incremental_mac_finalize($0, unsafeNativeHandle)
signal_incremental_mac_finalize($0, unsafeNativeHandle)
}
self._digest.append(contentsOf: digest)
return Array(self._digest)
@ -73,14 +73,14 @@ public class ValidatingMacContext: NativeHandleOwner {
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_validating_mac_destroy(handle)
}
public func update<Bytes: ContiguousBytes>(_ bytes: Bytes) throws -> UInt32 {
let validBytesCount = try bytes.withUnsafeBorrowedBuffer { bytesPtr in
return try invokeFnReturningInteger {
return signal_validating_mac_update($0, unsafeNativeHandle, bytesPtr, 0, UInt32(bytesPtr.length))
try invokeFnReturningInteger {
signal_validating_mac_update($0, unsafeNativeHandle, bytesPtr, 0, UInt32(bytesPtr.length))
}
}
if validBytesCount < 0 {
@ -91,7 +91,7 @@ public class ValidatingMacContext: NativeHandleOwner {
public func finalize() throws -> UInt32 {
let validBytesCount = try invokeFnReturningInteger {
return signal_validating_mac_finalize($0, unsafeNativeHandle)
signal_validating_mac_finalize($0, unsafeNativeHandle)
}
if validBytesCount < 0 {
throw SignalError.verificationFailed("Bad incremental MAC (finalize)")

View File

@ -56,16 +56,16 @@ public class SignalInputStreamAdapter<Inner>: SignalInputStream where Inner: Col
}
public func read(into buffer: UnsafeMutableRawBufferPointer) throws -> Int {
let amount = min(buffer.count, inner.count)
buffer.copyBytes(from: inner.prefix(amount))
inner = inner.dropFirst(amount)
let amount = min(buffer.count, self.inner.count)
buffer.copyBytes(from: self.inner.prefix(amount))
self.inner = self.inner.dropFirst(amount)
return amount
}
public func skip(by amount: UInt64) throws {
if amount > UInt64(inner.count) {
if amount > UInt64(self.inner.count) {
throw SignalInputStreamError.unexpectedEof
}
inner = inner.dropFirst(Int(amount))
self.inner = self.inner.dropFirst(Int(amount))
}
}

View File

@ -7,10 +7,12 @@ import Foundation
import SignalFfi
internal func withInputStream<Result>(_ stream: SignalInputStream, _ body: (UnsafePointer<SignalFfi.SignalInputStream>) throws -> Result) throws -> Result {
func ffiShimRead(stream_ctx: UnsafeMutableRawPointer?,
pBuf: UnsafeMutablePointer<UInt8>?,
bufLen: Int,
pAmountRead: UnsafeMutablePointer<Int>?) -> Int32 {
func ffiShimRead(
stream_ctx: UnsafeMutableRawPointer?,
pBuf: UnsafeMutablePointer<UInt8>?,
bufLen: Int,
pAmountRead: UnsafeMutablePointer<Int>?
) -> Int32 {
let streamContext = stream_ctx!.assumingMemoryBound(to: ErrorHandlingContext<SignalInputStream>.self)
return streamContext.pointee.catchCallbackErrors { stream in
let buf = UnsafeMutableRawBufferPointer(start: pBuf, count: bufLen)
@ -32,7 +34,8 @@ internal func withInputStream<Result>(_ stream: SignalInputStream, _ body: (Unsa
var ffiStream = SignalFfi.SignalInputStream(
ctx: $0,
read: ffiShimRead as SignalRead,
skip: ffiShimSkip as SignalSkip)
skip: ffiShimSkip as SignalSkip
)
return try body(&ffiStream)
}
}

View File

@ -3,24 +3,27 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public func hkdf<InputBytes, SaltBytes, InfoBytes>(outputLength: Int,
inputKeyMaterial: InputBytes,
salt: SaltBytes,
info: InfoBytes) throws -> [UInt8]
where InputBytes: ContiguousBytes, SaltBytes: ContiguousBytes, InfoBytes: ContiguousBytes {
public func hkdf(
outputLength: Int,
inputKeyMaterial: some ContiguousBytes,
salt: some ContiguousBytes,
info: some ContiguousBytes
) throws -> [UInt8] {
var output = Array(repeating: UInt8(0x00), count: outputLength)
try output.withUnsafeMutableBytes { outputBuffer in
try inputKeyMaterial.withUnsafeBorrowedBuffer { inputBuffer in
try salt.withUnsafeBorrowedBuffer { saltBuffer in
try info.withUnsafeBorrowedBuffer { infoBuffer in
try checkError(signal_hkdf_derive(.init(outputBuffer),
inputBuffer,
infoBuffer,
saltBuffer))
try checkError(signal_hkdf_derive(
.init(outputBuffer),
inputBuffer,
infoBuffer,
saltBuffer
))
}
}
}
@ -30,15 +33,18 @@ where InputBytes: ContiguousBytes, SaltBytes: ContiguousBytes, InfoBytes: Contig
}
@available(*, deprecated, message: "Remove the 'version' parameter for standard HKDF behavior")
public func hkdf<InputBytes, SaltBytes, InfoBytes>(outputLength: Int,
version: UInt32,
inputKeyMaterial: InputBytes,
salt: SaltBytes,
info: InfoBytes) throws -> [UInt8]
where InputBytes: ContiguousBytes, SaltBytes: ContiguousBytes, InfoBytes: ContiguousBytes {
public func hkdf(
outputLength: Int,
version: UInt32,
inputKeyMaterial: some ContiguousBytes,
salt: some ContiguousBytes,
info: some ContiguousBytes
) throws -> [UInt8] {
precondition(version == 3, "HKDF versions other than 3 are no longer supported")
return try hkdf(outputLength: outputLength,
inputKeyMaterial: inputKeyMaterial,
salt: salt,
info: info)
return try hkdf(
outputLength: outputLength,
inputKeyMaterial: inputKeyMaterial,
salt: salt,
info: info
)
}

View File

@ -3,11 +3,10 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class KEMKeyPair: ClonableHandleOwner {
public static func generate() -> KEMKeyPair {
return failOnError {
try invokeFnReturningNativeHandle {
@ -16,11 +15,11 @@ public class KEMKeyPair: ClonableHandleOwner {
}
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_kyber_key_pair_clone(&newHandle, currentHandle)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_kyber_key_pair_destroy(handle)
}
@ -55,11 +54,11 @@ public class KEMPublicKey: ClonableHandleOwner {
self.init(owned: handle!)
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_kyber_public_key_clone(&newHandle, currentHandle)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_kyber_public_key_destroy(handle)
}
@ -96,11 +95,11 @@ public class KEMSecretKey: ClonableHandleOwner {
self.init(owned: handle!)
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_kyber_secret_key_clone(&newHandle, currentHandle)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_kyber_secret_key_destroy(handle)
}

View File

@ -74,11 +74,11 @@ public func sanitizeWebp(input: SignalInputStream, length ignored: UInt64) throw
}
public class SanitizedMetadata: ClonableHandleOwner {
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_sanitized_metadata_clone(&newHandle, currentHandle)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_sanitized_metadata_destroy(handle)
}

View File

@ -7,26 +7,25 @@ import Foundation
import SignalFfi
public class MessageBackupKey: NativeHandleOwner {
public convenience init(masterKey: [UInt8], aci: Aci) throws {
let masterKey = try ByteArray(newContents: masterKey, expectedLength: 32)
let handle = try masterKey.withUnsafePointerToSerialized { masterKey in
try aci.withPointerToFixedWidthBinary { aci in
var outputHandle: OpaquePointer?
try checkError(signal_message_backup_key_new(&outputHandle, masterKey, aci))
return outputHandle
}
public convenience init(masterKey: [UInt8], aci: Aci) throws {
let masterKey = try ByteArray(newContents: masterKey, expectedLength: 32)
let handle = try masterKey.withUnsafePointerToSerialized { masterKey in
try aci.withPointerToFixedWidthBinary { aci in
var outputHandle: OpaquePointer?
try checkError(signal_message_backup_key_new(&outputHandle, masterKey, aci))
return outputHandle
}
}
self.init(owned: handle!)
}
self.init(owned: handle!)
}
internal required init(owned handle: OpaquePointer) {
super.init(owned: handle)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
signal_message_backup_key_destroy(handle)
}
internal required init(owned handle: OpaquePointer) {
super.init(owned: handle)
}
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
signal_message_backup_key_destroy(handle)
}
}
/// Validates a message backup file.
@ -42,58 +41,58 @@ public class MessageBackupKey: NativeHandleOwner {
/// - `SignalError.ioError`: If an IO error on the input occurs.
/// - `MessageBackupValidationError`: If validation fails
public func validateMessageBackup(
key: MessageBackupKey, length: UInt64, makeStream: () -> SignalInputStream
key: MessageBackupKey, length: UInt64, makeStream: () -> SignalInputStream
) throws -> MessageBackupUnknownFields {
let outcome: ValidationOutcome = try withInputStream(makeStream()) { firstInput in
try withInputStream(makeStream()) { secondInput in
try key.withNativeHandle { key in
try invokeFnReturningNativeHandle {
signal_message_backup_validator_validate($0, key, firstInput, secondInput, length)
let outcome: ValidationOutcome = try withInputStream(makeStream()) { firstInput in
try withInputStream(makeStream()) { secondInput in
try key.withNativeHandle { key in
try invokeFnReturningNativeHandle {
signal_message_backup_validator_validate($0, key, firstInput, secondInput, length)
}
}
}
}
}
}
if let errorMessage = outcome.errorMessage {
throw MessageBackupValidationError(errorMessage: errorMessage, unknownFields: outcome.unknownFields)
}
return outcome.unknownFields
if let errorMessage = outcome.errorMessage {
throw MessageBackupValidationError(errorMessage: errorMessage, unknownFields: outcome.unknownFields)
}
return outcome.unknownFields
}
/// The outcome of a failed validation attempt.
public struct MessageBackupValidationError: Error {
/// The human-readable error that caused validation to fail.
public var errorMessage: String
/// Unknown fields encountered while validating.
public var unknownFields: MessageBackupUnknownFields
/// The human-readable error that caused validation to fail.
public var errorMessage: String
/// Unknown fields encountered while validating.
public var unknownFields: MessageBackupUnknownFields
}
/// Unknown fields encountered while validating.
public struct MessageBackupUnknownFields {
public let fields: [String]
public let fields: [String]
}
private class ValidationOutcome: NativeHandleOwner {
public var unknownFields: MessageBackupUnknownFields {
let fields = failOnError {
try self.withNativeHandle { result in
try invokeFnReturningStringArray {
signal_message_backup_validation_outcome_get_unknown_fields($0, result)
public var unknownFields: MessageBackupUnknownFields {
let fields = failOnError {
try self.withNativeHandle { result in
try invokeFnReturningStringArray {
signal_message_backup_validation_outcome_get_unknown_fields($0, result)
}
}
}
}
return MessageBackupUnknownFields(fields: fields)
}
return MessageBackupUnknownFields(fields: fields)
}
public var errorMessage: String? {
try! self.withNativeHandle { result in
try invokeFnReturningOptionalString {
signal_message_backup_validation_outcome_get_error_message($0, result)
}
public var errorMessage: String? {
try! self.withNativeHandle { result in
try invokeFnReturningOptionalString {
signal_message_backup_validation_outcome_get_error_message($0, result)
}
}
}
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
signal_message_backup_validation_outcome_destroy(handle)
}
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
signal_message_backup_validation_outcome_destroy(handle)
}
}

View File

@ -16,7 +16,7 @@ public class NativeHandleOwner {
/// You should probably use `withNativeHandle(_:)`
/// unless you can't use block scoping to keep the owner (`self`) alive.
internal var unsafeNativeHandle: OpaquePointer? {
switch handle {
switch self.handle {
case nil:
return nil
case .borrowed(let handle)?:
@ -26,7 +26,7 @@ public class NativeHandleOwner {
}
}
required internal init(owned handle: OpaquePointer) {
internal required init(owned handle: OpaquePointer) {
self.handle = .owned(handle)
}
@ -34,7 +34,7 @@ public class NativeHandleOwner {
self.handle = handle.map { .borrowed($0) }
}
internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
internal class func destroyNativeHandle(_: OpaquePointer) -> SignalFfiErrorRef? {
fatalError("must be implemented by subclasses")
}
@ -61,7 +61,7 @@ public class NativeHandleOwner {
}
@available(*, unavailable, message: "use the method form instead")
internal func withNativeHandle<Result>(_ a: NativeHandleOwner, _ callback: (OpaquePointer?) throws -> Result) rethrows -> Result {
internal func withNativeHandle<Result>(_: NativeHandleOwner, _: (OpaquePointer?) throws -> Result) rethrows -> Result {
fatalError()
}
@ -96,11 +96,11 @@ internal func withNativeHandles<Result>(_ a: NativeHandleOwner, _ b: NativeHandl
}
public class ClonableHandleOwner: NativeHandleOwner {
required internal init(owned handle: OpaquePointer) {
internal required init(owned handle: OpaquePointer) {
super.init(owned: handle)
}
internal override init(borrowing handle: OpaquePointer?) {
override internal init(borrowing handle: OpaquePointer?) {
super.init(borrowing: handle)
}

View File

@ -91,15 +91,15 @@ public class Net {
) async throws -> CdsiLookup {
let timeoutMs = durationToMillis(timeout)
let handle: OpaquePointer = try await invokeAsyncFunction { promise, context in
asyncContext.withNativeHandle { asyncContext in
connectionManager.withNativeHandle { connectionManager in
self.asyncContext.withNativeHandle { asyncContext in
self.connectionManager.withNativeHandle { connectionManager in
request.withNativeHandle { request in
signal_cdsi_lookup_new(promise, context, asyncContext, connectionManager, auth.username, auth.password, request, timeoutMs)
}
}
}
}
return CdsiLookup(native: handle, asyncContext: asyncContext)
return CdsiLookup(native: handle, asyncContext: self.asyncContext)
}
private var asyncContext: TokioAsyncContext
@ -150,7 +150,8 @@ public class CdsiLookupRequest: NativeHandleOwner {
prevE164s: [String],
acisAndAccessKeys: [AciAndAccessKey],
token: Data?,
returnAcisWithoutUaks: Bool) throws {
returnAcisWithoutUaks: Bool
) throws {
self.init()
try self.withNativeHandle { handle in
for e164 in e164s {
@ -182,7 +183,7 @@ public class CdsiLookupRequest: NativeHandleOwner {
}
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
signal_lookup_request_destroy(handle)
}
}
@ -192,7 +193,7 @@ public class CdsiLookupRequest: NativeHandleOwner {
/// Returned by ``Net/cdsiLookup(auth:request:timeout:)`` when a request is successfully initiated.
public class CdsiLookup {
class NativeCdsiLookup: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
signal_cdsi_lookup_destroy(handle)
}
}
@ -212,10 +213,10 @@ public class CdsiLookup {
/// numbers.
public var token: Data {
failOnError {
try native.withNativeHandle { handle in
try invokeFnReturningData {
signal_cdsi_lookup_token($0, handle)
}
try self.native.withNativeHandle { handle in
try invokeFnReturningData {
signal_cdsi_lookup_token($0, handle)
}
}
}
}
@ -232,8 +233,8 @@ public class CdsiLookup {
/// `SignalError.networkProtocolError` for a CDSI or attested connection protocol issue.
public func complete() async throws -> CdsiLookupResponse {
let response: SignalFfiCdsiLookupResponse = try await invokeAsyncFunction { promise, context in
asyncContext.withNativeHandle { asyncContext in
native.withNativeHandle { handle in
self.asyncContext.withNativeHandle { asyncContext in
self.native.withNativeHandle { handle in
signal_cdsi_lookup_complete(promise, context, asyncContext, handle)
}
}
@ -285,7 +286,7 @@ public class LookupResponseEntryList: Collection {
public subscript(bounds: Range<Index>) -> SubSequence { self.owned[bounds] }
}
let nilUuid = uuid_t(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
let nilUuid = uuid_t(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
/// Entry contained in a successful CDSI lookup response.
///
@ -336,7 +337,7 @@ internal class TokioAsyncContext: NativeHandleOwner {
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
signal_tokio_async_context_destroy(handle)
}
}
@ -348,7 +349,7 @@ internal class ConnectionManager: NativeHandleOwner {
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
signal_connection_manager_destroy(handle)
}
}

View File

@ -48,7 +48,7 @@ public func verifyLocalPin<Bytes: ContiguousBytes>(_ pin: Bytes, againstEncodedH
/// A hash of the pin that can be used to interact with a Secure Value Recovery service.
public class PinHash: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_pin_hash_destroy(handle)
}
@ -83,7 +83,6 @@ public class PinHash: NativeHandleOwner {
/// - parameter salt: A 32 byte salt
/// - returns: A `PinHash`
public convenience init<PinBytes: ContiguousBytes, SaltBytes: ContiguousBytes>(normalizedPin: PinBytes, salt: SaltBytes) throws {
var result: OpaquePointer?
try normalizedPin.withUnsafeBorrowedBuffer { pinBytes in
try salt.withUnsafeBytes { saltBytes in
@ -114,5 +113,4 @@ public class PinHash: NativeHandleOwner {
}
self.init(owned: result!)
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class PrivateKey: ClonableHandleOwner {
public convenience init<Bytes: ContiguousBytes>(_ bytes: Bytes) throws {
@ -24,11 +24,11 @@ public class PrivateKey: ClonableHandleOwner {
}
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_privatekey_clone(&newHandle, currentHandle)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_privatekey_destroy(handle)
}
@ -73,5 +73,4 @@ public class PrivateKey: ClonableHandleOwner {
}
}
}
}

View File

@ -3,15 +3,17 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public func signalEncrypt<Bytes: ContiguousBytes>(message: Bytes,
for address: ProtocolAddress,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
now: Date = Date(),
context: StoreContext) throws -> CiphertextMessage {
public func signalEncrypt<Bytes: ContiguousBytes>(
message: Bytes,
for address: ProtocolAddress,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
now: Date = Date(),
context: StoreContext
) throws -> CiphertextMessage {
return try address.withNativeHandle { addressHandle in
try message.withUnsafeBorrowedBuffer { messageBuffer in
try withSessionStore(sessionStore, context) { ffiSessionStore in
@ -25,11 +27,13 @@ public func signalEncrypt<Bytes: ContiguousBytes>(message: Bytes,
}
}
public func signalDecrypt(message: SignalMessage,
from address: ProtocolAddress,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
context: StoreContext) throws -> [UInt8] {
public func signalDecrypt(
message: SignalMessage,
from address: ProtocolAddress,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
context: StoreContext
) throws -> [UInt8] {
return try withNativeHandles(message, address) { messageHandle, addressHandle in
try withSessionStore(sessionStore, context) { ffiSessionStore in
try withIdentityKeyStore(identityStore, context) { ffiIdentityStore in
@ -41,14 +45,16 @@ public func signalDecrypt(message: SignalMessage,
}
}
public func signalDecryptPreKey(message: PreKeySignalMessage,
from address: ProtocolAddress,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
preKeyStore: PreKeyStore,
signedPreKeyStore: SignedPreKeyStore,
kyberPreKeyStore: KyberPreKeyStore,
context: StoreContext) throws -> [UInt8] {
public func signalDecryptPreKey(
message: PreKeySignalMessage,
from address: ProtocolAddress,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
preKeyStore: PreKeyStore,
signedPreKeyStore: SignedPreKeyStore,
kyberPreKeyStore: KyberPreKeyStore,
context: StoreContext
) throws -> [UInt8] {
return try withNativeHandles(message, address) { messageHandle, addressHandle in
try withSessionStore(sessionStore, context) { ffiSessionStore in
try withIdentityKeyStore(identityStore, context) { ffiIdentityStore in
@ -66,12 +72,14 @@ public func signalDecryptPreKey(message: PreKeySignalMessage,
}
}
public func processPreKeyBundle(_ bundle: PreKeyBundle,
for address: ProtocolAddress,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
now: Date = Date(),
context: StoreContext) throws {
public func processPreKeyBundle(
_ bundle: PreKeyBundle,
for address: ProtocolAddress,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
now: Date = Date(),
context: StoreContext
) throws {
return try withNativeHandles(bundle, address) { bundleHandle, addressHandle in
try withSessionStore(sessionStore, context) { ffiSessionStore in
try withIdentityKeyStore(identityStore, context) { ffiIdentityStore in
@ -81,11 +89,13 @@ public func processPreKeyBundle(_ bundle: PreKeyBundle,
}
}
public func groupEncrypt<Bytes: ContiguousBytes>(_ message: Bytes,
from sender: ProtocolAddress,
distributionId: UUID,
store: SenderKeyStore,
context: StoreContext) throws -> CiphertextMessage {
public func groupEncrypt<Bytes: ContiguousBytes>(
_ message: Bytes,
from sender: ProtocolAddress,
distributionId: UUID,
store: SenderKeyStore,
context: StoreContext
) throws -> CiphertextMessage {
return try sender.withNativeHandle { senderHandle in
try message.withUnsafeBorrowedBuffer { messageBuffer in
try withUnsafePointer(to: distributionId.uuid) { distributionId in
@ -99,10 +109,12 @@ public func groupEncrypt<Bytes: ContiguousBytes>(_ message: Bytes,
}
}
public func groupDecrypt<Bytes: ContiguousBytes>(_ message: Bytes,
from sender: ProtocolAddress,
store: SenderKeyStore,
context: StoreContext) throws -> [UInt8] {
public func groupDecrypt<Bytes: ContiguousBytes>(
_ message: Bytes,
from sender: ProtocolAddress,
store: SenderKeyStore,
context: StoreContext
) throws -> [UInt8] {
return try sender.withNativeHandle { senderHandle in
try message.withUnsafeBorrowedBuffer { messageBuffer in
try withSenderKeyStore(store, context) { ffiStore in
@ -114,15 +126,19 @@ public func groupDecrypt<Bytes: ContiguousBytes>(_ message: Bytes,
}
}
public func processSenderKeyDistributionMessage(_ message: SenderKeyDistributionMessage,
from sender: ProtocolAddress,
store: SenderKeyStore,
context: StoreContext) throws {
public func processSenderKeyDistributionMessage(
_ message: SenderKeyDistributionMessage,
from sender: ProtocolAddress,
store: SenderKeyStore,
context: StoreContext
) throws {
return try withNativeHandles(sender, message) { senderHandle, messageHandle in
try withSenderKeyStore(store, context) {
try checkError(signal_process_sender_key_distribution_message(senderHandle,
messageHandle,
$0))
try checkError(signal_process_sender_key_distribution_message(
senderHandle,
messageHandle,
$0
))
}
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class PublicKey: ClonableHandleOwner {
public convenience init<Bytes: ContiguousBytes>(_ bytes: Bytes) throws {
@ -16,11 +16,11 @@ public class PublicKey: ClonableHandleOwner {
self.init(owned: handle!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_publickey_destroy(handle)
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_publickey_clone(&newHandle, currentHandle)
}
@ -44,9 +44,8 @@ public class PublicKey: ClonableHandleOwner {
}
}
public func verifySignature<MessageBytes, SignatureBytes>(message: MessageBytes, signature: SignatureBytes) throws -> Bool
where MessageBytes: ContiguousBytes, SignatureBytes: ContiguousBytes {
var result: Bool = false
public func verifySignature(message: some ContiguousBytes, signature: some ContiguousBytes) throws -> Bool {
var result = false
try withNativeHandle { nativeHandle in
try message.withUnsafeBorrowedBuffer { messageBuffer in
try signature.withUnsafeBorrowedBuffer { signatureBuffer in

View File

@ -3,26 +3,32 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
@inlinable
public func sealedSenderEncrypt<Bytes: ContiguousBytes>(message: Bytes,
for address: ProtocolAddress,
from senderCert: SenderCertificate,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
context: StoreContext) throws -> [UInt8] {
let ciphertextMessage = try signalEncrypt(message: message,
for: address,
sessionStore: sessionStore,
identityStore: identityStore,
context: context)
public func sealedSenderEncrypt<Bytes: ContiguousBytes>(
message: Bytes,
for address: ProtocolAddress,
from senderCert: SenderCertificate,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
context: StoreContext
) throws -> [UInt8] {
let ciphertextMessage = try signalEncrypt(
message: message,
for: address,
sessionStore: sessionStore,
identityStore: identityStore,
context: context
)
let usmc = try UnidentifiedSenderMessageContent(ciphertextMessage,
from: senderCert,
contentHint: .default,
groupId: [])
let usmc = try UnidentifiedSenderMessageContent(
ciphertextMessage,
from: senderCert,
contentHint: .default,
groupId: []
)
return try sealedSenderEncrypt(usmc, for: address, identityStore: identityStore, context: context)
}
@ -41,17 +47,21 @@ public class UnidentifiedSenderMessageContent: NativeHandleOwner {
public static var `default`: Self {
return Self(SignalContentHintDefault)
}
public static var resendable: Self {
return Self(SignalContentHintResendable)
}
public static var implicit: Self {
return Self(SignalContentHintImplicit)
}
}
public convenience init<Bytes: ContiguousBytes>(message sealedSenderMessage: Bytes,
identityStore: IdentityKeyStore,
context: StoreContext) throws {
public convenience init<Bytes: ContiguousBytes>(
message sealedSenderMessage: Bytes,
identityStore: IdentityKeyStore,
context: StoreContext
) throws {
var result: OpaquePointer?
try sealedSenderMessage.withUnsafeBorrowedBuffer { messageBuffer in
try withIdentityKeyStore(identityStore, context) { ffiIdentityStore in
@ -59,31 +69,36 @@ public class UnidentifiedSenderMessageContent: NativeHandleOwner {
signal_sealed_session_cipher_decrypt_to_usmc(
&result,
messageBuffer,
ffiIdentityStore))
ffiIdentityStore
))
}
}
self.init(owned: result!)
}
public convenience init<GroupIdBytes: ContiguousBytes>(_ message: CiphertextMessage,
from sender: SenderCertificate,
contentHint: ContentHint,
groupId: GroupIdBytes) throws {
public convenience init<GroupIdBytes: ContiguousBytes>(
_ message: CiphertextMessage,
from sender: SenderCertificate,
contentHint: ContentHint,
groupId: GroupIdBytes
) throws {
var result: OpaquePointer?
try withNativeHandles(message, sender) { messageHandle, senderHandle in
try groupId.withUnsafeBorrowedBuffer { groupIdBuffer in
try checkError(
signal_unidentified_sender_message_content_new(&result,
messageHandle,
senderHandle,
contentHint.rawValue,
groupIdBuffer))
signal_unidentified_sender_message_content_new(
&result,
messageHandle,
senderHandle,
contentHint.rawValue,
groupIdBuffer
))
}
}
self.init(owned: result!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_unidentified_sender_message_content_destroy(handle)
}
@ -144,28 +159,34 @@ public class UnidentifiedSenderMessageContent: NativeHandleOwner {
}
}
public func sealedSenderEncrypt(_ content: UnidentifiedSenderMessageContent,
for recipient: ProtocolAddress,
identityStore: IdentityKeyStore,
context: StoreContext) throws -> [UInt8] {
public func sealedSenderEncrypt(
_ content: UnidentifiedSenderMessageContent,
for recipient: ProtocolAddress,
identityStore: IdentityKeyStore,
context: StoreContext
) throws -> [UInt8] {
return try withNativeHandles(recipient, content) { recipientHandle, contentHandle in
try withIdentityKeyStore(identityStore, context) { ffiIdentityStore in
try invokeFnReturningArray {
signal_sealed_session_cipher_encrypt($0,
recipientHandle,
contentHandle,
ffiIdentityStore)
signal_sealed_session_cipher_encrypt(
$0,
recipientHandle,
contentHandle,
ffiIdentityStore
)
}
}
}
}
public func sealedSenderMultiRecipientEncrypt(_ content: UnidentifiedSenderMessageContent,
for recipients: [ProtocolAddress],
excludedRecipients: [ServiceId] = [],
identityStore: IdentityKeyStore,
sessionStore: SessionStore,
context: StoreContext) throws -> [UInt8] {
public func sealedSenderMultiRecipientEncrypt(
_ content: UnidentifiedSenderMessageContent,
for recipients: [ProtocolAddress],
excludedRecipients: [ServiceId] = [],
identityStore: IdentityKeyStore,
sessionStore: SessionStore,
context: StoreContext
) throws -> [UInt8] {
let sessions = try sessionStore.loadExistingSessions(for: recipients, context: context)
// Use withExtendedLifetime instead of withNativeHandle for the arrays of wrapper objects,
// which aren't compatible with withNativeHandle's simple lexical scoping.
@ -173,19 +194,21 @@ public func sealedSenderMultiRecipientEncrypt(_ content: UnidentifiedSenderMessa
let recipientHandles = recipients.map { $0.unsafeNativeHandle }
let sessionHandles = sessions.map { $0.unsafeNativeHandle }
return try content.withNativeHandle { contentHandle in
return try recipientHandles.withUnsafeBufferPointer { recipientHandles in
try recipientHandles.withUnsafeBufferPointer { recipientHandles in
let recipientHandlesBuffer = SignalBorrowedSliceOfProtocolAddress(base: recipientHandles.baseAddress, length: recipientHandles.count)
return try sessionHandles.withUnsafeBufferPointer { sessionHandles in
let sessionHandlesBuffer = SignalBorrowedSliceOfSessionRecord(base: sessionHandles.baseAddress, length: sessionHandles.count)
return try ServiceId.concatenatedFixedWidthBinary(excludedRecipients).withUnsafeBorrowedBuffer { excludedRecipientsBuffer in
return try withIdentityKeyStore(identityStore, context) { ffiIdentityStore in
try withIdentityKeyStore(identityStore, context) { ffiIdentityStore in
try invokeFnReturningArray {
signal_sealed_sender_multi_recipient_encrypt($0,
recipientHandlesBuffer,
sessionHandlesBuffer,
excludedRecipientsBuffer,
contentHandle,
ffiIdentityStore)
signal_sealed_sender_multi_recipient_encrypt(
$0,
recipientHandlesBuffer,
sessionHandlesBuffer,
excludedRecipientsBuffer,
contentHandle,
ffiIdentityStore
)
}
}
}
@ -225,7 +248,7 @@ public struct SealedSenderAddress: Hashable {
///
/// In a future release SealedSenderAddress will *only* support ACIs.
public var senderAci: Aci! {
return try? Aci.parseFrom(serviceIdString: uuidString)
return try? Aci.parseFrom(serviceIdString: self.uuidString)
}
}
@ -234,15 +257,17 @@ public struct SealedSenderResult {
public var sender: SealedSenderAddress
}
public func sealedSenderDecrypt<Bytes: ContiguousBytes>(message: Bytes,
from localAddress: SealedSenderAddress,
trustRoot: PublicKey,
timestamp: UInt64,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
preKeyStore: PreKeyStore,
signedPreKeyStore: SignedPreKeyStore,
context: StoreContext) throws -> SealedSenderResult {
public func sealedSenderDecrypt<Bytes: ContiguousBytes>(
message: Bytes,
from localAddress: SealedSenderAddress,
trustRoot: PublicKey,
timestamp: UInt64,
sessionStore: SessionStore,
identityStore: IdentityKeyStore,
preKeyStore: PreKeyStore,
signedPreKeyStore: SignedPreKeyStore,
context: StoreContext
) throws -> SealedSenderResult {
var senderE164: UnsafePointer<CChar>?
var senderUUID: UnsafePointer<CChar>?
var senderDeviceId: UInt32 = 0
@ -268,7 +293,8 @@ public func sealedSenderDecrypt<Bytes: ContiguousBytes>(message: Bytes,
ffiSessionStore,
ffiIdentityStore,
ffiPreKeyStore,
ffiSignedPreKeyStore)
ffiSignedPreKeyStore
)
}
}
}
@ -282,8 +308,12 @@ public func sealedSenderDecrypt<Bytes: ContiguousBytes>(message: Bytes,
signal_free_string(senderUUID)
}
return SealedSenderResult(message: plaintext,
sender: try SealedSenderAddress(e164: senderE164.map(String.init(cString:)),
uuidString: String(cString: senderUUID!),
deviceId: senderDeviceId))
return SealedSenderResult(
message: plaintext,
sender: try SealedSenderAddress(
e164: senderE164.map(String.init(cString:)),
uuidString: String(cString: senderUUID!),
deviceId: senderDeviceId
)
)
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class ServerCertificate: NativeHandleOwner {
public convenience init<Bytes: ContiguousBytes>(_ bytes: Bytes) throws {
@ -25,7 +25,7 @@ public class ServerCertificate: NativeHandleOwner {
self.init(owned: result!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_server_certificate_destroy(handle)
}
@ -94,19 +94,21 @@ public class SenderCertificate: NativeHandleOwner {
public convenience init(sender: SealedSenderAddress, publicKey: PublicKey, expiration: UInt64, signerCertificate: ServerCertificate, signerKey: PrivateKey) throws {
var result: OpaquePointer?
try withNativeHandles(publicKey, signerCertificate, signerKey) { publicKeyHandle, signerCertificateHandle, signerKeyHandle in
try checkError(signal_sender_certificate_new(&result,
sender.uuidString,
sender.e164,
sender.deviceId,
publicKeyHandle,
expiration,
signerCertificateHandle,
signerKeyHandle))
try checkError(signal_sender_certificate_new(
&result,
sender.uuidString,
sender.e164,
sender.deviceId,
publicKeyHandle,
expiration,
signerCertificateHandle,
signerKeyHandle
))
}
self.init(owned: result!)
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_sender_certificate_destroy(handle)
}
@ -184,7 +186,7 @@ public class SenderCertificate: NativeHandleOwner {
///
/// In a future release SenderCertificate will *only* support ACIs.
public var senderAci: Aci! {
return try? Aci.parseFrom(serviceIdString: senderUuid)
return try? Aci.parseFrom(serviceIdString: self.senderUuid)
}
public var senderE164: String? {
@ -214,7 +216,7 @@ public class SenderCertificate: NativeHandleOwner {
}
public func validate(trustRoot: PublicKey, time: UInt64) throws -> Bool {
var result: Bool = false
var result = false
try withNativeHandles(self, trustRoot) { certificateHandle, trustRootHandle in
try checkError(signal_sender_certificate_validate(&result, certificateHandle, trustRootHandle, time))
}

View File

@ -43,7 +43,7 @@ public enum ServiceIdError: Error {
}
public class ServiceId {
fileprivate var storage: ServiceIdStorage = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
private var storage: ServiceIdStorage = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
fileprivate init(fromFixedWidthBinary storage: ServiceIdStorage) {
self.storage = storage
@ -187,7 +187,7 @@ public class Aci: ServiceId {
super.init(.aci, uuid)
}
internal override init(fromFixedWidthBinary bytes: ServiceIdStorage) {
override internal init(fromFixedWidthBinary bytes: ServiceIdStorage) {
super.init(fromFixedWidthBinary: bytes)
}
}
@ -197,7 +197,7 @@ public class Pni: ServiceId {
super.init(.pni, uuid)
}
internal override init(fromFixedWidthBinary bytes: ServiceIdStorage) {
override internal init(fromFixedWidthBinary bytes: ServiceIdStorage) {
super.init(fromFixedWidthBinary: bytes)
}
}

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
///
/// SgxClient provides bindings to interact with a Signal SGX service
@ -25,8 +25,7 @@ import Foundation
/// which decrypts and verifies it, passing the plaintext back to the client for processing.
///
public class SgxClient: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_sgx_client_state_destroy(handle)
}

View File

@ -11,15 +11,20 @@ import SignalFfi
///
/// See ``SgxClient``
public class Svr2Client: SgxClient {
public convenience init<MrenclaveBytes, AttestationBytes>(mrenclave: MrenclaveBytes, attestationMessage: AttestationBytes, currentDate: Date) throws
where MrenclaveBytes: ContiguousBytes, AttestationBytes: ContiguousBytes {
public convenience init(
mrenclave: some ContiguousBytes,
attestationMessage: some ContiguousBytes,
currentDate: Date
) throws {
let handle: OpaquePointer? = try attestationMessage.withUnsafeBorrowedBuffer { attestationMessageBuffer in
try mrenclave.withUnsafeBorrowedBuffer { mrenclaveBuffer in
var result: OpaquePointer?
try checkError(signal_svr2_client_new(&result,
mrenclaveBuffer,
attestationMessageBuffer,
UInt64(currentDate.timeIntervalSince1970 * 1000)))
try checkError(signal_svr2_client_new(
&result,
mrenclaveBuffer,
attestationMessageBuffer,
UInt64(currentDate.timeIntervalSince1970 * 1000)
))
return result
}
}

View File

@ -62,7 +62,7 @@ public struct Username {
public func createLink(previousEntropy: [UInt8]? = nil) throws -> ([UInt8], [UInt8]) {
let bytes = failOnError {
return try self.value.withCString { usernamePtr in
try self.value.withCString { usernamePtr in
try (previousEntropy ?? []).withUnsafeBorrowedBuffer { entropyPtr in
try invokeFnReturningArray {
signal_username_link_create($0, usernamePtr, entropyPtr)
@ -84,8 +84,8 @@ public struct Username {
}
public static func candidates(
from nickname: String,
withValidLengthWithin lengthRange: ClosedRange<UInt32> = 3...32
from nickname: String,
withValidLengthWithin lengthRange: ClosedRange<UInt32> = 3...32
) throws -> [Username] {
let allCandidates = try nickname.withCString { nicknamePtr in
try invokeFnReturningStringArray {
@ -98,11 +98,11 @@ public struct Username {
extension Username: CustomStringConvertible {
public var description: String {
return value
return self.value
}
}
extension Username: Equatable { }
extension Username: Equatable {}
private func generateHash(_ s: String) throws -> [UInt8] {
try s.withCString { strPtr in

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
#if canImport(Security)
import Security
@ -114,7 +114,7 @@ internal func invokeFnReturningInteger<Result: FixedWidthInteger>(fn: (UnsafeMut
}
internal func invokeFnReturningBool(fn: (UnsafeMutablePointer<Bool>?) -> SignalFfiErrorRef?) throws -> Bool {
var output: Bool = false
var output = false
try checkError(fn(&output))
return output
}
@ -161,7 +161,7 @@ internal func fillRandom(_ buffer: UnsafeMutableRawBufferPointer) throws {
#if canImport(Security)
let result = SecRandomCopyBytes(kSecRandomDefault, buffer.count, baseAddress)
guard result == errSecSuccess else {
throw SignalError.internalError("SecRandomCopyBytes failed (error code \(result))")
throw SignalError.internalError("SecRandomCopyBytes failed (error code \(result))")
}
#else
for i in buffer.indices {

View File

@ -19,18 +19,21 @@ public class CiphertextMessage: NativeHandleOwner {
public static var whisper: Self {
return Self(SignalCiphertextMessageTypeWhisper)
}
public static var preKey: Self {
return Self(SignalCiphertextMessageTypePreKey)
}
public static var senderKey: Self {
return Self(SignalCiphertextMessageTypeSenderKey)
}
public static var plaintext: Self {
return Self(SignalCiphertextMessageTypePlaintext)
}
}
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_ciphertext_message_destroy(handle)
}

View File

@ -3,11 +3,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class PlaintextContent: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_plaintext_content_destroy(handle)
}
@ -49,7 +49,7 @@ public class PlaintextContent: NativeHandleOwner {
}
public class DecryptionErrorMessage: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_decryption_error_message_destroy(handle)
}

View File

@ -3,11 +3,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class PreKeySignalMessage: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_pre_key_signal_message_destroy(handle)
}
@ -50,7 +50,7 @@ public class PreKeySignalMessage: NativeHandleOwner {
}
}
if id == 0xFFFFFFFF {
if id == 0xFFFF_FFFF {
return nil
} else {
return id

View File

@ -3,26 +3,30 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class SenderKeyDistributionMessage: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_sender_key_distribution_message_destroy(handle)
}
public convenience init(from sender: ProtocolAddress,
distributionId: UUID,
store: SenderKeyStore,
context: StoreContext) throws {
public convenience init(
from sender: ProtocolAddress,
distributionId: UUID,
store: SenderKeyStore,
context: StoreContext
) throws {
var result: OpaquePointer?
try sender.withNativeHandle { senderHandle in
try withUnsafePointer(to: distributionId.uuid) { distributionId in
try withSenderKeyStore(store, context) {
try checkError(signal_sender_key_distribution_message_create(&result,
senderHandle,
distributionId,
$0))
try checkError(signal_sender_key_distribution_message_create(
&result,
senderHandle,
distributionId,
$0
))
}
}
}

View File

@ -3,11 +3,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class SenderKeyMessage: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_sender_key_message_destroy(handle)
}
@ -70,7 +70,7 @@ public class SenderKeyMessage: NativeHandleOwner {
}
public func verifySignature(against key: PublicKey) throws -> Bool {
var result: Bool = false
var result = false
try withNativeHandles(self, key) { messageHandle, keyHandle in
try checkError(signal_sender_key_message_verify_signature(&result, messageHandle, keyHandle))
}

View File

@ -3,11 +3,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class SignalMessage: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_message_destroy(handle)
}
@ -69,17 +69,21 @@ public class SignalMessage: NativeHandleOwner {
}
}
public func verifyMac<Bytes: ContiguousBytes>(sender: PublicKey,
receiver: PublicKey,
macKey: Bytes) throws -> Bool {
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))
try checkError(signal_message_verify_mac(
&result,
messageHandle,
senderHandle,
receiverHandle,
$0
))
return result
}
}

View File

@ -3,15 +3,15 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class KyberPreKeyRecord: ClonableHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_kyber_pre_key_record_destroy(handle)
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_kyber_pre_key_record_clone(&newHandle, currentHandle)
}

View File

@ -3,39 +3,43 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class PreKeyBundle: NativeHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_pre_key_bundle_destroy(handle)
}
// with a prekey
public convenience init<Bytes: ContiguousBytes>(registrationId: UInt32,
deviceId: UInt32,
prekeyId: UInt32,
prekey: PublicKey,
signedPrekeyId: UInt32,
signedPrekey: PublicKey,
signedPrekeySignature: Bytes,
identity identityKey: IdentityKey) throws {
public convenience init<Bytes: ContiguousBytes>(
registrationId: UInt32,
deviceId: UInt32,
prekeyId: UInt32,
prekey: PublicKey,
signedPrekeyId: UInt32,
signedPrekey: PublicKey,
signedPrekeySignature: Bytes,
identity identityKey: IdentityKey
) throws {
var result: OpaquePointer?
try withNativeHandles(prekey, signedPrekey, identityKey.publicKey) { prekeyHandle, signedPrekeyHandle, identityKeyHandle in
try signedPrekeySignature.withUnsafeBorrowedBuffer { signedSignatureBuffer in
try [].withUnsafeBorrowedBuffer { kyberSignatureBuffer in
try checkError(signal_pre_key_bundle_new(&result,
registrationId,
deviceId,
prekeyId,
prekeyHandle,
signedPrekeyId,
signedPrekeyHandle,
signedSignatureBuffer,
identityKeyHandle,
~0,
nil,
kyberSignatureBuffer))
try checkError(signal_pre_key_bundle_new(
&result,
registrationId,
deviceId,
prekeyId,
prekeyHandle,
signedPrekeyId,
signedPrekeyHandle,
signedSignatureBuffer,
identityKeyHandle,
~0,
nil,
kyberSignatureBuffer
))
}
}
}
@ -43,28 +47,32 @@ public class PreKeyBundle: NativeHandleOwner {
}
// without a prekey
public convenience init<Bytes: ContiguousBytes>(registrationId: UInt32,
deviceId: UInt32,
signedPrekeyId: UInt32,
signedPrekey: PublicKey,
signedPrekeySignature: Bytes,
identity identityKey: IdentityKey) throws {
public convenience init<Bytes: ContiguousBytes>(
registrationId: UInt32,
deviceId: UInt32,
signedPrekeyId: UInt32,
signedPrekey: PublicKey,
signedPrekeySignature: Bytes,
identity identityKey: IdentityKey
) throws {
var result: OpaquePointer?
try withNativeHandles(signedPrekey, identityKey.publicKey) { signedPrekeyHandle, identityKeyHandle in
try signedPrekeySignature.withUnsafeBorrowedBuffer { signedSignatureBuffer in
try [].withUnsafeBorrowedBuffer { kyberSignatureBuffer in
try checkError(signal_pre_key_bundle_new(&result,
registrationId,
deviceId,
~0,
nil,
signedPrekeyId,
signedPrekeyHandle,
signedSignatureBuffer,
identityKeyHandle,
~0,
nil,
kyberSignatureBuffer))
try checkError(signal_pre_key_bundle_new(
&result,
registrationId,
deviceId,
~0,
nil,
signedPrekeyId,
signedPrekeyHandle,
signedSignatureBuffer,
identityKeyHandle,
~0,
nil,
kyberSignatureBuffer
))
}
}
}
@ -87,23 +95,25 @@ public class PreKeyBundle: NativeHandleOwner {
kyberPrekeyId: UInt32,
kyberPrekey: KEMPublicKey,
kyberPrekeySignature: KEMBytes
) throws {
) throws {
var result: OpaquePointer?
try withNativeHandles(prekey, signedPrekey, identityKey.publicKey, kyberPrekey) { prekeyHandle, signedPrekeyHandle, identityKeyHandle, kyberKeyHandle in
try signedPrekeySignature.withUnsafeBorrowedBuffer { ecSignatureBuffer in
try kyberPrekeySignature.withUnsafeBorrowedBuffer { kyberSignatureBuffer in
try checkError(signal_pre_key_bundle_new(&result,
registrationId,
deviceId,
prekeyId,
prekeyHandle,
signedPrekeyId,
signedPrekeyHandle,
ecSignatureBuffer,
identityKeyHandle,
kyberPrekeyId,
kyberKeyHandle,
kyberSignatureBuffer))
try checkError(signal_pre_key_bundle_new(
&result,
registrationId,
deviceId,
prekeyId,
prekeyHandle,
signedPrekeyId,
signedPrekeyHandle,
ecSignatureBuffer,
identityKeyHandle,
kyberPrekeyId,
kyberKeyHandle,
kyberSignatureBuffer
))
}
}
}
@ -124,23 +134,25 @@ public class PreKeyBundle: NativeHandleOwner {
kyberPrekeyId: UInt32,
kyberPrekey: KEMPublicKey,
kyberPrekeySignature: KEMBytes
) throws {
) throws {
var result: OpaquePointer?
try withNativeHandles(signedPrekey, identityKey.publicKey, kyberPrekey) { signedPrekeyHandle, identityKeyHandle, kyberKeyHandle in
try signedPrekeySignature.withUnsafeBorrowedBuffer { ecSignatureBuffer in
try kyberPrekeySignature.withUnsafeBorrowedBuffer { kyberSignatureBuffer in
try checkError(signal_pre_key_bundle_new(&result,
registrationId,
deviceId,
~0,
nil,
signedPrekeyId,
signedPrekeyHandle,
ecSignatureBuffer,
identityKeyHandle,
kyberPrekeyId,
kyberKeyHandle,
kyberSignatureBuffer))
try checkError(signal_pre_key_bundle_new(
&result,
registrationId,
deviceId,
~0,
nil,
signedPrekeyId,
signedPrekeyHandle,
ecSignatureBuffer,
identityKeyHandle,
kyberPrekeyId,
kyberKeyHandle,
kyberSignatureBuffer
))
}
}
}

View File

@ -3,15 +3,15 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class PreKeyRecord: ClonableHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_pre_key_record_destroy(handle)
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_pre_key_record_clone(&newHandle, currentHandle)
}
@ -24,9 +24,11 @@ public class PreKeyRecord: ClonableHandleOwner {
self.init(owned: handle!)
}
public convenience init(id: UInt32,
publicKey: PublicKey,
privateKey: PrivateKey) throws {
public convenience init(
id: UInt32,
publicKey: PublicKey,
privateKey: PrivateKey
) throws {
var handle: OpaquePointer?
try withNativeHandles(publicKey, privateKey) { publicKeyHandle, privateKeyHandle in
try checkError(signal_pre_key_record_new(&handle, id, publicKeyHandle, privateKeyHandle))

View File

@ -3,15 +3,15 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class SenderKeyRecord: ClonableHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_sender_key_record_destroy(handle)
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_sender_key_record_clone(&newHandle, currentHandle)
}

View File

@ -3,15 +3,15 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class SessionRecord: ClonableHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_session_record_destroy(handle)
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_session_record_clone(&newHandle, currentHandle)
}
@ -61,7 +61,7 @@ public class SessionRecord: ClonableHandleOwner {
}
public func currentRatchetKeyMatches(_ key: PublicKey) throws -> Bool {
var result: Bool = false
var result = false
try withNativeHandles(self, key) { sessionHandle, keyHandle in
try checkError(signal_session_record_current_ratchet_key_matches(&result, sessionHandle, keyHandle))
}

View File

@ -3,15 +3,15 @@
// SPDX-License-Identifier: AGPL-3.0-only
//
import SignalFfi
import Foundation
import SignalFfi
public class SignedPreKeyRecord: ClonableHandleOwner {
internal override class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
override internal class func destroyNativeHandle(_ handle: OpaquePointer) -> SignalFfiErrorRef? {
return signal_signed_pre_key_record_destroy(handle)
}
internal override class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
override internal class func cloneNativeHandle(_ newHandle: inout OpaquePointer?, currentHandle: OpaquePointer?) -> SignalFfiErrorRef? {
return signal_signed_pre_key_record_clone(&newHandle, currentHandle)
}
@ -24,17 +24,24 @@ public class SignedPreKeyRecord: ClonableHandleOwner {
self.init(owned: handle!)
}
public convenience init<Bytes: ContiguousBytes>(id: UInt32,
timestamp: UInt64,
privateKey: PrivateKey,
signature: Bytes) throws {
public convenience init<Bytes: ContiguousBytes>(
id: UInt32,
timestamp: UInt64,
privateKey: PrivateKey,
signature: Bytes
) throws {
let publicKey = privateKey.publicKey
var result: OpaquePointer?
try withNativeHandles(publicKey, privateKey) { publicKeyHandle, privateKeyHandle in
try signature.withUnsafeBorrowedBuffer {
try checkError(signal_signed_pre_key_record_new(&result, id, timestamp,
publicKeyHandle, privateKeyHandle,
$0))
try checkError(signal_signed_pre_key_record_new(
&result,
id,
timestamp,
publicKeyHandle,
privateKeyHandle,
$0
))
}
}
self.init(owned: result!)

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class AuthCredential: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_check_valid_contents)
}
}

View File

@ -7,34 +7,32 @@ import Foundation
import SignalFfi
public class AuthCredentialPresentation: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_presentation_check_valid_contents)
}
public func getUuidCiphertext() throws -> UuidCiphertext {
return try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningSerialized {
signal_auth_credential_presentation_get_uuid_ciphertext($0, buffer)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_presentation_check_valid_contents)
}
}
public func getPniCiphertext() throws -> UuidCiphertext? {
return try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningOptionalVariableLengthSerialized {
signal_auth_credential_presentation_get_pni_ciphertext_or_empty($0, buffer)
}
public func getUuidCiphertext() throws -> UuidCiphertext {
return try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningSerialized {
signal_auth_credential_presentation_get_uuid_ciphertext($0, buffer)
}
}
}
}
public func getRedemptionTime() throws -> Date {
let secondsSinceEpoch = try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningInteger {
signal_auth_credential_presentation_get_redemption_time($0, buffer)
}
public func getPniCiphertext() throws -> UuidCiphertext? {
return try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningOptionalVariableLengthSerialized {
signal_auth_credential_presentation_get_pni_ciphertext_or_empty($0, buffer)
}
}
}
return Date(timeIntervalSince1970: TimeInterval(secondsSinceEpoch))
}
public func getRedemptionTime() throws -> Date {
let secondsSinceEpoch = try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningInteger {
signal_auth_credential_presentation_get_redemption_time($0, buffer)
}
}
return Date(timeIntervalSince1970: TimeInterval(secondsSinceEpoch))
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class AuthCredentialResponse: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_response_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_response_check_valid_contents)
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class AuthCredentialWithPni: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_with_pni_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_with_pni_check_valid_contents)
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class AuthCredentialWithPniResponse: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_with_pni_response_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_auth_credential_with_pni_response_check_valid_contents)
}
}

View File

@ -7,14 +7,13 @@ import Foundation
import SignalFfi
public class BackupAuthCredential: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_backup_auth_credential_check_valid_contents)
}
public func present(serverParams: GenericServerPublicParams) -> BackupAuthCredentialPresentation {
return failOnError {
present(serverParams: serverParams, randomness: try .generate())
self.present(serverParams: serverParams, randomness: try .generate())
}
}

View File

@ -7,7 +7,6 @@ import Foundation
import SignalFfi
public class BackupAuthCredentialPresentation: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_backup_auth_credential_presentation_check_valid_contents)
}

View File

@ -13,7 +13,7 @@ public class BackupAuthCredentialRequest: ByteArray {
public func issueCredential(timestamp: Date, receiptLevel: UInt64, params: GenericServerSecretParams) -> BackupAuthCredentialResponse {
return failOnError {
issueCredential(timestamp: timestamp, receiptLevel: receiptLevel, params: params, randomness: try .generate())
self.issueCredential(timestamp: timestamp, receiptLevel: receiptLevel, params: params, randomness: try .generate())
}
}

View File

@ -7,7 +7,6 @@ import Foundation
import SignalFfi
public class BackupAuthCredentialRequestContext: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_backup_auth_credential_request_context_check_valid_contents)
}
@ -47,5 +46,4 @@ public class BackupAuthCredentialRequestContext: ByteArray {
}
}
}
}

View File

@ -10,8 +10,8 @@ public class ByteArray {
private let contents: [UInt8]
init(_ newContents: [UInt8], checkValid: (SignalBorrowedBuffer) -> SignalFfiErrorRef?) throws {
contents = newContents
try withUnsafeBorrowedBuffer { buffer in
self.contents = newContents
try self.withUnsafeBorrowedBuffer { buffer in
try checkError(checkValid(buffer))
}
}
@ -20,7 +20,7 @@ public class ByteArray {
if newContents.count != expectedLength {
throw SignalError.invalidType("\(type(of: self)) uses \(expectedLength) bytes, but tried to deserialize from an array of \(newContents.count) bytes")
}
contents = newContents
self.contents = newContents
}
required init(contents: [UInt8]) throws {
@ -28,7 +28,7 @@ public class ByteArray {
}
public func serialize() -> [UInt8] {
return contents
return self.contents
}
/// Passes a pointer to the serialized contents to `callback`.
@ -45,7 +45,7 @@ public class ByteArray {
func withUnsafePointerToSerialized<Serialized, Result>(_ callback: (UnsafePointer<Serialized>) throws -> Result) throws -> Result {
precondition(MemoryLayout<Serialized>.alignment == 1, "not a fixed-sized array (tuple) of UInt8")
return try contents.withUnsafeBytes { buffer in
return try self.contents.withUnsafeBytes { buffer in
let expectedSize = MemoryLayout<Serialized>.size
guard expectedSize == buffer.count else {
throw SignalError.invalidType("\(type(of: self)) uses \(buffer.count) bytes, but was passed to a callback that uses \(expectedSize) bytes")
@ -64,6 +64,6 @@ public class ByteArray {
///
/// Used for types that don't have a fixed-length representation.
func withUnsafeBorrowedBuffer<Result>(_ callback: (SignalBorrowedBuffer) throws -> Result) throws -> Result {
return try contents.withUnsafeBorrowedBuffer(callback)
return try self.contents.withUnsafeBorrowedBuffer(callback)
}
}

View File

@ -7,33 +7,31 @@ import Foundation
import SignalFfi
public class CallLinkAuthCredential: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_auth_credential_check_valid_contents)
}
public func present(userId: Aci, redemptionTime: Date, serverParams: GenericServerPublicParams, callLinkParams: CallLinkSecretParams) -> CallLinkAuthCredentialPresentation {
return failOnError {
present(userId: userId, redemptionTime: redemptionTime, serverParams: serverParams, callLinkParams: callLinkParams, randomness: try .generate())
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_auth_credential_check_valid_contents)
}
}
public func present(userId: Aci, redemptionTime: Date, serverParams: GenericServerPublicParams, callLinkParams: CallLinkSecretParams, randomness: Randomness) -> CallLinkAuthCredentialPresentation {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try userId.withPointerToFixedWidthBinary { userId in
try serverParams.withUnsafeBorrowedBuffer { serverParams in
try callLinkParams.withUnsafeBorrowedBuffer { callLinkParams in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_auth_credential_present_deterministic($0, contents, userId, UInt64(redemptionTime.timeIntervalSince1970), serverParams, callLinkParams, randomness)
}
}
}
}
public func present(userId: Aci, redemptionTime: Date, serverParams: GenericServerPublicParams, callLinkParams: CallLinkSecretParams) -> CallLinkAuthCredentialPresentation {
return failOnError {
self.present(userId: userId, redemptionTime: redemptionTime, serverParams: serverParams, callLinkParams: callLinkParams, randomness: try .generate())
}
}
}
}
public func present(userId: Aci, redemptionTime: Date, serverParams: GenericServerPublicParams, callLinkParams: CallLinkSecretParams, randomness: Randomness) -> CallLinkAuthCredentialPresentation {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try userId.withPointerToFixedWidthBinary { userId in
try serverParams.withUnsafeBorrowedBuffer { serverParams in
try callLinkParams.withUnsafeBorrowedBuffer { callLinkParams in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_auth_credential_present_deterministic($0, contents, userId, UInt64(redemptionTime.timeIntervalSince1970), serverParams, callLinkParams, randomness)
}
}
}
}
}
}
}
}
}

View File

@ -7,28 +7,27 @@ import Foundation
import SignalFfi
public class CallLinkAuthCredentialPresentation: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_auth_credential_presentation_check_valid_contents)
}
public func verify(now: Date = Date(), serverParams: GenericServerSecretParams, callLinkParams: CallLinkPublicParams) throws {
try withUnsafeBorrowedBuffer { contents in
try serverParams.withUnsafeBorrowedBuffer { serverParams in
try callLinkParams.withUnsafeBorrowedBuffer { callLinkParams in
try checkError(signal_call_link_auth_credential_presentation_verify(contents, UInt64(now.timeIntervalSince1970), serverParams, callLinkParams))
}
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_auth_credential_presentation_check_valid_contents)
}
}
public var userId: UuidCiphertext {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try invokeFnReturningSerialized {
signal_call_link_auth_credential_presentation_get_user_id($0, contents)
public func verify(now: Date = Date(), serverParams: GenericServerSecretParams, callLinkParams: CallLinkPublicParams) throws {
try withUnsafeBorrowedBuffer { contents in
try serverParams.withUnsafeBorrowedBuffer { serverParams in
try callLinkParams.withUnsafeBorrowedBuffer { callLinkParams in
try checkError(signal_call_link_auth_credential_presentation_verify(contents, UInt64(now.timeIntervalSince1970), serverParams, callLinkParams))
}
}
}
}
public var userId: UuidCiphertext {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try invokeFnReturningSerialized {
signal_call_link_auth_credential_presentation_get_user_id($0, contents)
}
}
}
}
}
}
}

View File

@ -7,39 +7,39 @@ import Foundation
import SignalFfi
public class CallLinkAuthCredentialResponse: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_auth_credential_response_check_valid_contents)
}
public static func issueCredential(userId: Aci, redemptionTime: Date, params: GenericServerSecretParams) -> CallLinkAuthCredentialResponse {
return failOnError {
issueCredential(userId: userId, redemptionTime: redemptionTime, params: params, randomness: try .generate())
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_auth_credential_response_check_valid_contents)
}
}
public static func issueCredential(userId: Aci, redemptionTime: Date, params: GenericServerSecretParams, randomness: Randomness) -> CallLinkAuthCredentialResponse {
return failOnError {
try userId.withPointerToFixedWidthBinary { userId in
try params.withUnsafeBorrowedBuffer { params in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_auth_credential_response_issue_deterministic($0, userId, UInt64(redemptionTime.timeIntervalSince1970), params, randomness)
public static func issueCredential(userId: Aci, redemptionTime: Date, params: GenericServerSecretParams) -> CallLinkAuthCredentialResponse {
return failOnError {
self.issueCredential(userId: userId, redemptionTime: redemptionTime, params: params, randomness: try .generate())
}
}
public static func issueCredential(userId: Aci, redemptionTime: Date, params: GenericServerSecretParams, randomness: Randomness) -> CallLinkAuthCredentialResponse {
return failOnError {
try userId.withPointerToFixedWidthBinary { userId in
try params.withUnsafeBorrowedBuffer { params in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_auth_credential_response_issue_deterministic($0, userId, UInt64(redemptionTime.timeIntervalSince1970), params, randomness)
}
}
}
}
}
}
}
}
}
public func receive(userId: Aci, redemptionTime: Date, params: GenericServerPublicParams) throws -> CallLinkAuthCredential {
return try withUnsafeBorrowedBuffer { contents in
try userId.withPointerToFixedWidthBinary { userId in
try params.withUnsafeBorrowedBuffer { params in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_auth_credential_response_receive($0, contents, userId, UInt64(redemptionTime.timeIntervalSince1970), params)
}
public func receive(userId: Aci, redemptionTime: Date, params: GenericServerPublicParams) throws -> CallLinkAuthCredential {
return try withUnsafeBorrowedBuffer { contents in
try userId.withPointerToFixedWidthBinary { userId in
try params.withUnsafeBorrowedBuffer { params in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_auth_credential_response_receive($0, contents, userId, UInt64(redemptionTime.timeIntervalSince1970), params)
}
}
}
}
}
}
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class CallLinkPublicParams: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_public_params_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_public_params_check_valid_contents)
}
}

View File

@ -7,39 +7,37 @@ import Foundation
import SignalFfi
public class CallLinkSecretParams: ByteArray {
public static func deriveFromRootKey<RootKey: ContiguousBytes>(_ rootKey: RootKey) -> CallLinkSecretParams {
return failOnError {
try rootKey.withUnsafeBorrowedBuffer { rootKey in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_secret_params_derive_from_root_key($0, rootKey)
public static func deriveFromRootKey<RootKey: ContiguousBytes>(_ rootKey: RootKey) -> CallLinkSecretParams {
return failOnError {
try rootKey.withUnsafeBorrowedBuffer { rootKey in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_secret_params_derive_from_root_key($0, rootKey)
}
}
}
}
}
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_secret_params_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_call_link_secret_params_check_valid_contents)
}
public func getPublicParams() -> CallLinkPublicParams {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_secret_params_get_public_params($0, contents)
public func getPublicParams() -> CallLinkPublicParams {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try invokeFnReturningVariableLengthSerialized {
signal_call_link_secret_params_get_public_params($0, contents)
}
}
}
}
}
}
public func decrypt(_ ciphertext: UuidCiphertext) throws -> Aci {
return try withUnsafeBorrowedBuffer { contents in
try ciphertext.withUnsafePointerToSerialized { ciphertext in
try invokeFnReturningServiceId {
signal_call_link_secret_params_decrypt_user_id($0, contents, ciphertext)
public func decrypt(_ ciphertext: UuidCiphertext) throws -> Aci {
return try withUnsafeBorrowedBuffer { contents in
try ciphertext.withUnsafePointerToSerialized { ciphertext in
try invokeFnReturningServiceId {
signal_call_link_secret_params_decrypt_user_id($0, contents, ciphertext)
}
}
}
}
}
}
}

View File

@ -7,96 +7,94 @@ import Foundation
import SignalFfi
public class ClientZkAuthOperations {
let serverPublicParams: ServerPublicParams
let serverPublicParams: ServerPublicParams
public init(serverPublicParams: ServerPublicParams) {
self.serverPublicParams = serverPublicParams
}
public func receiveAuthCredential(aci: Aci, redemptionTime: UInt32, authCredentialResponse: AuthCredentialResponse) throws -> AuthCredential {
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try aci.withPointerToFixedWidthBinary { uuid in
try authCredentialResponse.withUnsafePointerToSerialized { authCredentialResponse in
try invokeFnReturningSerialized {
signal_server_public_params_receive_auth_credential($0, serverPublicParams, uuid, redemptionTime, authCredentialResponse)
}
}
}
public init(serverPublicParams: ServerPublicParams) {
self.serverPublicParams = serverPublicParams
}
}
/// Produces the `AuthCredentialWithPni` from a server-generated `AuthCredentialWithPniResponse`.
///
/// - parameter redemptionTime: This is provided by the server as an integer, and should be passed through directly.
public func receiveAuthCredentialWithPniAsServiceId(aci: Aci, pni: Pni, redemptionTime: UInt64, authCredentialResponse: AuthCredentialWithPniResponse) throws -> AuthCredentialWithPni {
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try aci.withPointerToFixedWidthBinary { aci in
try pni.withPointerToFixedWidthBinary { pni in
try authCredentialResponse.withUnsafePointerToSerialized { authCredentialResponse in
try invokeFnReturningSerialized {
signal_server_public_params_receive_auth_credential_with_pni_as_service_id($0, serverPublicParams, aci, pni, redemptionTime, authCredentialResponse)
public func receiveAuthCredential(aci: Aci, redemptionTime: UInt32, authCredentialResponse: AuthCredentialResponse) throws -> AuthCredential {
return try self.serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try aci.withPointerToFixedWidthBinary { uuid in
try authCredentialResponse.withUnsafePointerToSerialized { authCredentialResponse in
try invokeFnReturningSerialized {
signal_server_public_params_receive_auth_credential($0, serverPublicParams, uuid, redemptionTime, authCredentialResponse)
}
}
}
}
}
}
}
}
/// Produces the `AuthCredentialWithPni` from a server-generated `AuthCredentialWithPniResponse`.
///
/// This older style of AuthCredentialWithPni will not actually have a usable PNI field,
/// but can still be used for authenticating with an ACI.
///
/// - parameter redemptionTime: This is provided by the server as an integer, and should be passed through directly.
public func receiveAuthCredentialWithPniAsAci(aci: Aci, pni: Pni, redemptionTime: UInt64, authCredentialResponse: AuthCredentialWithPniResponse) throws -> AuthCredentialWithPni {
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try aci.withPointerToFixedWidthBinary { aci in
try pni.withPointerToFixedWidthBinary { pni in
try authCredentialResponse.withUnsafePointerToSerialized { authCredentialResponse in
try invokeFnReturningSerialized {
signal_server_public_params_receive_auth_credential_with_pni_as_aci($0, serverPublicParams, aci, pni, redemptionTime, authCredentialResponse)
/// Produces the `AuthCredentialWithPni` from a server-generated `AuthCredentialWithPniResponse`.
///
/// - parameter redemptionTime: This is provided by the server as an integer, and should be passed through directly.
public func receiveAuthCredentialWithPniAsServiceId(aci: Aci, pni: Pni, redemptionTime: UInt64, authCredentialResponse: AuthCredentialWithPniResponse) throws -> AuthCredentialWithPni {
return try self.serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try aci.withPointerToFixedWidthBinary { aci in
try pni.withPointerToFixedWidthBinary { pni in
try authCredentialResponse.withUnsafePointerToSerialized { authCredentialResponse in
try invokeFnReturningSerialized {
signal_server_public_params_receive_auth_credential_with_pni_as_service_id($0, serverPublicParams, aci, pni, redemptionTime, authCredentialResponse)
}
}
}
}
}
}
}
}
}
public func createAuthCredentialPresentation(groupSecretParams: GroupSecretParams, authCredential: AuthCredential) throws -> AuthCredentialPresentation {
return try createAuthCredentialPresentation(randomness: Randomness.generate(), groupSecretParams: groupSecretParams, authCredential: authCredential)
}
public func createAuthCredentialPresentation(randomness: Randomness, groupSecretParams: GroupSecretParams, authCredential: AuthCredential) throws -> AuthCredentialPresentation {
return try serverPublicParams.withUnsafePointerToSerialized { contents in
try randomness.withUnsafePointerToBytes { randomness in
try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try authCredential.withUnsafePointerToSerialized { authCredential in
try invokeFnReturningVariableLengthSerialized {
signal_server_public_params_create_auth_credential_presentation_deterministic($0, contents, randomness, groupSecretParams, authCredential)
/// Produces the `AuthCredentialWithPni` from a server-generated `AuthCredentialWithPniResponse`.
///
/// This older style of AuthCredentialWithPni will not actually have a usable PNI field,
/// but can still be used for authenticating with an ACI.
///
/// - parameter redemptionTime: This is provided by the server as an integer, and should be passed through directly.
public func receiveAuthCredentialWithPniAsAci(aci: Aci, pni: Pni, redemptionTime: UInt64, authCredentialResponse: AuthCredentialWithPniResponse) throws -> AuthCredentialWithPni {
return try self.serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try aci.withPointerToFixedWidthBinary { aci in
try pni.withPointerToFixedWidthBinary { pni in
try authCredentialResponse.withUnsafePointerToSerialized { authCredentialResponse in
try invokeFnReturningSerialized {
signal_server_public_params_receive_auth_credential_with_pni_as_aci($0, serverPublicParams, aci, pni, redemptionTime, authCredentialResponse)
}
}
}
}
}
}
}
}
}
public func createAuthCredentialPresentation(groupSecretParams: GroupSecretParams, authCredential: AuthCredentialWithPni) throws -> AuthCredentialPresentation {
return try createAuthCredentialPresentation(randomness: Randomness.generate(), groupSecretParams: groupSecretParams, authCredential: authCredential)
}
public func createAuthCredentialPresentation(groupSecretParams: GroupSecretParams, authCredential: AuthCredential) throws -> AuthCredentialPresentation {
return try self.createAuthCredentialPresentation(randomness: Randomness.generate(), groupSecretParams: groupSecretParams, authCredential: authCredential)
}
public func createAuthCredentialPresentation(randomness: Randomness, groupSecretParams: GroupSecretParams, authCredential: AuthCredentialWithPni) throws -> AuthCredentialPresentation {
return try serverPublicParams.withUnsafePointerToSerialized { contents in
try randomness.withUnsafePointerToBytes { randomness in
try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try authCredential.withUnsafePointerToSerialized { authCredential in
try invokeFnReturningVariableLengthSerialized {
signal_server_public_params_create_auth_credential_with_pni_presentation_deterministic($0, contents, randomness, groupSecretParams, authCredential)
public func createAuthCredentialPresentation(randomness: Randomness, groupSecretParams: GroupSecretParams, authCredential: AuthCredential) throws -> AuthCredentialPresentation {
return try self.serverPublicParams.withUnsafePointerToSerialized { contents in
try randomness.withUnsafePointerToBytes { randomness in
try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try authCredential.withUnsafePointerToSerialized { authCredential in
try invokeFnReturningVariableLengthSerialized {
signal_server_public_params_create_auth_credential_presentation_deterministic($0, contents, randomness, groupSecretParams, authCredential)
}
}
}
}
}
}
}
}
}
public func createAuthCredentialPresentation(groupSecretParams: GroupSecretParams, authCredential: AuthCredentialWithPni) throws -> AuthCredentialPresentation {
return try self.createAuthCredentialPresentation(randomness: Randomness.generate(), groupSecretParams: groupSecretParams, authCredential: authCredential)
}
public func createAuthCredentialPresentation(randomness: Randomness, groupSecretParams: GroupSecretParams, authCredential: AuthCredentialWithPni) throws -> AuthCredentialPresentation {
return try self.serverPublicParams.withUnsafePointerToSerialized { contents in
try randomness.withUnsafePointerToBytes { randomness in
try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try authCredential.withUnsafePointerToSerialized { authCredential in
try invokeFnReturningVariableLengthSerialized {
signal_server_public_params_create_auth_credential_with_pni_presentation_deterministic($0, contents, randomness, groupSecretParams, authCredential)
}
}
}
}
}
}
}

View File

@ -7,81 +7,79 @@ import Foundation
import SignalFfi
public class ClientZkGroupCipher {
let groupSecretParams: GroupSecretParams
let groupSecretParams: GroupSecretParams
public init(groupSecretParams: GroupSecretParams) {
self.groupSecretParams = groupSecretParams
}
public func encrypt(_ serviceId: ServiceId) throws -> UuidCiphertext {
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try serviceId.withPointerToFixedWidthBinary { serviceId in
try invokeFnReturningSerialized {
signal_group_secret_params_encrypt_service_id($0, groupSecretParams, serviceId)
}
}
public init(groupSecretParams: GroupSecretParams) {
self.groupSecretParams = groupSecretParams
}
}
public func decrypt(_ uuidCiphertext: UuidCiphertext) throws -> ServiceId {
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try uuidCiphertext.withUnsafePointerToSerialized { uuidCiphertext in
try invokeFnReturningServiceId {
signal_group_secret_params_decrypt_service_id($0, groupSecretParams, uuidCiphertext)
public func encrypt(_ serviceId: ServiceId) throws -> UuidCiphertext {
return try self.groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try serviceId.withPointerToFixedWidthBinary { serviceId in
try invokeFnReturningSerialized {
signal_group_secret_params_encrypt_service_id($0, groupSecretParams, serviceId)
}
}
}
}
}
}
public func encryptProfileKey(profileKey: ProfileKey, userId: Aci) throws -> ProfileKeyCiphertext {
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try profileKey.withUnsafePointerToSerialized { profileKey in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_group_secret_params_encrypt_profile_key($0, groupSecretParams, profileKey, userId)
}
public func decrypt(_ uuidCiphertext: UuidCiphertext) throws -> ServiceId {
return try self.groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try uuidCiphertext.withUnsafePointerToSerialized { uuidCiphertext in
try invokeFnReturningServiceId {
signal_group_secret_params_decrypt_service_id($0, groupSecretParams, uuidCiphertext)
}
}
}
}
}
}
public func decryptProfileKey(profileKeyCiphertext: ProfileKeyCiphertext, userId: Aci) throws -> ProfileKey {
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try profileKeyCiphertext.withUnsafePointerToSerialized { profileKeyCiphertext in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_group_secret_params_decrypt_profile_key($0, groupSecretParams, profileKeyCiphertext, userId )
}
public func encryptProfileKey(profileKey: ProfileKey, userId: Aci) throws -> ProfileKeyCiphertext {
return try self.groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try profileKey.withUnsafePointerToSerialized { profileKey in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_group_secret_params_encrypt_profile_key($0, groupSecretParams, profileKey, userId)
}
}
}
}
}
}
}
public func encryptBlob(plaintext: [UInt8]) throws -> [UInt8] {
return try encryptBlob(randomness: Randomness.generate(), plaintext: plaintext)
}
public func encryptBlob(randomness: Randomness, plaintext: [UInt8]) throws -> [UInt8] {
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try randomness.withUnsafePointerToBytes { randomness in
try plaintext.withUnsafeBorrowedBuffer { plaintext in
try invokeFnReturningArray {
signal_group_secret_params_encrypt_blob_with_padding_deterministic($0, groupSecretParams, randomness, plaintext, 0)
}
public func decryptProfileKey(profileKeyCiphertext: ProfileKeyCiphertext, userId: Aci) throws -> ProfileKey {
return try self.groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try profileKeyCiphertext.withUnsafePointerToSerialized { profileKeyCiphertext in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_group_secret_params_decrypt_profile_key($0, groupSecretParams, profileKeyCiphertext, userId)
}
}
}
}
}
}
}
public func decryptBlob(blobCiphertext: [UInt8]) throws -> [UInt8] {
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try blobCiphertext.withUnsafeBorrowedBuffer { blobCiphertext in
try invokeFnReturningArray {
signal_group_secret_params_decrypt_blob_with_padding($0, groupSecretParams, blobCiphertext)
public func encryptBlob(plaintext: [UInt8]) throws -> [UInt8] {
return try self.encryptBlob(randomness: Randomness.generate(), plaintext: plaintext)
}
public func encryptBlob(randomness: Randomness, plaintext: [UInt8]) throws -> [UInt8] {
return try self.groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try randomness.withUnsafePointerToBytes { randomness in
try plaintext.withUnsafeBorrowedBuffer { plaintext in
try invokeFnReturningArray {
signal_group_secret_params_encrypt_blob_with_padding_deterministic($0, groupSecretParams, randomness, plaintext, 0)
}
}
}
}
}
}
}
public func decryptBlob(blobCiphertext: [UInt8]) throws -> [UInt8] {
return try self.groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try blobCiphertext.withUnsafeBorrowedBuffer { blobCiphertext in
try invokeFnReturningArray {
signal_group_secret_params_decrypt_blob_with_padding($0, groupSecretParams, blobCiphertext)
}
}
}
}
}

View File

@ -7,63 +7,61 @@ import Foundation
import SignalFfi
public class ClientZkProfileOperations {
let serverPublicParams: ServerPublicParams
let serverPublicParams: ServerPublicParams
public init(serverPublicParams: ServerPublicParams) {
self.serverPublicParams = serverPublicParams
}
public init(serverPublicParams: ServerPublicParams) {
self.serverPublicParams = serverPublicParams
}
public func createProfileKeyCredentialRequestContext(userId: Aci, profileKey: ProfileKey) throws -> ProfileKeyCredentialRequestContext {
return try self.createProfileKeyCredentialRequestContext(randomness: Randomness.generate(), userId: userId, profileKey: profileKey)
}
public func createProfileKeyCredentialRequestContext(userId: Aci, profileKey: ProfileKey) throws -> ProfileKeyCredentialRequestContext {
return try createProfileKeyCredentialRequestContext(randomness: Randomness.generate(), userId: userId, profileKey: profileKey)
}
public func createProfileKeyCredentialRequestContext(randomness: Randomness, userId: Aci, profileKey: ProfileKey) throws -> ProfileKeyCredentialRequestContext {
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try randomness.withUnsafePointerToBytes { randomness in
try userId.withPointerToFixedWidthBinary { userId in
try profileKey.withUnsafePointerToSerialized { profileKey in
try invokeFnReturningSerialized {
signal_server_public_params_create_profile_key_credential_request_context_deterministic($0, serverPublicParams, randomness, userId, profileKey)
public func createProfileKeyCredentialRequestContext(randomness: Randomness, userId: Aci, profileKey: ProfileKey) throws -> ProfileKeyCredentialRequestContext {
return try self.serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try randomness.withUnsafePointerToBytes { randomness in
try userId.withPointerToFixedWidthBinary { userId in
try profileKey.withUnsafePointerToSerialized { profileKey in
try invokeFnReturningSerialized {
signal_server_public_params_create_profile_key_credential_request_context_deterministic($0, serverPublicParams, randomness, userId, profileKey)
}
}
}
}
}
}
}
}
}
public func receiveExpiringProfileKeyCredential(
profileKeyCredentialRequestContext: ProfileKeyCredentialRequestContext,
profileKeyCredentialResponse: ExpiringProfileKeyCredentialResponse,
now: Date = Date()
) throws -> ExpiringProfileKeyCredential {
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try profileKeyCredentialRequestContext.withUnsafePointerToSerialized { requestContext in
try profileKeyCredentialResponse.withUnsafePointerToSerialized { response in
try invokeFnReturningSerialized {
signal_server_public_params_receive_expiring_profile_key_credential($0, serverPublicParams, requestContext, response, UInt64(now.timeIntervalSince1970))
}
}
}
}
}
public func createProfileKeyCredentialPresentation(groupSecretParams: GroupSecretParams, profileKeyCredential: ExpiringProfileKeyCredential) throws -> ProfileKeyCredentialPresentation {
return try createProfileKeyCredentialPresentation(randomness: Randomness.generate(), groupSecretParams: groupSecretParams, profileKeyCredential: profileKeyCredential)
}
public func createProfileKeyCredentialPresentation(randomness: Randomness, groupSecretParams: GroupSecretParams, profileKeyCredential: ExpiringProfileKeyCredential) throws -> ProfileKeyCredentialPresentation {
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try randomness.withUnsafePointerToBytes { randomness in
try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try profileKeyCredential.withUnsafePointerToSerialized { profileKeyCredential in
try invokeFnReturningVariableLengthSerialized {
signal_server_public_params_create_expiring_profile_key_credential_presentation_deterministic($0, serverPublicParams, randomness, groupSecretParams, profileKeyCredential)
public func receiveExpiringProfileKeyCredential(
profileKeyCredentialRequestContext: ProfileKeyCredentialRequestContext,
profileKeyCredentialResponse: ExpiringProfileKeyCredentialResponse,
now: Date = Date()
) throws -> ExpiringProfileKeyCredential {
return try self.serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try profileKeyCredentialRequestContext.withUnsafePointerToSerialized { requestContext in
try profileKeyCredentialResponse.withUnsafePointerToSerialized { response in
try invokeFnReturningSerialized {
signal_server_public_params_receive_expiring_profile_key_credential($0, serverPublicParams, requestContext, response, UInt64(now.timeIntervalSince1970))
}
}
}
}
}
}
}
}
public func createProfileKeyCredentialPresentation(groupSecretParams: GroupSecretParams, profileKeyCredential: ExpiringProfileKeyCredential) throws -> ProfileKeyCredentialPresentation {
return try self.createProfileKeyCredentialPresentation(randomness: Randomness.generate(), groupSecretParams: groupSecretParams, profileKeyCredential: profileKeyCredential)
}
public func createProfileKeyCredentialPresentation(randomness: Randomness, groupSecretParams: GroupSecretParams, profileKeyCredential: ExpiringProfileKeyCredential) throws -> ProfileKeyCredentialPresentation {
return try self.serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try randomness.withUnsafePointerToBytes { randomness in
try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
try profileKeyCredential.withUnsafePointerToSerialized { profileKeyCredential in
try invokeFnReturningVariableLengthSerialized {
signal_server_public_params_create_expiring_profile_key_credential_presentation_deterministic($0, serverPublicParams, randomness, groupSecretParams, profileKeyCredential)
}
}
}
}
}
}
}

View File

@ -7,55 +7,53 @@ import Foundation
import SignalFfi
public class ClientZkReceiptOperations {
let serverPublicParams: ServerPublicParams
let serverPublicParams: ServerPublicParams
public init(serverPublicParams: ServerPublicParams) {
self.serverPublicParams = serverPublicParams
}
public func createReceiptCredentialRequestContext(receiptSerial: ReceiptSerial) throws -> ReceiptCredentialRequestContext {
return try createReceiptCredentialRequestContext(randomness: Randomness.generate(), receiptSerial: receiptSerial)
}
public func createReceiptCredentialRequestContext(randomness: Randomness, receiptSerial: ReceiptSerial) throws -> ReceiptCredentialRequestContext {
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try randomness.withUnsafePointerToBytes { randomness in
try receiptSerial.withUnsafePointerToSerialized { receiptSerial in
try invokeFnReturningSerialized {
signal_server_public_params_create_receipt_credential_request_context_deterministic($0, serverPublicParams, randomness, receiptSerial)
}
}
}
public init(serverPublicParams: ServerPublicParams) {
self.serverPublicParams = serverPublicParams
}
}
public func receiveReceiptCredential(receiptCredentialRequestContext: ReceiptCredentialRequestContext, receiptCredentialResponse: ReceiptCredentialResponse) throws -> ReceiptCredential {
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try receiptCredentialRequestContext.withUnsafePointerToSerialized { requestContext in
try receiptCredentialResponse.withUnsafePointerToSerialized { response in
try invokeFnReturningSerialized {
signal_server_public_params_receive_receipt_credential($0, serverPublicParams, requestContext, response)
}
}
}
public func createReceiptCredentialRequestContext(receiptSerial: ReceiptSerial) throws -> ReceiptCredentialRequestContext {
return try self.createReceiptCredentialRequestContext(randomness: Randomness.generate(), receiptSerial: receiptSerial)
}
}
public func createReceiptCredentialPresentation(receiptCredential: ReceiptCredential) throws -> ReceiptCredentialPresentation {
return try createReceiptCredentialPresentation(randomness: Randomness.generate(), receiptCredential: receiptCredential)
}
public func createReceiptCredentialPresentation(randomness: Randomness, receiptCredential: ReceiptCredential) throws -> ReceiptCredentialPresentation {
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try randomness.withUnsafePointerToBytes { randomness in
try receiptCredential.withUnsafePointerToSerialized { receiptCredential in
try invokeFnReturningSerialized {
signal_server_public_params_create_receipt_credential_presentation_deterministic($0, serverPublicParams, randomness, receiptCredential)
}
public func createReceiptCredentialRequestContext(randomness: Randomness, receiptSerial: ReceiptSerial) throws -> ReceiptCredentialRequestContext {
return try self.serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try randomness.withUnsafePointerToBytes { randomness in
try receiptSerial.withUnsafePointerToSerialized { receiptSerial in
try invokeFnReturningSerialized {
signal_server_public_params_create_receipt_credential_request_context_deterministic($0, serverPublicParams, randomness, receiptSerial)
}
}
}
}
}
}
}
public func receiveReceiptCredential(receiptCredentialRequestContext: ReceiptCredentialRequestContext, receiptCredentialResponse: ReceiptCredentialResponse) throws -> ReceiptCredential {
return try self.serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try receiptCredentialRequestContext.withUnsafePointerToSerialized { requestContext in
try receiptCredentialResponse.withUnsafePointerToSerialized { response in
try invokeFnReturningSerialized {
signal_server_public_params_receive_receipt_credential($0, serverPublicParams, requestContext, response)
}
}
}
}
}
public func createReceiptCredentialPresentation(receiptCredential: ReceiptCredential) throws -> ReceiptCredentialPresentation {
return try self.createReceiptCredentialPresentation(randomness: Randomness.generate(), receiptCredential: receiptCredential)
}
public func createReceiptCredentialPresentation(randomness: Randomness, receiptCredential: ReceiptCredential) throws -> ReceiptCredentialPresentation {
return try self.serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
try randomness.withUnsafePointerToBytes { randomness in
try receiptCredential.withUnsafePointerToSerialized { receiptCredential in
try invokeFnReturningSerialized {
signal_server_public_params_create_receipt_credential_presentation_deterministic($0, serverPublicParams, randomness, receiptCredential)
}
}
}
}
}
}

View File

@ -7,35 +7,33 @@ import Foundation
import SignalFfi
public class CreateCallLinkCredential: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_check_valid_contents)
}
public func present<RoomId: ContiguousBytes>(roomId: RoomId, userId: Aci, serverParams: GenericServerPublicParams, callLinkParams: CallLinkSecretParams) -> CreateCallLinkCredentialPresentation {
return failOnError {
present(roomId: roomId, userId: userId, serverParams: serverParams, callLinkParams: callLinkParams, randomness: try .generate())
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_check_valid_contents)
}
}
public func present<RoomId: ContiguousBytes>(roomId: RoomId, userId: Aci, serverParams: GenericServerPublicParams, callLinkParams: CallLinkSecretParams, randomness: Randomness) -> CreateCallLinkCredentialPresentation {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try roomId.withUnsafeBorrowedBuffer { roomId in
try userId.withPointerToFixedWidthBinary { userId in
try serverParams.withUnsafeBorrowedBuffer { serverParams in
try callLinkParams.withUnsafeBorrowedBuffer { callLinkParams in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_present_deterministic($0, contents, roomId, userId, serverParams, callLinkParams, randomness)
}
}
}
}
}
public func present<RoomId: ContiguousBytes>(roomId: RoomId, userId: Aci, serverParams: GenericServerPublicParams, callLinkParams: CallLinkSecretParams) -> CreateCallLinkCredentialPresentation {
return failOnError {
self.present(roomId: roomId, userId: userId, serverParams: serverParams, callLinkParams: callLinkParams, randomness: try .generate())
}
}
}
}
public func present<RoomId: ContiguousBytes>(roomId: RoomId, userId: Aci, serverParams: GenericServerPublicParams, callLinkParams: CallLinkSecretParams, randomness: Randomness) -> CreateCallLinkCredentialPresentation {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try roomId.withUnsafeBorrowedBuffer { roomId in
try userId.withPointerToFixedWidthBinary { userId in
try serverParams.withUnsafeBorrowedBuffer { serverParams in
try callLinkParams.withUnsafeBorrowedBuffer { callLinkParams in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_present_deterministic($0, contents, roomId, userId, serverParams, callLinkParams, randomness)
}
}
}
}
}
}
}
}
}
}

View File

@ -7,21 +7,19 @@ import Foundation
import SignalFfi
public class CreateCallLinkCredentialPresentation: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_presentation_check_valid_contents)
}
public func verify<RoomId: ContiguousBytes>(roomId: RoomId, now: Date = Date(), serverParams: GenericServerSecretParams, callLinkParams: CallLinkPublicParams) throws {
try withUnsafeBorrowedBuffer { contents in
try roomId.withUnsafeBorrowedBuffer { roomId in
try serverParams.withUnsafeBorrowedBuffer { serverParams in
try callLinkParams.withUnsafeBorrowedBuffer { callLinkParams in
try checkError(signal_create_call_link_credential_presentation_verify(contents, roomId, UInt64(now.timeIntervalSince1970), serverParams, callLinkParams))
}
}
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_presentation_check_valid_contents)
}
}
public func verify<RoomId: ContiguousBytes>(roomId: RoomId, now: Date = Date(), serverParams: GenericServerSecretParams, callLinkParams: CallLinkPublicParams) throws {
try withUnsafeBorrowedBuffer { contents in
try roomId.withUnsafeBorrowedBuffer { roomId in
try serverParams.withUnsafeBorrowedBuffer { serverParams in
try callLinkParams.withUnsafeBorrowedBuffer { callLinkParams in
try checkError(signal_create_call_link_credential_presentation_verify(contents, roomId, UInt64(now.timeIntervalSince1970), serverParams, callLinkParams))
}
}
}
}
}
}

View File

@ -7,29 +7,29 @@ import Foundation
import SignalFfi
public class CreateCallLinkCredentialRequest: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_request_check_valid_contents)
}
public func issueCredential(userId: Aci, timestamp: Date, params: GenericServerSecretParams) -> CreateCallLinkCredentialResponse {
return failOnError {
issueCredential(userId: userId, timestamp: timestamp, params: params, randomness: try .generate())
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_request_check_valid_contents)
}
}
public func issueCredential(userId: Aci, timestamp: Date, params: GenericServerSecretParams, randomness: Randomness) -> CreateCallLinkCredentialResponse {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try userId.withPointerToFixedWidthBinary { userId in
try params.withUnsafeBorrowedBuffer { params in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_request_issue_deterministic($0, contents, userId, UInt64(timestamp.timeIntervalSince1970), params, randomness)
}
}
}
public func issueCredential(userId: Aci, timestamp: Date, params: GenericServerSecretParams) -> CreateCallLinkCredentialResponse {
return failOnError {
self.issueCredential(userId: userId, timestamp: timestamp, params: params, randomness: try .generate())
}
}
public func issueCredential(userId: Aci, timestamp: Date, params: GenericServerSecretParams, randomness: Randomness) -> CreateCallLinkCredentialResponse {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try userId.withPointerToFixedWidthBinary { userId in
try params.withUnsafeBorrowedBuffer { params in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_request_issue_deterministic($0, contents, userId, UInt64(timestamp.timeIntervalSince1970), params, randomness)
}
}
}
}
}
}
}
}
}
}

View File

@ -7,51 +7,49 @@ import Foundation
import SignalFfi
public class CreateCallLinkCredentialRequestContext: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_request_context_check_valid_contents)
}
public static func forRoomId<RoomId: ContiguousBytes>(_ roomId: RoomId) -> Self {
return failOnError {
self.forRoomId(roomId, randomness: try .generate())
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_request_context_check_valid_contents)
}
}
public static func forRoomId<RoomId: ContiguousBytes>(_ roomId: RoomId, randomness: Randomness) -> Self {
return failOnError {
try roomId.withUnsafeBorrowedBuffer { roomId in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_request_context_new_deterministic($0, roomId, randomness)
}
public static func forRoomId<RoomId: ContiguousBytes>(_ roomId: RoomId) -> Self {
return failOnError {
self.forRoomId(roomId, randomness: try .generate())
}
}
}
}
public func getRequest() -> CreateCallLinkCredentialRequest {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_request_context_get_request($0, contents)
}
}
}
}
public func receive(_ response: CreateCallLinkCredentialResponse, userId: Aci, params: GenericServerPublicParams) throws -> CreateCallLinkCredential {
return try withUnsafeBorrowedBuffer { contents in
try response.withUnsafeBorrowedBuffer { response in
try userId.withPointerToFixedWidthBinary { userId in
try params.withUnsafeBorrowedBuffer { params in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_request_context_receive_response($0, contents, response, userId, params)
public static func forRoomId<RoomId: ContiguousBytes>(_ roomId: RoomId, randomness: Randomness) -> Self {
return failOnError {
try roomId.withUnsafeBorrowedBuffer { roomId in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_request_context_new_deterministic($0, roomId, randomness)
}
}
}
}
}
}
}
}
public func getRequest() -> CreateCallLinkCredentialRequest {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_request_context_get_request($0, contents)
}
}
}
}
public func receive(_ response: CreateCallLinkCredentialResponse, userId: Aci, params: GenericServerPublicParams) throws -> CreateCallLinkCredential {
return try withUnsafeBorrowedBuffer { contents in
try response.withUnsafeBorrowedBuffer { response in
try userId.withPointerToFixedWidthBinary { userId in
try params.withUnsafeBorrowedBuffer { params in
try invokeFnReturningVariableLengthSerialized {
signal_create_call_link_credential_request_context_receive_response($0, contents, response, userId, params)
}
}
}
}
}
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class CreateCallLinkCredentialResponse: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_response_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_create_call_link_credential_response_check_valid_contents)
}
}

View File

@ -7,18 +7,18 @@ import Foundation
import SignalFfi
public class ExpiringProfileKeyCredential: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_expiring_profile_key_credential_check_valid_contents)
}
public var expirationTime: Date {
let timestampInSeconds = failOnError {
try self.withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_expiring_profile_key_credential_get_expiration_time($0, contents)
}
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_expiring_profile_key_credential_check_valid_contents)
}
public var expirationTime: Date {
let timestampInSeconds = failOnError {
try self.withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_expiring_profile_key_credential_get_expiration_time($0, contents)
}
}
}
return Date(timeIntervalSince1970: TimeInterval(timestampInSeconds))
}
return Date(timeIntervalSince1970: TimeInterval(timestampInSeconds))
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class ExpiringProfileKeyCredentialResponse: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_expiring_profile_key_credential_response_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_expiring_profile_key_credential_response_check_valid_contents)
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class GenericServerPublicParams: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_generic_server_public_params_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_generic_server_public_params_check_valid_contents)
}
}

View File

@ -7,35 +7,33 @@ import Foundation
import SignalFfi
public class GenericServerSecretParams: ByteArray {
public static func generate() -> Self {
return failOnError {
generate(randomness: try .generate())
}
}
public static func generate(randomness: Randomness) -> Self {
return failOnError {
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_generic_server_secret_params_generate_deterministic($0, randomness)
public static func generate() -> Self {
return failOnError {
self.generate(randomness: try .generate())
}
}
}
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_generic_server_secret_params_check_valid_contents)
}
public func getPublicParams() -> GenericServerPublicParams {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try invokeFnReturningVariableLengthSerialized {
signal_generic_server_secret_params_get_public_params($0, contents)
public static func generate(randomness: Randomness) -> Self {
return failOnError {
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_generic_server_secret_params_generate_deterministic($0, randomness)
}
}
}
}
}
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_generic_server_secret_params_check_valid_contents)
}
public func getPublicParams() -> GenericServerPublicParams {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try invokeFnReturningVariableLengthSerialized {
signal_generic_server_secret_params_get_public_params($0, contents)
}
}
}
}
}

View File

@ -4,11 +4,9 @@
//
public class GroupIdentifier: ByteArray {
public static let SIZE: Int = 32
public static let SIZE: Int = 32
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: GroupIdentifier.SIZE)
}
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: GroupIdentifier.SIZE)
}
}

View File

@ -4,11 +4,9 @@
//
public class GroupMasterKey: ByteArray {
public static let SIZE: Int = 32
public static let SIZE: Int = 32
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: GroupMasterKey.SIZE)
}
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: GroupMasterKey.SIZE)
}
}

View File

@ -7,17 +7,15 @@ import Foundation
import SignalFfi
public class GroupPublicParams: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_public_params_check_valid_contents)
}
public func getGroupIdentifier() throws -> GroupIdentifier {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_group_public_params_get_group_identifier($0, contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_public_params_check_valid_contents)
}
}
public func getGroupIdentifier() throws -> GroupIdentifier {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_group_public_params_get_group_identifier($0, contents)
}
}
}
}

View File

@ -7,45 +7,43 @@ import Foundation
import SignalFfi
public class GroupSecretParams: ByteArray {
public static func generate() throws -> GroupSecretParams {
return try generate(randomness: Randomness.generate())
}
public static func generate(randomness: Randomness) throws -> GroupSecretParams {
return try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningSerialized {
signal_group_secret_params_generate_deterministic($0, randomness)
}
public static func generate() throws -> GroupSecretParams {
return try self.generate(randomness: Randomness.generate())
}
}
public static func deriveFromMasterKey(groupMasterKey: GroupMasterKey) throws -> GroupSecretParams {
return try groupMasterKey.withUnsafePointerToSerialized { groupMasterKey in
try invokeFnReturningSerialized {
signal_group_secret_params_derive_from_master_key($0, groupMasterKey)
}
public static func generate(randomness: Randomness) throws -> GroupSecretParams {
return try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningSerialized {
signal_group_secret_params_generate_deterministic($0, randomness)
}
}
}
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_secret_params_check_valid_contents)
}
public func getMasterKey() throws -> GroupMasterKey {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_group_secret_params_get_master_key($0, contents)
}
public static func deriveFromMasterKey(groupMasterKey: GroupMasterKey) throws -> GroupSecretParams {
return try groupMasterKey.withUnsafePointerToSerialized { groupMasterKey in
try invokeFnReturningSerialized {
signal_group_secret_params_derive_from_master_key($0, groupMasterKey)
}
}
}
}
public func getPublicParams() throws -> GroupPublicParams {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_group_secret_params_get_public_params($0, contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_secret_params_check_valid_contents)
}
}
public func getMasterKey() throws -> GroupMasterKey {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_group_secret_params_get_master_key($0, contents)
}
}
}
public func getPublicParams() throws -> GroupPublicParams {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_group_secret_params_get_public_params($0, contents)
}
}
}
}

View File

@ -16,38 +16,37 @@ import SignalFfi
* - SeeAlso: ``GroupSendCredentialResponse``, ``GroupSendCredentialPresentation``
*/
public class GroupSendCredential: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_send_credential_check_valid_contents)
}
/**
* Generates a new presentation, so that multiple uses of this credential are harder to link.
*/
public func present(serverParams: ServerPublicParams) -> GroupSendCredentialPresentation {
return failOnError {
present(serverParams: serverParams, randomness: try .generate())
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_send_credential_check_valid_contents)
}
}
/**
* Generates a new presentation with a dedicated source of randomness.
*
* Should only be used for testing purposes.
*
* - SeeAlso: ``present(serverParams:)``
*/
public func present(serverParams: ServerPublicParams, randomness: Randomness) -> GroupSendCredentialPresentation {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try serverParams.withUnsafePointerToSerialized { serverParams in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_group_send_credential_present_deterministic($0, contents, serverParams, randomness)
}
}
/**
* Generates a new presentation, so that multiple uses of this credential are harder to link.
*/
public func present(serverParams: ServerPublicParams) -> GroupSendCredentialPresentation {
return failOnError {
self.present(serverParams: serverParams, randomness: try .generate())
}
}
/**
* Generates a new presentation with a dedicated source of randomness.
*
* Should only be used for testing purposes.
*
* - SeeAlso: ``present(serverParams:)``
*/
public func present(serverParams: ServerPublicParams, randomness: Randomness) -> GroupSendCredentialPresentation {
return failOnError {
try withUnsafeBorrowedBuffer { contents in
try serverParams.withUnsafePointerToSerialized { serverParams in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_group_send_credential_present_deterministic($0, contents, serverParams, randomness)
}
}
}
}
}
}
}
}
}

View File

@ -16,23 +16,22 @@ import SignalFfi
* - SeeAlso: ``GroupSendCredentialResponse``, ``GroupSendCredential``
*/
public class GroupSendCredentialPresentation: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_send_credential_presentation_check_valid_contents)
}
/**
* Verifies that the credential is valid for a group containing the holder and `groupMembers`.
*
* - Throws: ``SignalError/verificationFailed(_:)`` if the credential is not valid for any reason
*/
public func verify(groupMembers: [ServiceId], now: Date = Date(), serverParams: ServerSecretParams) throws {
try withUnsafeBorrowedBuffer { contents in
try ServiceId.concatenatedFixedWidthBinary(groupMembers).withUnsafeBorrowedBuffer { groupMembers in
try serverParams.withUnsafePointerToSerialized { serverParams in
try checkError(signal_group_send_credential_presentation_verify(contents, groupMembers, UInt64(now.timeIntervalSince1970), serverParams))
}
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_send_credential_presentation_check_valid_contents)
}
/**
* Verifies that the credential is valid for a group containing the holder and `groupMembers`.
*
* - Throws: ``SignalError/verificationFailed(_:)`` if the credential is not valid for any reason
*/
public func verify(groupMembers: [ServiceId], now: Date = Date(), serverParams: ServerSecretParams) throws {
try withUnsafeBorrowedBuffer { contents in
try ServiceId.concatenatedFixedWidthBinary(groupMembers).withUnsafeBorrowedBuffer { groupMembers in
try serverParams.withUnsafePointerToSerialized { serverParams in
try checkError(signal_group_send_credential_presentation_verify(contents, groupMembers, UInt64(now.timeIntervalSince1970), serverParams))
}
}
}
}
}
}

View File

@ -16,119 +16,120 @@ import SignalFfi
* - SeeAlso: ``GroupSendCredential``, ``GroupSendCredentialPresentation``
*/
public class GroupSendCredentialResponse: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_send_credential_response_check_valid_contents)
}
public static func defaultExpiration() -> Date {
let expiration = failOnError {
try invokeFnReturningInteger {
signal_group_send_credential_response_default_expiration_based_on_current_time($0)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_group_send_credential_response_check_valid_contents)
}
return Date(timeIntervalSince1970: TimeInterval(expiration))
}
/**
* Issues a new credential stating that `requestingMember` is a member of a group containing
* `groupMembers`.
*
* `groupMembers` should include `requestingMember` as well.
*/
public static func issueCredential(groupMembers: [UuidCiphertext], requestingMember: UuidCiphertext, expiration: Date = GroupSendCredentialResponse.defaultExpiration(), params: ServerSecretParams) -> GroupSendCredentialResponse {
return failOnError {
issueCredential(groupMembers: groupMembers, requestingMember: requestingMember, expiration: expiration, params: params, randomness: try .generate())
}
}
/**
* Issues a new credential stating that `requestingMember` is a member of a group containing
* `groupMembers`, with an explictly-chosen source of randomness.
*
* Should only be used for testing purposes.
*
* - SeeAlso: ``issueCredential(groupMembers:requestingMember:expiration:params:)``
*/
public static func issueCredential(groupMembers: [UuidCiphertext], requestingMember: UuidCiphertext, expiration: Date = GroupSendCredentialResponse.defaultExpiration(), params: ServerSecretParams, randomness: Randomness) -> GroupSendCredentialResponse {
let concatenated = groupMembers.flatMap { $0.serialize() }
return failOnError {
return try concatenated.withUnsafeBorrowedBuffer { concatenated in
try requestingMember.withUnsafePointerToSerialized { requestingMember in
try params.withUnsafePointerToSerialized { params in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_group_send_credential_response_issue_deterministic(
$0,
concatenated,
requestingMember,
UInt64(expiration.timeIntervalSince1970),
params,
randomness)
}
public static func defaultExpiration() -> Date {
let expiration = failOnError {
try invokeFnReturningInteger {
signal_group_send_credential_response_default_expiration_based_on_current_time($0)
}
}
}
}
return Date(timeIntervalSince1970: TimeInterval(expiration))
}
}
/**
* Receives, validates, and extracts the credential from a response.
*
* Note that the `receive` operation is provided for both ``ServiceId``s and ``UuidCiphertext``s.
* If you already have the ciphertexts for the group members available,
* ``receive(groupMembers:localUser:now:serverParams:groupParams:)-5ipwi`` will be *significantly*
* faster; if you don't, this method is faster than generating the ciphertexts and throwing them
* away afterwards.
*
* `localUser` should be included in `groupMembers`.
*
* - Throws: ``SignalError/verificationFailed(_:)`` if the credential is not valid for any reason
*/
public func receive(groupMembers: [ServiceId], localUser: Aci, now: Date = Date(), serverParams: ServerPublicParams, groupParams: GroupSecretParams) throws -> GroupSendCredential {
return try withUnsafeBorrowedBuffer { response in
try ServiceId.concatenatedFixedWidthBinary(groupMembers).withUnsafeBorrowedBuffer { groupMembers in
try localUser.withPointerToFixedWidthBinary { localUser in
try serverParams.withUnsafePointerToSerialized { serverParams in
try groupParams.withUnsafePointerToSerialized { groupParams in
try invokeFnReturningVariableLengthSerialized {
signal_group_send_credential_response_receive($0, response, groupMembers, localUser, UInt64(now.timeIntervalSince1970), serverParams, groupParams)
}
}
}
/**
* Issues a new credential stating that `requestingMember` is a member of a group containing
* `groupMembers`.
*
* `groupMembers` should include `requestingMember` as well.
*/
public static func issueCredential(groupMembers: [UuidCiphertext], requestingMember: UuidCiphertext, expiration: Date = GroupSendCredentialResponse.defaultExpiration(), params: ServerSecretParams) -> GroupSendCredentialResponse {
return failOnError {
self.issueCredential(groupMembers: groupMembers, requestingMember: requestingMember, expiration: expiration, params: params, randomness: try .generate())
}
}
}
}
/**
* Receives, validates, and extracts the credential from a response.
*
* Note that the `receive` operation is provided for both ``ServiceId``s and ``UuidCiphertext``s.
* If you already have the ciphertexts for the group members available, this method will be
* *significantly* faster; if you don't,
* ``receive(groupMembers:localUser:now:serverParams:groupParams:)-4eco5`` is faster than
* generating the ciphertexts and
* throwing them away afterwards.
*
* `localUser` should be included in `groupMembers`.
*
* - Throws: ``SignalError/verificationFailed(_:)`` if the credential is not valid for any reason
*/
public func receive(groupMembers: [UuidCiphertext], localUser: UuidCiphertext, now: Date = Date(), serverParams: ServerPublicParams, groupParams: GroupSecretParams) throws -> GroupSendCredential {
return try withUnsafeBorrowedBuffer { response in
try groupMembers.flatMap { $0.serialize() }.withUnsafeBorrowedBuffer { groupMembers in
try localUser.withUnsafePointerToSerialized { localUser in
try serverParams.withUnsafePointerToSerialized { serverParams in
try groupParams.withUnsafePointerToSerialized { groupParams in
try invokeFnReturningVariableLengthSerialized {
signal_group_send_credential_response_receive_with_ciphertexts($0, response, groupMembers, localUser, UInt64(now.timeIntervalSince1970), serverParams, groupParams)
}
/**
* Issues a new credential stating that `requestingMember` is a member of a group containing
* `groupMembers`, with an explictly-chosen source of randomness.
*
* Should only be used for testing purposes.
*
* - SeeAlso: ``issueCredential(groupMembers:requestingMember:expiration:params:)``
*/
public static func issueCredential(groupMembers: [UuidCiphertext], requestingMember: UuidCiphertext, expiration: Date = GroupSendCredentialResponse.defaultExpiration(), params: ServerSecretParams, randomness: Randomness) -> GroupSendCredentialResponse {
let concatenated = groupMembers.flatMap { $0.serialize() }
return failOnError {
try concatenated.withUnsafeBorrowedBuffer { concatenated in
try requestingMember.withUnsafePointerToSerialized { requestingMember in
try params.withUnsafePointerToSerialized { params in
try randomness.withUnsafePointerToBytes { randomness in
try invokeFnReturningVariableLengthSerialized {
signal_group_send_credential_response_issue_deterministic(
$0,
concatenated,
requestingMember,
UInt64(expiration.timeIntervalSince1970),
params,
randomness
)
}
}
}
}
}
}
}
/**
* Receives, validates, and extracts the credential from a response.
*
* Note that the `receive` operation is provided for both ``ServiceId``s and ``UuidCiphertext``s.
* If you already have the ciphertexts for the group members available,
* ``receive(groupMembers:localUser:now:serverParams:groupParams:)-5ipwi`` will be *significantly*
* faster; if you don't, this method is faster than generating the ciphertexts and throwing them
* away afterwards.
*
* `localUser` should be included in `groupMembers`.
*
* - Throws: ``SignalError/verificationFailed(_:)`` if the credential is not valid for any reason
*/
public func receive(groupMembers: [ServiceId], localUser: Aci, now: Date = Date(), serverParams: ServerPublicParams, groupParams: GroupSecretParams) throws -> GroupSendCredential {
return try withUnsafeBorrowedBuffer { response in
try ServiceId.concatenatedFixedWidthBinary(groupMembers).withUnsafeBorrowedBuffer { groupMembers in
try localUser.withPointerToFixedWidthBinary { localUser in
try serverParams.withUnsafePointerToSerialized { serverParams in
try groupParams.withUnsafePointerToSerialized { groupParams in
try invokeFnReturningVariableLengthSerialized {
signal_group_send_credential_response_receive($0, response, groupMembers, localUser, UInt64(now.timeIntervalSince1970), serverParams, groupParams)
}
}
}
}
}
}
}
/**
* Receives, validates, and extracts the credential from a response.
*
* Note that the `receive` operation is provided for both ``ServiceId``s and ``UuidCiphertext``s.
* If you already have the ciphertexts for the group members available, this method will be
* *significantly* faster; if you don't,
* ``receive(groupMembers:localUser:now:serverParams:groupParams:)-4eco5`` is faster than
* generating the ciphertexts and
* throwing them away afterwards.
*
* `localUser` should be included in `groupMembers`.
*
* - Throws: ``SignalError/verificationFailed(_:)`` if the credential is not valid for any reason
*/
public func receive(groupMembers: [UuidCiphertext], localUser: UuidCiphertext, now: Date = Date(), serverParams: ServerPublicParams, groupParams: GroupSecretParams) throws -> GroupSendCredential {
return try withUnsafeBorrowedBuffer { response in
try groupMembers.flatMap { $0.serialize() }.withUnsafeBorrowedBuffer { groupMembers in
try localUser.withUnsafePointerToSerialized { localUser in
try serverParams.withUnsafePointerToSerialized { serverParams in
try groupParams.withUnsafePointerToSerialized { groupParams in
try invokeFnReturningVariableLengthSerialized {
signal_group_send_credential_response_receive_with_ciphertexts($0, response, groupMembers, localUser, UInt64(now.timeIntervalSince1970), serverParams, groupParams)
}
}
}
}
}
}
}
}
}
}
}

View File

@ -4,11 +4,9 @@
//
public class NotarySignature: ByteArray {
public static let SIZE: Int = 64
public static let SIZE: Int = 64
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: NotarySignature.SIZE)
}
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: NotarySignature.SIZE)
}
}

View File

@ -7,41 +7,39 @@ import Foundation
import SignalFfi
public class ProfileKey: ByteArray {
public static let SIZE: Int = 32
public static let SIZE: Int = 32
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: ProfileKey.SIZE)
}
public func getCommitment(userId: Aci) throws -> ProfileKeyCommitment {
return try withUnsafePointerToSerialized { contents in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_profile_key_get_commitment($0, contents, userId)
}
}
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: ProfileKey.SIZE)
}
}
public func getProfileKeyVersion(userId: Aci) throws -> ProfileKeyVersion {
return try withUnsafePointerToSerialized { contents in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_profile_key_get_profile_key_version($0, contents, userId)
public func getCommitment(userId: Aci) throws -> ProfileKeyCommitment {
return try withUnsafePointerToSerialized { contents in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_profile_key_get_commitment($0, contents, userId)
}
}
}
}
}
}
public func deriveAccessKey() -> [UInt8] {
return failOnError {
try withUnsafePointerToSerialized { contents in
try invokeFnReturningFixedLengthArray {
signal_profile_key_derive_access_key($0, contents)
public func getProfileKeyVersion(userId: Aci) throws -> ProfileKeyVersion {
return try withUnsafePointerToSerialized { contents in
try userId.withPointerToFixedWidthBinary { userId in
try invokeFnReturningSerialized {
signal_profile_key_get_profile_key_version($0, contents, userId)
}
}
}
}
}
}
public func deriveAccessKey() -> [UInt8] {
return failOnError {
try withUnsafePointerToSerialized { contents in
try invokeFnReturningFixedLengthArray {
signal_profile_key_derive_access_key($0, contents)
}
}
}
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class ProfileKeyCiphertext: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_ciphertext_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_ciphertext_check_valid_contents)
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class ProfileKeyCommitment: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_commitment_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_commitment_check_valid_contents)
}
}

View File

@ -7,25 +7,23 @@ import Foundation
import SignalFfi
public class ProfileKeyCredentialPresentation: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_credential_presentation_check_valid_contents)
}
public func getUuidCiphertext() throws -> UuidCiphertext {
return try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningSerialized {
signal_profile_key_credential_presentation_get_uuid_ciphertext($0, buffer)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_credential_presentation_check_valid_contents)
}
}
public func getProfileKeyCiphertext() throws -> ProfileKeyCiphertext {
return try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningSerialized {
signal_profile_key_credential_presentation_get_profile_key_ciphertext($0, buffer)
}
public func getUuidCiphertext() throws -> UuidCiphertext {
return try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningSerialized {
signal_profile_key_credential_presentation_get_uuid_ciphertext($0, buffer)
}
}
}
}
public func getProfileKeyCiphertext() throws -> ProfileKeyCiphertext {
return try withUnsafeBorrowedBuffer { buffer in
try invokeFnReturningSerialized {
signal_profile_key_credential_presentation_get_profile_key_ciphertext($0, buffer)
}
}
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class ProfileKeyCredentialRequest: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_credential_request_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_credential_request_check_valid_contents)
}
}

View File

@ -7,17 +7,15 @@ import Foundation
import SignalFfi
public class ProfileKeyCredentialRequestContext: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_credential_request_context_check_valid_contents)
}
public func getRequest() throws -> ProfileKeyCredentialRequest {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_profile_key_credential_request_context_get_request($0, contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_profile_key_credential_request_context_check_valid_contents)
}
}
public func getRequest() throws -> ProfileKeyCredentialRequest {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_profile_key_credential_request_context_get_request($0, contents)
}
}
}
}

View File

@ -4,11 +4,9 @@
//
public class ProfileKeyVersion: ByteArray {
public static let SIZE: Int = 64
public static let SIZE: Int = 64
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: ProfileKeyVersion.SIZE)
}
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: ProfileKeyVersion.SIZE)
}
}

View File

@ -7,25 +7,23 @@ import Foundation
import SignalFfi
public class ReceiptCredential: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_check_valid_contents)
}
public func getReceiptExpirationTime() throws -> UInt64 {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_receipt_credential_get_receipt_expiration_time($0, contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_check_valid_contents)
}
}
public func getReceiptLevel() throws -> UInt64 {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_receipt_credential_get_receipt_level($0, contents)
}
public func getReceiptExpirationTime() throws -> UInt64 {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_receipt_credential_get_receipt_expiration_time($0, contents)
}
}
}
}
public func getReceiptLevel() throws -> UInt64 {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_receipt_credential_get_receipt_level($0, contents)
}
}
}
}

View File

@ -7,33 +7,31 @@ import Foundation
import SignalFfi
public class ReceiptCredentialPresentation: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_presentation_check_valid_contents)
}
public func getReceiptExpirationTime() throws -> UInt64 {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_receipt_credential_presentation_get_receipt_expiration_time($0, contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_presentation_check_valid_contents)
}
}
public func getReceiptLevel() throws -> UInt64 {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_receipt_credential_presentation_get_receipt_level($0, contents)
}
public func getReceiptExpirationTime() throws -> UInt64 {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_receipt_credential_presentation_get_receipt_expiration_time($0, contents)
}
}
}
}
public func getReceiptSerial() throws -> ReceiptSerial {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_receipt_credential_presentation_get_receipt_serial($0, contents)
}
public func getReceiptLevel() throws -> UInt64 {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningInteger {
signal_receipt_credential_presentation_get_receipt_level($0, contents)
}
}
}
}
public func getReceiptSerial() throws -> ReceiptSerial {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_receipt_credential_presentation_get_receipt_serial($0, contents)
}
}
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class ReceiptCredentialRequest: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_request_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_request_check_valid_contents)
}
}

View File

@ -7,17 +7,15 @@ import Foundation
import SignalFfi
public class ReceiptCredentialRequestContext: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_request_context_check_valid_contents)
}
public func getRequest() throws -> ReceiptCredentialRequest {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_receipt_credential_request_context_get_request($0, contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_request_context_check_valid_contents)
}
}
public func getRequest() throws -> ReceiptCredentialRequest {
return try withUnsafePointerToSerialized { contents in
try invokeFnReturningSerialized {
signal_receipt_credential_request_context_get_request($0, contents)
}
}
}
}

View File

@ -7,7 +7,7 @@ import Foundation
import SignalFfi
public class ReceiptCredentialResponse: ByteArray {
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_response_check_valid_contents)
}
public required init(contents: [UInt8]) throws {
try super.init(contents, checkValid: signal_receipt_credential_response_check_valid_contents)
}
}

View File

@ -4,11 +4,9 @@
//
public class ReceiptSerial: ByteArray {
public static let SIZE: Int = 16
public static let SIZE: Int = 16
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: ReceiptSerial.SIZE)
}
public required init(contents: [UInt8]) throws {
try super.init(newContents: contents, expectedLength: ReceiptSerial.SIZE)
}
}

Some files were not shown because too many files have changed in this diff Show More