Use "struct" in data models to leverage Equatable
This way Configuration objects can be compared for changes.
This commit is contained in:
parent
f4508911aa
commit
f1bdc8490c
|
@ -26,7 +26,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/// A generic structure holding a pair of inbound/outbound states.
|
/// A generic structure holding a pair of inbound/outbound states.
|
||||||
public class BidirectionalState<T> {
|
public struct BidirectionalState<T> {
|
||||||
private let resetValue: T
|
private let resetValue: T
|
||||||
|
|
||||||
/// The inbound state.
|
/// The inbound state.
|
||||||
|
@ -58,7 +58,7 @@ public class BidirectionalState<T> {
|
||||||
/**
|
/**
|
||||||
Resets state to the value provided with `init(withResetValue:)`.
|
Resets state to the value provided with `init(withResetValue:)`.
|
||||||
*/
|
*/
|
||||||
public func reset() {
|
public mutating func reset() {
|
||||||
inbound = resetValue
|
inbound = resetValue
|
||||||
outbound = resetValue
|
outbound = resetValue
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/// Encapsulates the IPv4 settings for the tunnel.
|
/// Encapsulates the IPv4 settings for the tunnel.
|
||||||
public struct IPv4Settings: Codable, CustomStringConvertible {
|
public struct IPv4Settings: Codable, Equatable, CustomStringConvertible {
|
||||||
|
|
||||||
/// Represents an IPv4 route in the routing table.
|
/// Represents an IPv4 route in the routing table.
|
||||||
public struct Route: Codable, Hashable, CustomStringConvertible {
|
public struct Route: Codable, Hashable, CustomStringConvertible {
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/// Encapsulates the IPv6 settings for the tunnel.
|
/// Encapsulates the IPv6 settings for the tunnel.
|
||||||
public struct IPv6Settings: Codable, CustomStringConvertible {
|
public struct IPv6Settings: Codable, Equatable, CustomStringConvertible {
|
||||||
|
|
||||||
/// Represents an IPv6 route in the routing table.
|
/// Represents an IPv6 route in the routing table.
|
||||||
public struct Route: Codable, Hashable, CustomStringConvertible {
|
public struct Route: Codable, Hashable, CustomStringConvertible {
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/// Encapsulates a proxy setting.
|
/// Encapsulates a proxy setting.
|
||||||
public struct Proxy: Codable, RawRepresentable, CustomStringConvertible {
|
public struct Proxy: Codable, Equatable, RawRepresentable, CustomStringConvertible {
|
||||||
|
|
||||||
/// The proxy address.
|
/// The proxy address.
|
||||||
public let address: String
|
public let address: String
|
||||||
|
|
|
@ -356,7 +356,7 @@ extension OpenVPN {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The immutable configuration for `OpenVPNSession`.
|
/// The immutable configuration for `OpenVPNSession`.
|
||||||
public struct Configuration: Codable {
|
public struct Configuration: Codable, Equatable {
|
||||||
|
|
||||||
/// - Seealso: `ConfigurationBuilder.cipher`
|
/// - Seealso: `ConfigurationBuilder.cipher`
|
||||||
public let cipher: Cipher?
|
public let cipher: Cipher?
|
||||||
|
|
|
@ -30,7 +30,7 @@ import CTunnelKitCore
|
||||||
extension OpenVPN {
|
extension OpenVPN {
|
||||||
|
|
||||||
/// Represents an OpenVPN static key file (as generated with --genkey)
|
/// Represents an OpenVPN static key file (as generated with --genkey)
|
||||||
public class StaticKey: Codable {
|
public struct StaticKey: Codable, Equatable {
|
||||||
enum CodingKeys: CodingKey {
|
enum CodingKeys: CodingKey {
|
||||||
case data
|
case data
|
||||||
|
|
||||||
|
@ -147,12 +147,12 @@ extension OpenVPN {
|
||||||
- Parameter file: The text file containing the key.
|
- Parameter file: The text file containing the key.
|
||||||
- Parameter direction: The key direction, or bidirectional if nil.
|
- Parameter direction: The key direction, or bidirectional if nil.
|
||||||
*/
|
*/
|
||||||
public convenience init?(file: String, direction: Direction?) {
|
public init?(file: String, direction: Direction?) {
|
||||||
let lines = file.split(separator: "\n")
|
let lines = file.split(separator: "\n")
|
||||||
self.init(lines: lines, direction: direction)
|
self.init(lines: lines, direction: direction)
|
||||||
}
|
}
|
||||||
|
|
||||||
public convenience init?(lines: [Substring], direction: Direction?) {
|
public init?(lines: [Substring], direction: Direction?) {
|
||||||
var isHead = true
|
var isHead = true
|
||||||
var hexLines: [Substring] = []
|
var hexLines: [Substring] = []
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ extension OpenVPN {
|
||||||
|
|
||||||
- Parameter biData: The key data.
|
- Parameter biData: The key data.
|
||||||
*/
|
*/
|
||||||
public convenience init(biData data: Data) {
|
public init(biData data: Data) {
|
||||||
self.init(data: data, direction: nil)
|
self.init(data: data, direction: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ extension OpenVPN {
|
||||||
|
|
||||||
// MARK: Codable
|
// MARK: Codable
|
||||||
|
|
||||||
public required init(from decoder: Decoder) throws {
|
public init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
secureData = Z(try container.decode(Data.self, forKey: .data))
|
secureData = Z(try container.decode(Data.self, forKey: .data))
|
||||||
direction = try container.decodeIfPresent(Direction.self, forKey: .dir)
|
direction = try container.decodeIfPresent(Direction.self, forKey: .dir)
|
||||||
|
|
|
@ -28,10 +28,10 @@ import Foundation
|
||||||
extension OpenVPN {
|
extension OpenVPN {
|
||||||
|
|
||||||
/// Holds parameters for TLS wrapping.
|
/// Holds parameters for TLS wrapping.
|
||||||
public class TLSWrap: Codable {
|
public struct TLSWrap: Codable, Equatable {
|
||||||
|
|
||||||
/// The wrapping strategy.
|
/// The wrapping strategy.
|
||||||
public enum Strategy: String, Codable {
|
public enum Strategy: String, Codable, Equatable {
|
||||||
|
|
||||||
/// Authenticates payload (--tls-auth).
|
/// Authenticates payload (--tls-auth).
|
||||||
case auth
|
case auth
|
||||||
|
|
|
@ -63,7 +63,7 @@ extension ControlPacket {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension OpenVPN {
|
extension OpenVPN {
|
||||||
class DataPacket {
|
struct DataPacket {
|
||||||
static let pingString = Data(hex: "2a187bf3641eb4cb07ed2d0a981fc748")
|
static let pingString = Data(hex: "2a187bf3641eb4cb07ed2d0a981fc748")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ extension WireGuard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct Configuration: Codable, WireGuardConfigurationProviding {
|
public struct Configuration: Codable, Equatable, WireGuardConfigurationProviding {
|
||||||
public let tunnelConfiguration: TunnelConfiguration
|
public let tunnelConfiguration: TunnelConfiguration
|
||||||
|
|
||||||
public var interface: InterfaceConfiguration {
|
public var interface: InterfaceConfiguration {
|
||||||
|
|
Loading…
Reference in New Issue