Skip to content

Commit

Permalink
Update settings schema to V4 to fix a migration bug in obfuscation se…
Browse files Browse the repository at this point in the history
…ttings
  • Loading branch information
Jon Petersson committed Dec 4, 2023
1 parent 233d384 commit 738dda4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ios/MullvadSettings/WireGuardObfuscationSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 738dda4

Please sign in to comment.