Files
libsignal/swift/Sources/LibSignalClient/zkgroup/CreateCallLinkCredentialRequestContext.swift
Jordan Rose 6a547bf3f2 zkgroup: Use ServiceId and Aci in public APIs instead of UidBytes
Some of these APIs have to match up with UuidCiphertexts, and so we
convert them all for consistency.
2023-07-20 12:26:46 -07:00

58 lines
1.9 KiB
Swift

//
// Copyright 2023 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
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 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)
}
}
}
}
}
}
}