WireGuardKit: Set public access level for shared structs
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
This commit is contained in:
parent
a03df7d8cc
commit
4cb21b5eb0
|
@ -4,26 +4,26 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
|
|
||||||
struct DNSServer {
|
public struct DNSServer {
|
||||||
let address: IPAddress
|
public let address: IPAddress
|
||||||
|
|
||||||
init(address: IPAddress) {
|
public init(address: IPAddress) {
|
||||||
self.address = address
|
self.address = address
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DNSServer: Equatable {
|
extension DNSServer: Equatable {
|
||||||
static func == (lhs: DNSServer, rhs: DNSServer) -> Bool {
|
public static func == (lhs: DNSServer, rhs: DNSServer) -> Bool {
|
||||||
return lhs.address.rawValue == rhs.address.rawValue
|
return lhs.address.rawValue == rhs.address.rawValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DNSServer {
|
extension DNSServer {
|
||||||
var stringRepresentation: String {
|
public var stringRepresentation: String {
|
||||||
return "\(address)"
|
return "\(address)"
|
||||||
}
|
}
|
||||||
|
|
||||||
init?(from addressString: String) {
|
public init?(from addressString: String) {
|
||||||
if let addr = IPv4Address(addressString) {
|
if let addr = IPv4Address(addressString) {
|
||||||
address = addr
|
address = addr
|
||||||
} else if let addr = IPv6Address(addressString) {
|
} else if let addr = IPv6Address(addressString) {
|
||||||
|
|
|
@ -4,31 +4,31 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
|
|
||||||
struct Endpoint {
|
public struct Endpoint {
|
||||||
let host: NWEndpoint.Host
|
public let host: NWEndpoint.Host
|
||||||
let port: NWEndpoint.Port
|
public let port: NWEndpoint.Port
|
||||||
|
|
||||||
init(host: NWEndpoint.Host, port: NWEndpoint.Port) {
|
public init(host: NWEndpoint.Host, port: NWEndpoint.Port) {
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Endpoint: Equatable {
|
extension Endpoint: Equatable {
|
||||||
static func == (lhs: Endpoint, rhs: Endpoint) -> Bool {
|
public static func == (lhs: Endpoint, rhs: Endpoint) -> Bool {
|
||||||
return lhs.host == rhs.host && lhs.port == rhs.port
|
return lhs.host == rhs.host && lhs.port == rhs.port
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Endpoint: Hashable {
|
extension Endpoint: Hashable {
|
||||||
func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(host)
|
hasher.combine(host)
|
||||||
hasher.combine(port)
|
hasher.combine(port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Endpoint {
|
extension Endpoint {
|
||||||
var stringRepresentation: String {
|
public var stringRepresentation: String {
|
||||||
switch host {
|
switch host {
|
||||||
case .name(let hostname, _):
|
case .name(let hostname, _):
|
||||||
return "\(hostname):\(port)"
|
return "\(hostname):\(port)"
|
||||||
|
@ -41,7 +41,7 @@ extension Endpoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init?(from string: String) {
|
public init?(from string: String) {
|
||||||
// Separation of host and port is based on 'parse_endpoint' function in
|
// Separation of host and port is based on 'parse_endpoint' function in
|
||||||
// https://git.zx2c4.com/wireguard-tools/tree/src/config.c
|
// https://git.zx2c4.com/wireguard-tools/tree/src/config.c
|
||||||
guard !string.isEmpty else { return nil }
|
guard !string.isEmpty else { return nil }
|
||||||
|
@ -72,7 +72,7 @@ extension Endpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Endpoint {
|
extension Endpoint {
|
||||||
func hasHostAsIPAddress() -> Bool {
|
public func hasHostAsIPAddress() -> Bool {
|
||||||
switch host {
|
switch host {
|
||||||
case .name:
|
case .name:
|
||||||
return false
|
return false
|
||||||
|
@ -85,7 +85,7 @@ extension Endpoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hostname() -> String? {
|
public func hostname() -> String? {
|
||||||
switch host {
|
switch host {
|
||||||
case .name(let hostname, _):
|
case .name(let hostname, _):
|
||||||
return hostname
|
return hostname
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
|
|
||||||
struct IPAddressRange {
|
public struct IPAddressRange {
|
||||||
let address: IPAddress
|
public let address: IPAddress
|
||||||
var networkPrefixLength: UInt8
|
public let networkPrefixLength: UInt8
|
||||||
|
|
||||||
init(address: IPAddress, networkPrefixLength: UInt8) {
|
init(address: IPAddress, networkPrefixLength: UInt8) {
|
||||||
self.address = address
|
self.address = address
|
||||||
|
@ -15,24 +15,24 @@ struct IPAddressRange {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension IPAddressRange: Equatable {
|
extension IPAddressRange: Equatable {
|
||||||
static func == (lhs: IPAddressRange, rhs: IPAddressRange) -> Bool {
|
public static func == (lhs: IPAddressRange, rhs: IPAddressRange) -> Bool {
|
||||||
return lhs.address.rawValue == rhs.address.rawValue && lhs.networkPrefixLength == rhs.networkPrefixLength
|
return lhs.address.rawValue == rhs.address.rawValue && lhs.networkPrefixLength == rhs.networkPrefixLength
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension IPAddressRange: Hashable {
|
extension IPAddressRange: Hashable {
|
||||||
func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(address.rawValue)
|
hasher.combine(address.rawValue)
|
||||||
hasher.combine(networkPrefixLength)
|
hasher.combine(networkPrefixLength)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension IPAddressRange {
|
extension IPAddressRange {
|
||||||
var stringRepresentation: String {
|
public var stringRepresentation: String {
|
||||||
return "\(address)/\(networkPrefixLength)"
|
return "\(address)/\(networkPrefixLength)"
|
||||||
}
|
}
|
||||||
|
|
||||||
init?(from string: String) {
|
public init?(from string: String) {
|
||||||
guard let parsed = IPAddressRange.parseAddressString(string) else { return nil }
|
guard let parsed = IPAddressRange.parseAddressString(string) else { return nil }
|
||||||
address = parsed.0
|
address = parsed.0
|
||||||
networkPrefixLength = parsed.1
|
networkPrefixLength = parsed.1
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import Network
|
import Network
|
||||||
|
|
||||||
struct InterfaceConfiguration {
|
public struct InterfaceConfiguration {
|
||||||
var privateKey: Data
|
public var privateKey: Data
|
||||||
var addresses = [IPAddressRange]()
|
public var addresses = [IPAddressRange]()
|
||||||
var listenPort: UInt16?
|
public var listenPort: UInt16?
|
||||||
var mtu: UInt16?
|
public var mtu: UInt16?
|
||||||
var dns = [DNSServer]()
|
public var dns = [DNSServer]()
|
||||||
|
|
||||||
init(privateKey: Data) {
|
public init(privateKey: Data) {
|
||||||
if privateKey.count != TunnelConfiguration.keyLength {
|
if privateKey.count != TunnelConfiguration.keyLength {
|
||||||
fatalError("Invalid private key")
|
fatalError("Invalid private key")
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ struct InterfaceConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension InterfaceConfiguration: Equatable {
|
extension InterfaceConfiguration: Equatable {
|
||||||
static func == (lhs: InterfaceConfiguration, rhs: InterfaceConfiguration) -> Bool {
|
public static func == (lhs: InterfaceConfiguration, rhs: InterfaceConfiguration) -> Bool {
|
||||||
let lhsAddresses = lhs.addresses.filter { $0.address is IPv4Address } + lhs.addresses.filter { $0.address is IPv6Address }
|
let lhsAddresses = lhs.addresses.filter { $0.address is IPv4Address } + lhs.addresses.filter { $0.address is IPv6Address }
|
||||||
let rhsAddresses = rhs.addresses.filter { $0.address is IPv4Address } + rhs.addresses.filter { $0.address is IPv6Address }
|
let rhsAddresses = rhs.addresses.filter { $0.address is IPv4Address } + rhs.addresses.filter { $0.address is IPv6Address }
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct PeerConfiguration {
|
public struct PeerConfiguration {
|
||||||
var publicKey: Data
|
public var publicKey: Data
|
||||||
var preSharedKey: Data? {
|
public var preSharedKey: Data? {
|
||||||
didSet(value) {
|
didSet(value) {
|
||||||
if let value = value {
|
if let value = value {
|
||||||
if value.count != TunnelConfiguration.keyLength {
|
if value.count != TunnelConfiguration.keyLength {
|
||||||
|
@ -14,14 +14,14 @@ struct PeerConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var allowedIPs = [IPAddressRange]()
|
public var allowedIPs = [IPAddressRange]()
|
||||||
var endpoint: Endpoint?
|
public var endpoint: Endpoint?
|
||||||
var persistentKeepAlive: UInt16?
|
public var persistentKeepAlive: UInt16?
|
||||||
var rxBytes: UInt64?
|
public var rxBytes: UInt64?
|
||||||
var txBytes: UInt64?
|
public var txBytes: UInt64?
|
||||||
var lastHandshakeTime: Date?
|
public var lastHandshakeTime: Date?
|
||||||
|
|
||||||
init(publicKey: Data) {
|
public init(publicKey: Data) {
|
||||||
self.publicKey = publicKey
|
self.publicKey = publicKey
|
||||||
if publicKey.count != TunnelConfiguration.keyLength {
|
if publicKey.count != TunnelConfiguration.keyLength {
|
||||||
fatalError("Invalid public key")
|
fatalError("Invalid public key")
|
||||||
|
@ -30,7 +30,7 @@ struct PeerConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension PeerConfiguration: Equatable {
|
extension PeerConfiguration: Equatable {
|
||||||
static func == (lhs: PeerConfiguration, rhs: PeerConfiguration) -> Bool {
|
public static func == (lhs: PeerConfiguration, rhs: PeerConfiguration) -> Bool {
|
||||||
return lhs.publicKey == rhs.publicKey &&
|
return lhs.publicKey == rhs.publicKey &&
|
||||||
lhs.preSharedKey == rhs.preSharedKey &&
|
lhs.preSharedKey == rhs.preSharedKey &&
|
||||||
Set(lhs.allowedIPs) == Set(rhs.allowedIPs) &&
|
Set(lhs.allowedIPs) == Set(rhs.allowedIPs) &&
|
||||||
|
@ -40,7 +40,7 @@ extension PeerConfiguration: Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension PeerConfiguration: Hashable {
|
extension PeerConfiguration: Hashable {
|
||||||
func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(publicKey)
|
hasher.combine(publicKey)
|
||||||
hasher.combine(preSharedKey)
|
hasher.combine(preSharedKey)
|
||||||
hasher.combine(Set(allowedIPs))
|
hasher.combine(Set(allowedIPs))
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
final class TunnelConfiguration {
|
public final class TunnelConfiguration {
|
||||||
var name: String?
|
public var name: String?
|
||||||
var interface: InterfaceConfiguration
|
public var interface: InterfaceConfiguration
|
||||||
let peers: [PeerConfiguration]
|
public let peers: [PeerConfiguration]
|
||||||
|
|
||||||
static let keyLength = 32
|
public static let keyLength = 32
|
||||||
|
|
||||||
init(name: String?, interface: InterfaceConfiguration, peers: [PeerConfiguration]) {
|
public init(name: String?, interface: InterfaceConfiguration, peers: [PeerConfiguration]) {
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
self.peers = peers
|
self.peers = peers
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -24,7 +24,7 @@ final class TunnelConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TunnelConfiguration: Equatable {
|
extension TunnelConfiguration: Equatable {
|
||||||
static func == (lhs: TunnelConfiguration, rhs: TunnelConfiguration) -> Bool {
|
public static func == (lhs: TunnelConfiguration, rhs: TunnelConfiguration) -> Bool {
|
||||||
return lhs.name == rhs.name &&
|
return lhs.name == rhs.name &&
|
||||||
lhs.interface == rhs.interface &&
|
lhs.interface == rhs.interface &&
|
||||||
Set(lhs.peers) == Set(rhs.peers)
|
Set(lhs.peers) == Set(rhs.peers)
|
||||||
|
|
Loading…
Reference in New Issue