aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared/Model
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-12 11:40:57 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-12 11:40:57 -0600
commitde14b76b4d99f74d52b6e404b2ab37394fa5b9dc (patch)
tree0d6e1efbf855bb4995b22e6c55ab8ab2f08e8f24 /WireGuard/Shared/Model
parentZip importing: importFromFile should take a completionHandler (diff)
downloadwireguard-apple-de14b76b4d99f74d52b6e404b2ab37394fa5b9dc.tar.xz
wireguard-apple-de14b76b4d99f74d52b6e404b2ab37394fa5b9dc.zip
Added swiftlint and fixed all errors (and a bunch, but not all, warnings)
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'WireGuard/Shared/Model')
-rw-r--r--WireGuard/Shared/Model/Configuration.swift18
-rw-r--r--WireGuard/Shared/Model/DNSServer.swift2
-rw-r--r--WireGuard/Shared/Model/Endpoint.swift14
-rw-r--r--WireGuard/Shared/Model/IPAddressRange.swift6
4 files changed, 24 insertions, 16 deletions
diff --git a/WireGuard/Shared/Model/Configuration.swift b/WireGuard/Shared/Model/Configuration.swift
index d2680cbe..09fdd6b8 100644
--- a/WireGuard/Shared/Model/Configuration.swift
+++ b/WireGuard/Shared/Model/Configuration.swift
@@ -16,7 +16,7 @@ final class TunnelConfiguration: Codable {
let peerPublicKeysArray = peers.map { $0.publicKey }
let peerPublicKeysSet = Set<Data>(peerPublicKeysArray)
- if (peerPublicKeysArray.count != peerPublicKeysSet.count) {
+ if peerPublicKeysArray.count != peerPublicKeysSet.count {
fatalError("Two or more peers cannot have the same public key")
}
}
@@ -34,8 +34,12 @@ struct InterfaceConfiguration: Codable {
init(name: String, privateKey: Data) {
self.name = name
self.privateKey = privateKey
- if (name.isEmpty) { fatalError("Empty name") }
- if (privateKey.count != TunnelConfiguration.keyLength) { fatalError("Invalid private key") }
+ if name.isEmpty {
+ fatalError("Empty name")
+ }
+ if privateKey.count != TunnelConfiguration.keyLength {
+ fatalError("Invalid private key")
+ }
}
}
@@ -45,7 +49,9 @@ struct PeerConfiguration: Codable {
var preSharedKey: Data? {
didSet(value) {
if let value = value {
- if (value.count != TunnelConfiguration.keyLength) { fatalError("Invalid preshared key") }
+ if value.count != TunnelConfiguration.keyLength {
+ fatalError("Invalid preshared key")
+ }
}
}
}
@@ -55,6 +61,8 @@ struct PeerConfiguration: Codable {
init(publicKey: Data) {
self.publicKey = publicKey
- if (publicKey.count != TunnelConfiguration.keyLength) { fatalError("Invalid public key") }
+ if publicKey.count != TunnelConfiguration.keyLength {
+ fatalError("Invalid public key")
+ }
}
}
diff --git a/WireGuard/Shared/Model/DNSServer.swift b/WireGuard/Shared/Model/DNSServer.swift
index 8be1dddd..bb20c025 100644
--- a/WireGuard/Shared/Model/DNSServer.swift
+++ b/WireGuard/Shared/Model/DNSServer.swift
@@ -40,7 +40,7 @@ extension DNSServer: Codable {
let container = try decoder.singleValueContainer()
var data = try container.decode(Data.self)
let ipAddressFromData: IPAddress? = {
- switch (data.count) {
+ switch data.count {
case 4: return IPv4Address(data)
case 16: return IPv6Address(data)
default: return nil
diff --git a/WireGuard/Shared/Model/Endpoint.swift b/WireGuard/Shared/Model/Endpoint.swift
index ab357ba2..38ffab9a 100644
--- a/WireGuard/Shared/Model/Endpoint.swift
+++ b/WireGuard/Shared/Model/Endpoint.swift
@@ -35,8 +35,8 @@ extension Endpoint {
hostString = String(string[string.startIndex ..< endOfHost])
}
guard let endpointPort = NWEndpoint.Port(String(string[startOfPort ..< string.endIndex])) else { return nil }
- let invalidCharacterIndex = hostString.unicodeScalars.firstIndex { (c) -> Bool in
- return !CharacterSet.urlHostAllowed.contains(c)
+ let invalidCharacterIndex = hostString.unicodeScalars.firstIndex { char in
+ return !CharacterSet.urlHostAllowed.contains(char)
}
guard (invalidCharacterIndex == nil) else { return nil }
host = NWEndpoint.Host(hostString)
@@ -79,11 +79,11 @@ extension Endpoint: Codable {
extension Endpoint {
func hasHostAsIPAddress() -> Bool {
switch (host) {
- case .name(_, _):
+ case .name:
return false
- case .ipv4(_):
+ case .ipv4:
return true
- case .ipv6(_):
+ case .ipv6:
return true
}
}
@@ -92,9 +92,9 @@ extension Endpoint {
switch (host) {
case .name(let hostname, _):
return hostname
- case .ipv4(_):
+ case .ipv4:
return nil
- case .ipv6(_):
+ case .ipv6:
return nil
}
}
diff --git a/WireGuard/Shared/Model/IPAddressRange.swift b/WireGuard/Shared/Model/IPAddressRange.swift
index 2fb4a16d..e3c14414 100644
--- a/WireGuard/Shared/Model/IPAddressRange.swift
+++ b/WireGuard/Shared/Model/IPAddressRange.swift
@@ -27,9 +27,9 @@ extension IPAddressRange {
}
let maxNetworkPrefixLength: UInt8 = (address is IPv4Address) ? 32 : 128
var networkPrefixLength: UInt8
- if (endOfIPAddress < string.endIndex) { // "/" was located
+ if endOfIPAddress < string.endIndex { // "/" was located
let indexOfNetworkPrefixLength = string.index(after: endOfIPAddress)
- guard (indexOfNetworkPrefixLength < string.endIndex) else { return nil }
+ guard indexOfNetworkPrefixLength < string.endIndex else { return nil }
let networkPrefixLengthSubstring = string[indexOfNetworkPrefixLength ..< string.endIndex]
guard let npl = UInt8(networkPrefixLengthSubstring) else { return nil }
networkPrefixLength = min(npl, maxNetworkPrefixLength)
@@ -69,7 +69,7 @@ extension IPAddressRange: Codable {
var data = try container.decode(Data.self)
networkPrefixLength = data.removeLast()
let ipAddressFromData: IPAddress? = {
- switch (data.count) {
+ switch data.count {
case 4: return IPv4Address(data)
case 16: return IPv6Address(data)
default: return nil