Move VPNProtocolType serialization to Data layer (#318)
It's crucial that the data layer has full control over how entities are (de)serialized. Do not leave this choice up to the domain layer by defining an enum as a raw value type, because any change in the enum raw value would literally be a disaster, i.e. _any_ serialized data would break instantly.
This commit is contained in:
parent
278efaf347
commit
ddf3dc313f
|
@ -7,13 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## Unreleased
|
||||
|
||||
### Changed
|
||||
|
||||
- Internal error handling. [#310](https://github.com/passepartoutvpn/passepartout-apple/pull/310)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Allow wildcards in proxy bypass domains. [#296](https://github.com/passepartoutvpn/passepartout-apple/issues/296)
|
||||
- Fail gracefully when refreshing infrastructure. [#307](https://github.com/passepartoutvpn/passepartout-apple/pull/307)
|
||||
- Only show 'Reconnect' on active profile. [#311](https://github.com/passepartoutvpn/passepartout-apple/pull/311)
|
||||
- IPv4/6 address validation. [#308](https://github.com/passepartoutvpn/passepartout-apple/pull/308)
|
||||
- Domain name validation. [#297](https://github.com/passepartoutvpn/passepartout-apple/pull/297)
|
||||
|
||||
## 2.1.1 (2023-04-19)
|
||||
|
||||
|
|
|
@ -25,11 +25,10 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
// FIXME: arch, provide a well-defined serialization property rather than .rawValue
|
||||
public enum VPNProtocolType: String, CaseIterable, Codable {
|
||||
case openVPN = "ovpn"
|
||||
public enum VPNProtocolType: CaseIterable, Codable {
|
||||
case openVPN
|
||||
|
||||
case wireGuard = "wg"
|
||||
case wireGuard
|
||||
}
|
||||
|
||||
public protocol VPNProtocolProviding {
|
||||
|
|
|
@ -57,7 +57,7 @@ extension ProviderServer: Identifiable {
|
|||
}
|
||||
|
||||
public static func id(withName providerName: ProviderName, vpnProtocol: VPNProtocolType, apiId: String) -> String? {
|
||||
let idSource = [providerName, vpnProtocol.rawValue, apiId].joined(separator: ":")
|
||||
let idSource = [providerName, "\(vpnProtocol)", apiId].joined(separator: ":")
|
||||
guard let data = idSource.data(using: .utf8) else {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// VPNProtocolType+RawRepresentable.swift
|
||||
// Passepartout
|
||||
//
|
||||
// Created by Davide De Rosa on 7/2/23.
|
||||
// Copyright (c) 2023 Davide De Rosa. All rights reserved.
|
||||
//
|
||||
// https://github.com/passepartoutvpn
|
||||
//
|
||||
// This file is part of Passepartout.
|
||||
//
|
||||
// Passepartout is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Passepartout is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import PassepartoutCore
|
||||
|
||||
extension VPNProtocolType: RawRepresentable {
|
||||
private static let openVPNString = "ovpn"
|
||||
|
||||
private static let wireGuardString = "wg"
|
||||
|
||||
public init?(rawValue: String) {
|
||||
switch rawValue {
|
||||
case Self.openVPNString:
|
||||
self = .openVPN
|
||||
|
||||
case Self.wireGuardString:
|
||||
self = .wireGuard
|
||||
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var rawValue: String {
|
||||
switch self {
|
||||
case .openVPN:
|
||||
return Self.openVPNString
|
||||
|
||||
case .wireGuard:
|
||||
return Self.wireGuardString
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue