WireGuardKit: Set public access level for shared structs

Signed-off-by: Andrej Mihajlov <and@mullvad.net>
This commit is contained in:
Andrej Mihajlov 2020-11-05 12:23:06 +01:00
parent a03df7d8cc
commit 4cb21b5eb0
6 changed files with 50 additions and 50 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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 }

View File

@ -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))

View File

@ -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)