diff --git a/ios/MullvadSettings/WireGuardObfuscationSettings.swift b/ios/MullvadSettings/WireGuardObfuscationSettings.swift index 7259c970591f..e55ac8538af7 100644 --- a/ios/MullvadSettings/WireGuardObfuscationSettings.swift +++ b/ios/MullvadSettings/WireGuardObfuscationSettings.swift @@ -20,7 +20,7 @@ public enum WireGuardObfuscationState: Codable { /// The port to select when using UDP-over-TCP obfuscation /// /// `.automatic` means an algorith will decide between using `port80` or `port5001` -public enum WireGuardObfuscationPort: UInt16, Codable { +public enum WireGuardObfuscationPort: UInt16, Codable, CaseIterable { case automatic = 0 case port80 = 80 case port5001 = 5001 @@ -40,6 +40,14 @@ public enum WireGuardObfuscationPort: UInt16, Codable { default: self = .automatic } } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + let decodedValue = try? container.decode(UInt16.self) + + let port = WireGuardObfuscationPort.allCases.first(where: { $0.rawValue == decodedValue }) + self = port ?? .automatic + } } public struct WireGuardObfuscationSettings: Codable, Equatable {