diff options
| author | Andrew Bulhak <andrew.bulhak@mullvad.net> | 2025-07-31 16:08:26 +0200 |
|---|---|---|
| committer | Andrew Bulhak <andrew.bulhak@mullvad.net> | 2025-08-04 15:41:28 +0200 |
| commit | ab927b72ac7337ccc048057954bb2858370a907f (patch) | |
| tree | 7e571b72a931103c231cd1e97dfd4318a52f7606 | |
| parent | 44d47dd4c360e644df505460e7a79ba09849d82b (diff) | |
| download | mullvadvpn-ab927b72ac7337ccc048057954bb2858370a907f.tar.xz mullvadvpn-ab927b72ac7337ccc048057954bb2858370a907f.zip | |
Make the code more concise/idiomatic/better organised
| -rw-r--r-- | ios/MullvadRustRuntime/MullvadApiContext.swift | 4 | ||||
| -rw-r--r-- | ios/MullvadRustRuntime/MullvadApiResponse.swift | 18 | ||||
| -rw-r--r-- | ios/MullvadTypes/PersistentAccessMethod.swift | 92 | ||||
| -rw-r--r-- | ios/MullvadTypes/PersistentProxyConfiguration.swift | 99 | ||||
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 4 |
5 files changed, 108 insertions, 109 deletions
diff --git a/ios/MullvadRustRuntime/MullvadApiContext.swift b/ios/MullvadRustRuntime/MullvadApiContext.swift index bd89ab891f..7600b79e70 100644 --- a/ios/MullvadRustRuntime/MullvadApiContext.swift +++ b/ios/MullvadRustRuntime/MullvadApiContext.swift @@ -9,7 +9,7 @@ import MullvadTypes public struct MullvadApiContext: @unchecked Sendable { - enum MullvadApiContextError: Error { + enum Error: Swift.Error { case failedToConstructApiClient } @@ -58,7 +58,7 @@ public struct MullvadApiContext: @unchecked Sendable { } if context._0 == nil { - throw MullvadApiContextError.failedToConstructApiClient + throw Error.failedToConstructApiClient } } } diff --git a/ios/MullvadRustRuntime/MullvadApiResponse.swift b/ios/MullvadRustRuntime/MullvadApiResponse.swift index ddead026b3..597de40b75 100644 --- a/ios/MullvadRustRuntime/MullvadApiResponse.swift +++ b/ios/MullvadRustRuntime/MullvadApiResponse.swift @@ -26,19 +26,11 @@ public class MullvadApiResponse { } public var etag: String? { - return if response.etag == nil { - nil - } else { - String(cString: response.etag) - } + response.etag.map { String(cString: $0) } } public var errorDescription: String? { - return if response.error_description == nil { - nil - } else { - String(cString: response.error_description) - } + response.error_description.map { String(cString: $0) } } public var statusCode: UInt16 { @@ -46,11 +38,7 @@ public class MullvadApiResponse { } public var serverResponseCode: String? { - return if response.server_response_code == nil { - nil - } else { - String(cString: response.server_response_code) - } + response.server_response_code.map { String(cString: $0) } } public var success: Bool { diff --git a/ios/MullvadTypes/PersistentAccessMethod.swift b/ios/MullvadTypes/PersistentAccessMethod.swift index ff816405b6..602a0995f5 100644 --- a/ios/MullvadTypes/PersistentAccessMethod.swift +++ b/ios/MullvadTypes/PersistentAccessMethod.swift @@ -61,95 +61,3 @@ public struct PersistentAccessMethod: Identifiable, Codable, Equatable, Sendable lhs.id == rhs.id } } - -/// Persistent proxy configuration. -public enum PersistentProxyConfiguration: Codable, Equatable, Sendable { - /// Direct communication without proxy. - case direct - - /// Communication over bridges. - case bridges - - /// Communication over proxy address from a DNS. - case encryptedDNS - - /// Communication over shadowsocks. - case shadowsocks(ShadowsocksConfiguration) - - /// Communication over socks5 proxy. - case socks5(SocksConfiguration) -} - -extension PersistentProxyConfiguration { - /// Socks autentication method. - public enum SocksAuthentication: Codable, Equatable, Sendable { - case noAuthentication - case authentication(UserCredential) - } - - public struct UserCredential: Codable, Equatable, Sendable { - public let username: String - public let password: String - - public init(username: String, password: String) { - self.username = username - self.password = password - } - } - - /// Socks v5 proxy configuration. - public struct SocksConfiguration: Codable, Equatable, Sendable { - /// Proxy server address. - public var server: AnyIPAddress - - /// Proxy server port. - public var port: UInt16 - - /// Authentication method. - public var authentication: SocksAuthentication - - public init(server: AnyIPAddress, port: UInt16, authentication: SocksAuthentication) { - self.server = server - self.port = port - self.authentication = authentication - } - - public var credential: UserCredential? { - guard case let .authentication(credential) = authentication else { - return nil - } - return credential - } - - public var toAnyIPEndpoint: AnyIPEndpoint { - switch server { - case let .ipv4(ip): - return .ipv4(IPv4Endpoint(ip: ip, port: port)) - case let .ipv6(ip): - return .ipv6(IPv6Endpoint(ip: ip, port: port)) - } - } - } - - /// Shadowsocks configuration. - public struct ShadowsocksConfiguration: Codable, Equatable, Sendable { - /// Server address. - public var server: AnyIPAddress - - /// Server port. - public var port: UInt16 - - /// Server password. - public var password: String - - /// Server cipher. - public var cipher: ShadowsocksCipherOptions - - public init(server: AnyIPAddress, port: UInt16, password: String, cipher: ShadowsocksCipherOptions) { - self.server = server - self.port = port - self.password = password - self.cipher = cipher - } - } -} diff --git a/ios/MullvadTypes/PersistentProxyConfiguration.swift b/ios/MullvadTypes/PersistentProxyConfiguration.swift new file mode 100644 index 0000000000..2978acc2fc --- /dev/null +++ b/ios/MullvadTypes/PersistentProxyConfiguration.swift @@ -0,0 +1,99 @@ +// +// PersistentProxyConfiguration.swift +// MullvadVPN +// +// Created by Andrew Bulhak on 2025-07-31. +// Copyright © 2025 Mullvad VPN AB. All rights reserved. +// + +/// Persistent proxy configuration; formerly contained in PersistentAccessMethod.swift. +public enum PersistentProxyConfiguration: Codable, Equatable, Sendable { + /// Direct communication without proxy. + case direct + + /// Communication over bridges. + case bridges + + /// Communication over proxy address from a DNS. + case encryptedDNS + + /// Communication over shadowsocks. + case shadowsocks(ShadowsocksConfiguration) + + /// Communication over socks5 proxy. + case socks5(SocksConfiguration) +} + +extension PersistentProxyConfiguration { + /// Socks autentication method. + public enum SocksAuthentication: Codable, Equatable, Sendable { + case noAuthentication + case authentication(UserCredential) + } + + public struct UserCredential: Codable, Equatable, Sendable { + public let username: String + public let password: String + + public init(username: String, password: String) { + self.username = username + self.password = password + } + } + + /// Socks v5 proxy configuration. + public struct SocksConfiguration: Codable, Equatable, Sendable { + /// Proxy server address. + public var server: AnyIPAddress + + /// Proxy server port. + public var port: UInt16 + + /// Authentication method. + public var authentication: SocksAuthentication + + public init(server: AnyIPAddress, port: UInt16, authentication: SocksAuthentication) { + self.server = server + self.port = port + self.authentication = authentication + } + + public var credential: UserCredential? { + guard case let .authentication(credential) = authentication else { + return nil + } + return credential + } + + public var toAnyIPEndpoint: AnyIPEndpoint { + switch server { + case let .ipv4(ip): + return .ipv4(IPv4Endpoint(ip: ip, port: port)) + case let .ipv6(ip): + return .ipv6(IPv6Endpoint(ip: ip, port: port)) + } + } + } + + /// Shadowsocks configuration. + public struct ShadowsocksConfiguration: Codable, Equatable, Sendable { + /// Server address. + public var server: AnyIPAddress + + /// Server port. + public var port: UInt16 + + /// Server password. + public var password: String + + /// Server cipher. + public var cipher: ShadowsocksCipherOptions + + public init(server: AnyIPAddress, port: UInt16, password: String, cipher: ShadowsocksCipherOptions) { + self.server = server + self.port = port + self.password = password + self.cipher = cipher + } + } +} diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index b0bd9e504a..3df113f19b 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -93,6 +93,7 @@ 44E1F7582D3EA83A003A60FF /* DestinationDescriber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44E1F7572D3EA82C003A60FF /* DestinationDescriber.swift */; }; 44E1F75A2D3FDCCA003A60FF /* DestinationDescriberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44E1F7592D3FDCBA003A60FF /* DestinationDescriberTests.swift */; }; 44E1F75B2D3FEC81003A60FF /* DestinationDescriber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44E1F7572D3EA82C003A60FF /* DestinationDescriber.swift */; }; + 44EC6C5A2E3BB3F60087F54A /* PersistentProxyConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44EC6C592E3BB3EF0087F54A /* PersistentProxyConfiguration.swift */; }; 5803B4B02940A47300C23744 /* TunnelConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5803B4AF2940A47300C23744 /* TunnelConfiguration.swift */; }; 5803B4B22940A48700C23744 /* TunnelStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5803B4B12940A48700C23744 /* TunnelStore.swift */; }; 5807E2C02432038B00F5FF30 /* String+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5807E2BF2432038B00F5FF30 /* String+Helpers.swift */; }; @@ -1678,6 +1679,7 @@ 44DF8AC32BF20BD200869CA4 /* PacketTunnelActor+PostQuantum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PacketTunnelActor+PostQuantum.swift"; sourceTree = "<group>"; }; 44E1F7572D3EA82C003A60FF /* DestinationDescriber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DestinationDescriber.swift; sourceTree = "<group>"; }; 44E1F7592D3FDCBA003A60FF /* DestinationDescriberTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DestinationDescriberTests.swift; sourceTree = "<group>"; }; + 44EC6C592E3BB3EF0087F54A /* PersistentProxyConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistentProxyConfiguration.swift; sourceTree = "<group>"; }; 5802EBC42A8E44AC00E5CE4C /* AppRoutes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppRoutes.swift; sourceTree = "<group>"; }; 5802EBC62A8E457A00E5CE4C /* AppRouteProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppRouteProtocol.swift; sourceTree = "<group>"; }; 5802EBC82A8E45BA00E5CE4C /* ApplicationRouterDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationRouterDelegate.swift; sourceTree = "<group>"; }; @@ -3101,6 +3103,7 @@ A97FF54F2A0D2FFC00900996 /* NSFileCoordinator+Extensions.swift */, 58CC40EE24A601900019D96E /* ObserverList.swift */, 586C0D962B04E0AC00E7CDD7 /* PersistentAccessMethod.swift */, + 44EC6C592E3BB3EF0087F54A /* PersistentProxyConfiguration.swift */, 58CAFA01298530DC00BE19F7 /* Promise.swift */, 449EBA242B975B7C00DFA4EB /* Protocols */, 5898D2B12902A6DE00EB5EBA /* RelayConstraint.swift */, @@ -6872,6 +6875,7 @@ F0ADF1CD2CFDFF3100299F09 /* StringConversionError.swift in Sources */, A9A8A8EB2A262AB30086D569 /* FileCache.swift in Sources */, A90C48692C36BF3900DCB94C /* TunnelProvider.swift in Sources */, + 44EC6C5A2E3BB3F60087F54A /* PersistentProxyConfiguration.swift in Sources */, 58D2240D294C90210029F5F8 /* CustomErrorDescriptionProtocol.swift in Sources */, A98207EF2D9192A300654558 /* ShadowsocksBridgeProviding.swift in Sources */, 58D2240E294C90210029F5F8 /* Error+Chain.swift in Sources */, |
