aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-11-05 12:23:06 +0100
committerAndrej Mihajlov <and@mullvad.net>2020-12-02 11:08:08 +0100
commit4cb21b5eb029f26c53b76950ac4cc6acec63d181 (patch)
tree5e86dd29a1e9830d40a51d795af89e8edfb34e4f
parentWireGuardKit: Move shared structs to WireGuardKit (diff)
downloadwireguard-apple-4cb21b5eb029f26c53b76950ac4cc6acec63d181.tar.xz
wireguard-apple-4cb21b5eb029f26c53b76950ac4cc6acec63d181.zip
WireGuardKit: Set public access level for shared structs
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
-rw-r--r--WireGuardKit/Sources/WireGuardKit/DNSServer.swift12
-rw-r--r--WireGuardKit/Sources/WireGuardKit/Endpoint.swift20
-rw-r--r--WireGuardKit/Sources/WireGuardKit/IPAddressRange.swift14
-rw-r--r--WireGuardKit/Sources/WireGuardKit/InterfaceConfiguration.swift16
-rw-r--r--WireGuardKit/Sources/WireGuardKit/PeerConfiguration.swift24
-rw-r--r--WireGuardKit/Sources/WireGuardKit/TunnelConfiguration.swift14
6 files changed, 50 insertions, 50 deletions
diff --git a/WireGuardKit/Sources/WireGuardKit/DNSServer.swift b/WireGuardKit/Sources/WireGuardKit/DNSServer.swift
index 0d03577..b1a2401 100644
--- a/WireGuardKit/Sources/WireGuardKit/DNSServer.swift
+++ b/WireGuardKit/Sources/WireGuardKit/DNSServer.swift
@@ -4,26 +4,26 @@
import Foundation
import Network
-struct DNSServer {
- let address: IPAddress
+public struct DNSServer {
+ public let address: IPAddress
- init(address: IPAddress) {
+ public init(address: IPAddress) {
self.address = address
}
}
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
}
}
extension DNSServer {
- var stringRepresentation: String {
+ public var stringRepresentation: String {
return "\(address)"
}
- init?(from addressString: String) {
+ public init?(from addressString: String) {
if let addr = IPv4Address(addressString) {
address = addr
} else if let addr = IPv6Address(addressString) {
diff --git a/WireGuardKit/Sources/WireGuardKit/Endpoint.swift b/WireGuardKit/Sources/WireGuardKit/Endpoint.swift
index dad5961..07529e3 100644
--- a/WireGuardKit/Sources/WireGuardKit/Endpoint.swift
+++ b/WireGuardKit/Sources/WireGuardKit/Endpoint.swift
@@ -4,31 +4,31 @@
import Foundation
import Network
-struct Endpoint {
- let host: NWEndpoint.Host
- let port: NWEndpoint.Port
+public struct Endpoint {
+ public let host: NWEndpoint.Host
+ public let port: NWEndpoint.Port
- init(host: NWEndpoint.Host, port: NWEndpoint.Port) {
+ public init(host: NWEndpoint.Host, port: NWEndpoint.Port) {
self.host = host
self.port = port
}
}
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
}
}
extension Endpoint: Hashable {
- func hash(into hasher: inout Hasher) {
+ public func hash(into hasher: inout Hasher) {
hasher.combine(host)
hasher.combine(port)
}
}
extension Endpoint {
- var stringRepresentation: String {
+ public var stringRepresentation: String {
switch host {
case .name(let hostname, _):
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
// https://git.zx2c4.com/wireguard-tools/tree/src/config.c
guard !string.isEmpty else { return nil }
@@ -72,7 +72,7 @@ extension Endpoint {
}
extension Endpoint {
- func hasHostAsIPAddress() -> Bool {
+ public func hasHostAsIPAddress() -> Bool {
switch host {
case .name:
return false
@@ -85,7 +85,7 @@ extension Endpoint {
}
}
- func hostname() -> String? {
+ public func hostname() -> String? {
switch host {
case .name(let hostname, _):
return hostname
diff --git a/WireGuardKit/Sources/WireGuardKit/IPAddressRange.swift b/WireGuardKit/Sources/WireGuardKit/IPAddressRange.swift
index d38686c..c65ff1d 100644
--- a/WireGuardKit/Sources/WireGuardKit/IPAddressRange.swift
+++ b/WireGuardKit/Sources/WireGuardKit/IPAddressRange.swift
@@ -4,9 +4,9 @@
import Foundation
import Network
-struct IPAddressRange {
- let address: IPAddress
- var networkPrefixLength: UInt8
+public struct IPAddressRange {
+ public let address: IPAddress
+ public let networkPrefixLength: UInt8
init(address: IPAddress, networkPrefixLength: UInt8) {
self.address = address
@@ -15,24 +15,24 @@ struct IPAddressRange {
}
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
}
}
extension IPAddressRange: Hashable {
- func hash(into hasher: inout Hasher) {
+ public func hash(into hasher: inout Hasher) {
hasher.combine(address.rawValue)
hasher.combine(networkPrefixLength)
}
}
extension IPAddressRange {
- var stringRepresentation: String {
+ public var stringRepresentation: String {
return "\(address)/\(networkPrefixLength)"
}
- init?(from string: String) {
+ public init?(from string: String) {
guard let parsed = IPAddressRange.parseAddressString(string) else { return nil }
address = parsed.0
networkPrefixLength = parsed.1
diff --git a/WireGuardKit/Sources/WireGuardKit/InterfaceConfiguration.swift b/WireGuardKit/Sources/WireGuardKit/InterfaceConfiguration.swift
index d80ed89..16a9046 100644
--- a/WireGuardKit/Sources/WireGuardKit/InterfaceConfiguration.swift
+++ b/WireGuardKit/Sources/WireGuardKit/InterfaceConfiguration.swift
@@ -4,14 +4,14 @@
import Foundation
import Network
-struct InterfaceConfiguration {
- var privateKey: Data
- var addresses = [IPAddressRange]()
- var listenPort: UInt16?
- var mtu: UInt16?
- var dns = [DNSServer]()
+public struct InterfaceConfiguration {
+ public var privateKey: Data
+ public var addresses = [IPAddressRange]()
+ public var listenPort: UInt16?
+ public var mtu: UInt16?
+ public var dns = [DNSServer]()
- init(privateKey: Data) {
+ public init(privateKey: Data) {
if privateKey.count != TunnelConfiguration.keyLength {
fatalError("Invalid private key")
}
@@ -20,7 +20,7 @@ struct InterfaceConfiguration {
}
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 rhsAddresses = rhs.addresses.filter { $0.address is IPv4Address } + rhs.addresses.filter { $0.address is IPv6Address }
diff --git a/WireGuardKit/Sources/WireGuardKit/PeerConfiguration.swift b/WireGuardKit/Sources/WireGuardKit/PeerConfiguration.swift
index 7fd3f87..4d92dc6 100644
--- a/WireGuardKit/Sources/WireGuardKit/PeerConfiguration.swift
+++ b/WireGuardKit/Sources/WireGuardKit/PeerConfiguration.swift
@@ -3,9 +3,9 @@
import Foundation
-struct PeerConfiguration {
- var publicKey: Data
- var preSharedKey: Data? {
+public struct PeerConfiguration {
+ public var publicKey: Data
+ public var preSharedKey: Data? {
didSet(value) {
if let value = value {
if value.count != TunnelConfiguration.keyLength {
@@ -14,14 +14,14 @@ struct PeerConfiguration {
}
}
}
- var allowedIPs = [IPAddressRange]()
- var endpoint: Endpoint?
- var persistentKeepAlive: UInt16?
- var rxBytes: UInt64?
- var txBytes: UInt64?
- var lastHandshakeTime: Date?
+ public var allowedIPs = [IPAddressRange]()
+ public var endpoint: Endpoint?
+ public var persistentKeepAlive: UInt16?
+ public var rxBytes: UInt64?
+ public var txBytes: UInt64?
+ public var lastHandshakeTime: Date?
- init(publicKey: Data) {
+ public init(publicKey: Data) {
self.publicKey = publicKey
if publicKey.count != TunnelConfiguration.keyLength {
fatalError("Invalid public key")
@@ -30,7 +30,7 @@ struct PeerConfiguration {
}
extension PeerConfiguration: Equatable {
- static func == (lhs: PeerConfiguration, rhs: PeerConfiguration) -> Bool {
+ public static func == (lhs: PeerConfiguration, rhs: PeerConfiguration) -> Bool {
return lhs.publicKey == rhs.publicKey &&
lhs.preSharedKey == rhs.preSharedKey &&
Set(lhs.allowedIPs) == Set(rhs.allowedIPs) &&
@@ -40,7 +40,7 @@ extension PeerConfiguration: Equatable {
}
extension PeerConfiguration: Hashable {
- func hash(into hasher: inout Hasher) {
+ public func hash(into hasher: inout Hasher) {
hasher.combine(publicKey)
hasher.combine(preSharedKey)
hasher.combine(Set(allowedIPs))
diff --git a/WireGuardKit/Sources/WireGuardKit/TunnelConfiguration.swift b/WireGuardKit/Sources/WireGuardKit/TunnelConfiguration.swift
index 5a8f7df..b1ca442 100644
--- a/WireGuardKit/Sources/WireGuardKit/TunnelConfiguration.swift
+++ b/WireGuardKit/Sources/WireGuardKit/TunnelConfiguration.swift
@@ -3,14 +3,14 @@
import Foundation
-final class TunnelConfiguration {
- var name: String?
- var interface: InterfaceConfiguration
- let peers: [PeerConfiguration]
+public final class TunnelConfiguration {
+ public var name: String?
+ public var interface: InterfaceConfiguration
+ 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.peers = peers
self.name = name
@@ -24,7 +24,7 @@ final class TunnelConfiguration {
}
extension TunnelConfiguration: Equatable {
- static func == (lhs: TunnelConfiguration, rhs: TunnelConfiguration) -> Bool {
+ public static func == (lhs: TunnelConfiguration, rhs: TunnelConfiguration) -> Bool {
return lhs.name == rhs.name &&
lhs.interface == rhs.interface &&
Set(lhs.peers) == Set(rhs.peers)