Review some Core/OpenVPN entities

- Drop redundant Equatable (automatic in structs)
- Make IPv4/6 routes Hashable
- Expose StaticKey as hex String
- Mask PAC URL
This commit is contained in:
Davide De Rosa 2022-03-07 23:50:38 +01:00
parent 3741a17c20
commit 3807b4754b
8 changed files with 23 additions and 33 deletions

View File

@ -35,10 +35,4 @@ public struct DataCount: Equatable {
self.received = received self.received = received
self.sent = sent self.sent = sent
} }
// MARK: Equatable
public static func ==(lhs: DataCount, rhs: DataCount) -> Bool {
return lhs.up == rhs.up && lhs.down == rhs.down
}
} }

View File

@ -37,12 +37,6 @@ public struct Endpoint: Codable, Equatable, CustomStringConvertible {
self.proto = proto self.proto = proto
} }
// MARK: Equatable
public static func ==(lhs: Endpoint, rhs: Endpoint) -> Bool {
return lhs.address == rhs.address && lhs.proto == rhs.proto
}
// MARK: CustomStringConvertible // MARK: CustomStringConvertible
public var description: String { public var description: String {
@ -85,12 +79,6 @@ public struct EndpointProtocol: RawRepresentable, Equatable, CustomStringConvert
return "\(socketType.rawValue):\(port)" return "\(socketType.rawValue):\(port)"
} }
// MARK: Equatable
public static func ==(lhs: EndpointProtocol, rhs: EndpointProtocol) -> Bool {
return (lhs.socketType == rhs.socketType) && (lhs.port == rhs.port)
}
// MARK: CustomStringConvertible // MARK: CustomStringConvertible
public var description: String { public var description: String {

View File

@ -29,7 +29,7 @@ import Foundation
public struct IPv4Settings: Codable, CustomStringConvertible { public struct IPv4Settings: Codable, CustomStringConvertible {
/// Represents an IPv4 route in the routing table. /// Represents an IPv4 route in the routing table.
public struct Route: Codable, CustomStringConvertible { public struct Route: Codable, Hashable, CustomStringConvertible {
/// The destination host or subnet. /// The destination host or subnet.
public let destination: String public let destination: String
@ -46,6 +46,14 @@ public struct IPv4Settings: Codable, CustomStringConvertible {
self.gateway = gateway self.gateway = gateway
} }
// MARK: Hashable
public func hash(into hasher: inout Hasher) {
hasher.combine(destination)
hasher.combine(mask)
hasher.combine(gateway)
}
// MARK: CustomStringConvertible // MARK: CustomStringConvertible
public var description: String { public var description: String {

View File

@ -29,7 +29,7 @@ import Foundation
public struct IPv6Settings: Codable, CustomStringConvertible { public struct IPv6Settings: Codable, CustomStringConvertible {
/// Represents an IPv6 route in the routing table. /// Represents an IPv6 route in the routing table.
public struct Route: Codable, CustomStringConvertible { public struct Route: Codable, Hashable, CustomStringConvertible {
/// The destination host or subnet. /// The destination host or subnet.
public let destination: String public let destination: String
@ -46,6 +46,14 @@ public struct IPv6Settings: Codable, CustomStringConvertible {
self.gateway = gateway self.gateway = gateway
} }
// MARK: Hashable
public func hash(into hasher: inout Hasher) {
hasher.combine(destination)
hasher.combine(prefixLength)
hasher.combine(gateway)
}
// MARK: CustomStringConvertible // MARK: CustomStringConvertible
public var description: String { public var description: String {

View File

@ -751,7 +751,7 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
} }
proxySettings?.proxyAutoConfigurationURL = pacURL proxySettings?.proxyAutoConfigurationURL = pacURL
proxySettings?.autoProxyConfigurationEnabled = true proxySettings?.autoProxyConfigurationEnabled = true
log.info("Routing: Setting PAC \(pacURL)") log.info("Routing: Setting PAC \(pacURL.maskedDescription)")
} }
// only set if there is a proxy (proxySettings set to non-nil above) // only set if there is a proxy (proxySettings set to non-nil above)

View File

@ -56,12 +56,6 @@ extension OpenVPN {
self.username = username self.username = username
self.password = password self.password = password
} }
// MARK: Equatable
public static func ==(lhs: Credentials, rhs: Credentials) -> Bool {
return (lhs.username == rhs.username) && (lhs.password == rhs.password)
}
} }
/// Encryption algorithm. /// Encryption algorithm.

View File

@ -72,12 +72,6 @@ extension OpenVPN {
return CryptoContainer(pem: decryptedPEM) return CryptoContainer(pem: decryptedPEM)
} }
// MARK: Equatable
public static func ==(lhs: CryptoContainer, rhs: CryptoContainer) -> Bool {
return lhs.pem == rhs.pem
}
// MARK: Codable // MARK: Codable
public init(from decoder: Decoder) throws { public init(from decoder: Decoder) throws {

View File

@ -227,5 +227,9 @@ extension OpenVPN {
try container.encode(secureData.toData(), forKey: .data) try container.encode(secureData.toData(), forKey: .data)
try container.encodeIfPresent(direction, forKey: .dir) try container.encodeIfPresent(direction, forKey: .dir)
} }
public var hexString: String {
return secureData.toHex()
}
} }
} }