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:
Davide De Rosa 2023-07-02 13:27:46 +02:00 committed by GitHub
parent 278efaf347
commit ddf3dc313f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 9 deletions

View File

@ -7,13 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Changed
- Internal error handling. [#310](https://github.com/passepartoutvpn/passepartout-apple/pull/310)
### Fixed ### Fixed
- Allow wildcards in proxy bypass domains. [#296](https://github.com/passepartoutvpn/passepartout-apple/issues/296) - 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) ## 2.1.1 (2023-04-19)

View File

@ -25,11 +25,10 @@
import Foundation import Foundation
// FIXME: arch, provide a well-defined serialization property rather than .rawValue public enum VPNProtocolType: CaseIterable, Codable {
public enum VPNProtocolType: String, CaseIterable, Codable { case openVPN
case openVPN = "ovpn"
case wireGuard = "wg" case wireGuard
} }
public protocol VPNProtocolProviding { public protocol VPNProtocolProviding {

View File

@ -57,7 +57,7 @@ extension ProviderServer: Identifiable {
} }
public static func id(withName providerName: ProviderName, vpnProtocol: VPNProtocolType, apiId: String) -> String? { 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 { guard let data = idSource.data(using: .utf8) else {
return nil return nil
} }

View File

@ -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
}
}
}