mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-03 04:52:19 +02:00
swift-format is owned by the Swift project and is generally less opinionated than swiftformat (but better at formatting to a limited line length).
55 lines
1.9 KiB
Swift
55 lines
1.9 KiB
Swift
//
|
|
// Copyright 2023 Signal Messenger, LLC.
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
import SignalFfi
|
|
|
|
public class BackupAuthCredentialRequestContext: ByteArray, @unchecked Sendable {
|
|
public required init(contents: Data) throws {
|
|
try super.init(contents, checkValid: signal_backup_auth_credential_request_context_check_valid_contents)
|
|
}
|
|
|
|
public static func create<BackupKey: ContiguousBytes>(backupKey: BackupKey, aci: UUID) -> Self {
|
|
return failOnError {
|
|
let backupKeyBytes = try backupKey.withUnsafeBytes {
|
|
try ByteArray(newContents: Data($0), expectedLength: 32)
|
|
}
|
|
return try withAllBorrowed(.fixed(backupKeyBytes), aci) { backupKeyTuple, uuid in
|
|
try invokeFnReturningVariableLengthSerialized {
|
|
signal_backup_auth_credential_request_context_new($0, backupKeyTuple, uuid)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public func getRequest() -> BackupAuthCredentialRequest {
|
|
return failOnError {
|
|
try withUnsafeBorrowedBuffer { contents in
|
|
try invokeFnReturningVariableLengthSerialized {
|
|
signal_backup_auth_credential_request_context_get_request($0, contents)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public func receive(
|
|
_ response: BackupAuthCredentialResponse,
|
|
timestamp: Date,
|
|
params: GenericServerPublicParams
|
|
) throws -> BackupAuthCredential {
|
|
return try withAllBorrowed(self, response, params) { contents, response, params in
|
|
try invokeFnReturningVariableLengthSerialized {
|
|
signal_backup_auth_credential_request_context_receive_response(
|
|
$0,
|
|
contents,
|
|
response,
|
|
UInt64(timestamp.timeIntervalSince1970),
|
|
params
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|