Signal-iOS/SignalServiceKit/SecureValueRecovery/SgxWebsocketConnectionFactory.swift
2026-05-26 17:48:41 -05:00

46 lines
1.5 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
import LibSignalClient
// MARK: -
public protocol SgxWebsocketConnectionFactory {
/// Connect to an SgxClient-conformant server via websocket and perform the initial handshake.
///
/// - Parameters:
/// - queue: The queue to use.
/// - Returns:
/// A Promise for an established connection. If the Promise doesnt
/// resolve to an error, the caller is responsible for ensuring the
/// returned connection is properly disconnected.
func connectAndPerformHandshake<Configurator: SgxWebsocketConfigurator>(
configurator: Configurator,
) async throws -> SgxWebsocketConnection<Configurator>
}
final class SgxWebsocketConnectionFactoryImpl: SgxWebsocketConnectionFactory {
private let websocketFactory: WebSocketFactory
init(websocketFactory: WebSocketFactory) {
self.websocketFactory = websocketFactory
}
func connectAndPerformHandshake<Configurator: SgxWebsocketConfigurator>(
configurator: Configurator,
) async throws -> SgxWebsocketConnection<Configurator> {
let websocketFactory = self.websocketFactory
let auth = try await configurator.fetchAuth()
return try await SgxWebsocketConnectionImpl<Configurator>.connectAndPerformHandshake(
configurator: configurator,
auth: auth,
websocketFactory: websocketFactory,
)
}
}