Use "struct" in data models to leverage Equatable

This way Configuration objects can be compared for changes.
This commit is contained in:
Davide De Rosa 2022-03-22 07:14:57 +01:00
parent f4508911aa
commit f1bdc8490c
9 changed files with 15 additions and 15 deletions

View File

@ -26,7 +26,7 @@
import Foundation
/// A generic structure holding a pair of inbound/outbound states.
public class BidirectionalState<T> {
public struct BidirectionalState<T> {
private let resetValue: T
/// The inbound state.
@ -58,7 +58,7 @@ public class BidirectionalState<T> {
/**
Resets state to the value provided with `init(withResetValue:)`.
*/
public func reset() {
public mutating func reset() {
inbound = resetValue
outbound = resetValue
}

View File

@ -26,7 +26,7 @@
import Foundation
/// 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.
public struct Route: Codable, Hashable, CustomStringConvertible {

View File

@ -26,7 +26,7 @@
import Foundation
/// 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.
public struct Route: Codable, Hashable, CustomStringConvertible {

View File

@ -26,7 +26,7 @@
import Foundation
/// Encapsulates a proxy setting.
public struct Proxy: Codable, RawRepresentable, CustomStringConvertible {
public struct Proxy: Codable, Equatable, RawRepresentable, CustomStringConvertible {
/// The proxy address.
public let address: String

View File

@ -356,7 +356,7 @@ extension OpenVPN {
}
/// The immutable configuration for `OpenVPNSession`.
public struct Configuration: Codable {
public struct Configuration: Codable, Equatable {
/// - Seealso: `ConfigurationBuilder.cipher`
public let cipher: Cipher?

View File

@ -30,7 +30,7 @@ import CTunnelKitCore
extension OpenVPN {
/// Represents an OpenVPN static key file (as generated with --genkey)
public class StaticKey: Codable {
public struct StaticKey: Codable, Equatable {
enum CodingKeys: CodingKey {
case data
@ -147,12 +147,12 @@ extension OpenVPN {
- Parameter file: The text file containing the key.
- 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")
self.init(lines: lines, direction: direction)
}
public convenience init?(lines: [Substring], direction: Direction?) {
public init?(lines: [Substring], direction: Direction?) {
var isHead = true
var hexLines: [Substring] = []
@ -196,7 +196,7 @@ extension OpenVPN {
- Parameter biData: The key data.
*/
public convenience init(biData data: Data) {
public init(biData data: Data) {
self.init(data: data, direction: nil)
}
@ -216,7 +216,7 @@ extension OpenVPN {
// MARK: Codable
public required init(from decoder: Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
secureData = Z(try container.decode(Data.self, forKey: .data))
direction = try container.decodeIfPresent(Direction.self, forKey: .dir)

View File

@ -28,10 +28,10 @@ import Foundation
extension OpenVPN {
/// Holds parameters for TLS wrapping.
public class TLSWrap: Codable {
public struct TLSWrap: Codable, Equatable {
/// The wrapping strategy.
public enum Strategy: String, Codable {
public enum Strategy: String, Codable, Equatable {
/// Authenticates payload (--tls-auth).
case auth

View File

@ -63,7 +63,7 @@ extension ControlPacket {
}
extension OpenVPN {
class DataPacket {
struct DataPacket {
static let pingString = Data(hex: "2a187bf3641eb4cb07ed2d0a981fc748")
}

View File

@ -203,7 +203,7 @@ extension WireGuard {
}
}
public struct Configuration: Codable, WireGuardConfigurationProviding {
public struct Configuration: Codable, Equatable, WireGuardConfigurationProviding {
public let tunnelConfiguration: TunnelConfiguration
public var interface: InterfaceConfiguration {