From 57ba6e3f3419e0db626bead5499b18e3e6b6ab90 Mon Sep 17 00:00:00 2001 From: Andrew Bulhak Date: Thu, 4 Apr 2024 14:55:16 +0200 Subject: [PATCH] Move KeyPolicy under State's namespace --- .../Actor/PacketTunnelActor+KeyPolicy.swift | 2 +- .../Actor/PacketTunnelActor.swift | 2 +- .../Actor/State+Extensions.swift | 6 +++--- ios/PacketTunnelCore/Actor/State.swift | 20 +++++++++---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ios/PacketTunnelCore/Actor/PacketTunnelActor+KeyPolicy.swift b/ios/PacketTunnelCore/Actor/PacketTunnelActor+KeyPolicy.swift index 1636e8454292..9181a73edfd5 100644 --- a/ios/PacketTunnelCore/Actor/PacketTunnelActor+KeyPolicy.swift +++ b/ios/PacketTunnelCore/Actor/PacketTunnelActor+KeyPolicy.swift @@ -90,7 +90,7 @@ extension PacketTunnelActor { - Parameter keyPolicy: a reference to key policy held either in connection state or blocked state struct. - Returns: `true` when the policy was modified, otherwise `false`. */ - private func setCurrentKeyPolicy(_ keyPolicy: inout KeyPolicy) { + private func setCurrentKeyPolicy(_ keyPolicy: inout State.KeyPolicy) { if case .usePrior = keyPolicy { keyPolicy = .useCurrent } diff --git a/ios/PacketTunnelCore/Actor/PacketTunnelActor.swift b/ios/PacketTunnelCore/Actor/PacketTunnelActor.swift index 4ec5b99de234..81b3bfaff179 100644 --- a/ios/PacketTunnelCore/Actor/PacketTunnelActor.swift +++ b/ios/PacketTunnelCore/Actor/PacketTunnelActor.swift @@ -305,7 +305,7 @@ extension PacketTunnelActor { settings: Settings, reason: ReconnectReason ) throws -> State.ConnectionData? { - var keyPolicy: KeyPolicy = .useCurrent + var keyPolicy: State.KeyPolicy = .useCurrent var networkReachability = defaultPathObserver.defaultPath?.networkReachability ?? .undetermined var lastKeyRotation: Date? diff --git a/ios/PacketTunnelCore/Actor/State+Extensions.swift b/ios/PacketTunnelCore/Actor/State+Extensions.swift index d6ea62a7ab2d..45b28a0c9c32 100644 --- a/ios/PacketTunnelCore/Actor/State+Extensions.swift +++ b/ios/PacketTunnelCore/Actor/State+Extensions.swift @@ -154,7 +154,7 @@ extension State { } } -extension KeyPolicy { +extension State.KeyPolicy { func logFormat() -> String { switch self { case .useCurrent: @@ -165,8 +165,8 @@ extension KeyPolicy { } } -extension KeyPolicy: Equatable { - static func == (lhs: KeyPolicy, rhs: KeyPolicy) -> Bool { +extension State.KeyPolicy: Equatable { + static func == (lhs: State.KeyPolicy, rhs: State.KeyPolicy) -> Bool { switch (lhs, rhs) { case (.useCurrent, .useCurrent): true case let (.usePrior(priorA, _), .usePrior(priorB, _)): priorA == priorB diff --git a/ios/PacketTunnelCore/Actor/State.swift b/ios/PacketTunnelCore/Actor/State.swift index f65fdea515a4..ab3fe767c937 100644 --- a/ios/PacketTunnelCore/Actor/State.swift +++ b/ios/PacketTunnelCore/Actor/State.swift @@ -82,15 +82,6 @@ enum State: Equatable { case error(BlockingData) } -/// Policy describing what WG key to use for tunnel communication. -enum KeyPolicy { - /// Use current key stored in device data. - case useCurrent - - /// Use prior key until timer fires. - case usePrior(_ priorKey: PrivateKey, _ timerTask: AutoCancellingTask) -} - /// Enum describing network availability. public enum NetworkReachability: Equatable, Codable { case undetermined, reachable, unreachable @@ -98,12 +89,21 @@ public enum NetworkReachability: Equatable, Codable { protocol StateAssociatedData { var currentKey: PrivateKey? { get set } - var keyPolicy: KeyPolicy { get set } + var keyPolicy: State.KeyPolicy { get set } var networkReachability: NetworkReachability { get set } var lastKeyRotation: Date? { get set } } extension State { + /// Policy describing what WG key to use for tunnel communication. + enum KeyPolicy { + /// Use current key stored in device data. + case useCurrent + + /// Use prior key until timer fires. + case usePrior(_ priorKey: PrivateKey, _ timerTask: AutoCancellingTask) + } + /// Data associated with states that hold connection data. struct ConnectionData: Equatable, StateAssociatedData { /// Current selected relay.