Linter: Fix all linter issues across the codebase
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
This commit is contained in:
parent
35f0ada8a9
commit
5a044e4129
|
@ -21,18 +21,18 @@ class Keychain {
|
||||||
|
|
||||||
static func makeReference(containing value: String, called name: String, previouslyReferencedBy oldRef: Data? = nil) -> Data? {
|
static func makeReference(containing value: String, called name: String, previouslyReferencedBy oldRef: Data? = nil) -> Data? {
|
||||||
var ret: OSStatus
|
var ret: OSStatus
|
||||||
guard var id = Bundle.main.bundleIdentifier else {
|
guard var bundleIdentifier = Bundle.main.bundleIdentifier else {
|
||||||
wg_log(.error, staticMessage: "Unable to determine bundle identifier")
|
wg_log(.error, staticMessage: "Unable to determine bundle identifier")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if id.hasSuffix(".network-extension") {
|
if bundleIdentifier.hasSuffix(".network-extension") {
|
||||||
id.removeLast(".network-extension".count)
|
bundleIdentifier.removeLast(".network-extension".count)
|
||||||
}
|
}
|
||||||
var items: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
|
var items: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
|
||||||
kSecAttrLabel as String: "WireGuard Tunnel: " + name,
|
kSecAttrLabel as String: "WireGuard Tunnel: " + name,
|
||||||
kSecAttrAccount as String: name + ": " + UUID().uuidString,
|
kSecAttrAccount as String: name + ": " + UUID().uuidString,
|
||||||
kSecAttrDescription as String: "wg-quick(8) config",
|
kSecAttrDescription as String: "wg-quick(8) config",
|
||||||
kSecAttrService as String: id,
|
kSecAttrService as String: bundleIdentifier,
|
||||||
kSecValueData as String: value.data(using: .utf8) as Any,
|
kSecValueData as String: value.data(using: .utf8) as Any,
|
||||||
kSecReturnPersistentRef as String: true]
|
kSecReturnPersistentRef as String: true]
|
||||||
|
|
||||||
|
|
|
@ -464,8 +464,8 @@ class TunnelsManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static func tunnelNameIsLessThan(_ a: String, _ b: String) -> Bool {
|
static func tunnelNameIsLessThan(_ lhs: String, _ rhs: String) -> Bool {
|
||||||
return a.compare(b, options: [.caseInsensitive, .diacriticInsensitive, .widthInsensitive, .numeric]) == .orderedAscending
|
return lhs.compare(rhs, options: [.caseInsensitive, .diacriticInsensitive, .widthInsensitive, .numeric]) == .orderedAscending
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,8 +701,8 @@ class CatalinaWorkaround {
|
||||||
}
|
}
|
||||||
|
|
||||||
func reinstateTunnelsDeletedOutsideApp() {
|
func reinstateTunnelsDeletedOutsideApp() {
|
||||||
let rd = reinstationDataForTunnelsDeletedOutsideApp()
|
let data = reinstationDataForTunnelsDeletedOutsideApp()
|
||||||
reinstateTunnels(ArraySlice(rd), completionHandler: nil)
|
reinstateTunnels(ArraySlice(data), completionHandler: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func reinstateTunnels(_ rdArray: ArraySlice<ReinstationData>, completionHandler: (() -> Void)?) {
|
private func reinstateTunnels(_ rdArray: ArraySlice<ReinstationData>, completionHandler: (() -> Void)?) {
|
||||||
|
|
|
@ -153,8 +153,8 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
}!
|
}!
|
||||||
let firstPeerSectionIndex = interfaceSectionIndex + 1
|
let firstPeerSectionIndex = interfaceSectionIndex + 1
|
||||||
var interfaceFieldIsVisible = self.interfaceFieldIsVisible
|
let interfaceFieldIsVisible = self.interfaceFieldIsVisible
|
||||||
var peerFieldIsVisible = self.peerFieldIsVisible
|
let peerFieldIsVisible = self.peerFieldIsVisible
|
||||||
|
|
||||||
func handleSectionFieldsModified<T>(fields: [T], fieldIsVisible: [Bool], section: Int, changes: [T: TunnelViewModel.Changes.FieldChange]) {
|
func handleSectionFieldsModified<T>(fields: [T], fieldIsVisible: [Bool], section: Int, changes: [T: TunnelViewModel.Changes.FieldChange]) {
|
||||||
for (index, field) in fields.enumerated() {
|
for (index, field) in fields.enumerated() {
|
||||||
|
|
|
@ -417,12 +417,12 @@ extension TunnelsListTableViewController: TunnelsManagerListDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UISplitViewController {
|
extension UISplitViewController {
|
||||||
func showDetailViewController(_ vc: UIViewController, sender: Any?, animated: Bool) {
|
func showDetailViewController(_ viewController: UIViewController, sender: Any?, animated: Bool) {
|
||||||
if animated {
|
if animated {
|
||||||
showDetailViewController(vc, sender: sender)
|
showDetailViewController(viewController, sender: sender)
|
||||||
} else {
|
} else {
|
||||||
UIView.performWithoutAnimation {
|
UIView.performWithoutAnimation {
|
||||||
showDetailViewController(vc, sender: sender)
|
showDetailViewController(viewController, sender: sender)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ extension ZipArchive {
|
||||||
static func unarchive(url: URL, requiredFileExtensions: [String]) throws -> [(fileBaseName: String, contents: Data)] {
|
static func unarchive(url: URL, requiredFileExtensions: [String]) throws -> [(fileBaseName: String, contents: Data)] {
|
||||||
|
|
||||||
var results = [(fileBaseName: String, contents: Data)]()
|
var results = [(fileBaseName: String, contents: Data)]()
|
||||||
var requiredFileExtensionsLowercased = requiredFileExtensions.map { $0.lowercased() }
|
let requiredFileExtensionsLowercased = requiredFileExtensions.map { $0.lowercased() }
|
||||||
|
|
||||||
guard let zipFile = unzOpen64(url.path) else {
|
guard let zipFile = unzOpen64(url.path) else {
|
||||||
throw ZipArchiveError.cantOpenInputZipFile
|
throw ZipArchiveError.cantOpenInputZipFile
|
||||||
|
@ -62,8 +62,8 @@ extension ZipArchive {
|
||||||
guard unzOpenCurrentFile(zipFile) == UNZ_OK else { throw ZipArchiveError.badArchive }
|
guard unzOpenCurrentFile(zipFile) == UNZ_OK else { throw ZipArchiveError.badArchive }
|
||||||
|
|
||||||
let bufferSize = 16384 // 16 KiB
|
let bufferSize = 16384 // 16 KiB
|
||||||
var fileNameBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
|
let fileNameBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
|
||||||
var dataBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
|
let dataBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
|
||||||
|
|
||||||
defer {
|
defer {
|
||||||
fileNameBuffer.deallocate()
|
fileNameBuffer.deallocate()
|
||||||
|
|
|
@ -21,7 +21,7 @@ extension Array {
|
||||||
let execute = queue?.sync ?? { $0() }
|
let execute = queue?.sync ?? { $0() }
|
||||||
|
|
||||||
execute {
|
execute {
|
||||||
DispatchQueue.concurrentPerform(iterations: self.count) { (index) in
|
DispatchQueue.concurrentPerform(iterations: self.count) { index in
|
||||||
let value = transform(self[index])
|
let value = transform(self[index])
|
||||||
resultQueue.sync {
|
resultQueue.sync {
|
||||||
result[index] = value
|
result[index] = value
|
||||||
|
|
|
@ -12,25 +12,27 @@ extension DNSResolver {
|
||||||
private static let resolverQueue = DispatchQueue(label: "DNSResolverQueue", qos: .default, attributes: .concurrent)
|
private static let resolverQueue = DispatchQueue(label: "DNSResolverQueue", qos: .default, attributes: .concurrent)
|
||||||
|
|
||||||
static func resolveSync(endpoints: [Endpoint?]) -> [Result<Endpoint, DNSResolutionError>?] {
|
static func resolveSync(endpoints: [Endpoint?]) -> [Result<Endpoint, DNSResolutionError>?] {
|
||||||
let isAllEndpointsAlreadyResolved = endpoints.allSatisfy({ (maybeEndpoint) -> Bool in
|
let isAllEndpointsAlreadyResolved = endpoints.allSatisfy { maybeEndpoint -> Bool in
|
||||||
return maybeEndpoint?.hasHostAsIPAddress() ?? true
|
return maybeEndpoint?.hasHostAsIPAddress() ?? true
|
||||||
})
|
}
|
||||||
|
|
||||||
if isAllEndpointsAlreadyResolved {
|
if isAllEndpointsAlreadyResolved {
|
||||||
return endpoints.map { (endpoint) in
|
return endpoints.map { endpoint in
|
||||||
return endpoint.map { .success($0) }
|
return endpoint.map { .success($0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return endpoints.concurrentMap(queue: resolverQueue) {
|
return endpoints.concurrentMap(queue: resolverQueue) { endpoint -> Result<Endpoint, DNSResolutionError>? in
|
||||||
(endpoint) -> Result<Endpoint, DNSResolutionError>? in
|
|
||||||
guard let endpoint = endpoint else { return nil }
|
guard let endpoint = endpoint else { return nil }
|
||||||
|
|
||||||
if endpoint.hasHostAsIPAddress() {
|
if endpoint.hasHostAsIPAddress() {
|
||||||
return .success(endpoint)
|
return .success(endpoint)
|
||||||
} else {
|
} else {
|
||||||
return Result { try DNSResolver.resolveSync(endpoint: endpoint) }
|
return Result { try DNSResolver.resolveSync(endpoint: endpoint) }
|
||||||
.mapError { $0 as! DNSResolutionError }
|
.mapError { error -> DNSResolutionError in
|
||||||
|
// swiftlint:disable:next force_cast
|
||||||
|
return error as! DNSResolutionError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ extension IPv4Address {
|
||||||
init?(addrInfo: addrinfo) {
|
init?(addrInfo: addrinfo) {
|
||||||
guard addrInfo.ai_family == AF_INET else { return nil }
|
guard addrInfo.ai_family == AF_INET else { return nil }
|
||||||
|
|
||||||
let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in.self, capacity: MemoryLayout<sockaddr_in>.size) { (ptr) -> Data in
|
let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in.self, capacity: MemoryLayout<sockaddr_in>.size) { ptr -> Data in
|
||||||
return Data(bytes: &ptr.pointee.sin_addr, count: MemoryLayout<in_addr>.size)
|
return Data(bytes: &ptr.pointee.sin_addr, count: MemoryLayout<in_addr>.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ extension IPv6Address {
|
||||||
init?(addrInfo: addrinfo) {
|
init?(addrInfo: addrinfo) {
|
||||||
guard addrInfo.ai_family == AF_INET6 else { return nil }
|
guard addrInfo.ai_family == AF_INET6 else { return nil }
|
||||||
|
|
||||||
let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in6.self, capacity: MemoryLayout<sockaddr_in6>.size) { (ptr) -> Data in
|
let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in6.self, capacity: MemoryLayout<sockaddr_in6>.size) { ptr -> Data in
|
||||||
return Data(bytes: &ptr.pointee.sin6_addr, count: MemoryLayout<in6_addr>.size)
|
return Data(bytes: &ptr.pointee.sin6_addr, count: MemoryLayout<in6_addr>.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import Foundation
|
||||||
import WireGuardKitC
|
import WireGuardKitC
|
||||||
|
|
||||||
/// The class describing a private key used by WireGuard.
|
/// The class describing a private key used by WireGuard.
|
||||||
public class PrivateKey: _BaseKey {
|
public class PrivateKey: BaseKey {
|
||||||
/// Derived public key
|
/// Derived public key
|
||||||
public var publicKey: PublicKey {
|
public var publicKey: PublicKey {
|
||||||
return rawValue.withUnsafeBytes { (privateKeyBufferPointer: UnsafeRawBufferPointer) -> PublicKey in
|
return rawValue.withUnsafeBytes { (privateKeyBufferPointer: UnsafeRawBufferPointer) -> PublicKey in
|
||||||
|
@ -33,13 +33,13 @@ public class PrivateKey: _BaseKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The class describing a public key used by WireGuard.
|
/// The class describing a public key used by WireGuard.
|
||||||
public class PublicKey: _BaseKey {}
|
public class PublicKey: BaseKey {}
|
||||||
|
|
||||||
/// The class describing a pre-shared key used by WireGuard.
|
/// The class describing a pre-shared key used by WireGuard.
|
||||||
public class PreSharedKey: _BaseKey {}
|
public class PreSharedKey: BaseKey {}
|
||||||
|
|
||||||
/// The base key implementation. Should not be used directly.
|
/// The base key implementation. Should not be used directly.
|
||||||
public class _BaseKey: RawRepresentable, Equatable, Hashable {
|
public class BaseKey: RawRepresentable, Equatable, Hashable {
|
||||||
/// Raw key representation
|
/// Raw key representation
|
||||||
public let rawValue: Data
|
public let rawValue: Data
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ public class _BaseKey: RawRepresentable, Equatable, Hashable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func == (lhs: _BaseKey, rhs: _BaseKey) -> Bool {
|
public static func == (lhs: BaseKey, rhs: BaseKey) -> Bool {
|
||||||
return lhs.rawValue.withUnsafeBytes { (lhsBytes: UnsafeRawBufferPointer) -> Bool in
|
return lhs.rawValue.withUnsafeBytes { (lhsBytes: UnsafeRawBufferPointer) -> Bool in
|
||||||
return rhs.rawValue.withUnsafeBytes { (rhsBytes: UnsafeRawBufferPointer) -> Bool in
|
return rhs.rawValue.withUnsafeBytes { (rhsBytes: UnsafeRawBufferPointer) -> Bool in
|
||||||
return key_eq(
|
return key_eq(
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class WireGuardAdapter {
|
||||||
|
|
||||||
var buffer = [UInt8](repeating: 0, count: Int(IFNAMSIZ))
|
var buffer = [UInt8](repeating: 0, count: Int(IFNAMSIZ))
|
||||||
|
|
||||||
return buffer.withUnsafeMutableBufferPointer { (mutableBufferPointer) in
|
return buffer.withUnsafeMutableBufferPointer { mutableBufferPointer in
|
||||||
guard let baseAddress = mutableBufferPointer.baseAddress else { return nil }
|
guard let baseAddress = mutableBufferPointer.baseAddress else { return nil }
|
||||||
|
|
||||||
var ifnameSize = socklen_t(IFNAMSIZ)
|
var ifnameSize = socklen_t(IFNAMSIZ)
|
||||||
|
@ -158,7 +158,7 @@ public class WireGuardAdapter {
|
||||||
networkMonitor.start(queue: self.workQueue)
|
networkMonitor.start(queue: self.workQueue)
|
||||||
self.networkMonitor = networkMonitor
|
self.networkMonitor = networkMonitor
|
||||||
|
|
||||||
self.updateNetworkSettings(tunnelConfiguration: tunnelConfiguration) { (settingsGenerator, error) in
|
self.updateNetworkSettings(tunnelConfiguration: tunnelConfiguration) { settingsGenerator, error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
completionHandler(error)
|
completionHandler(error)
|
||||||
} else {
|
} else {
|
||||||
|
@ -212,7 +212,7 @@ public class WireGuardAdapter {
|
||||||
// This will broadcast the `NEVPNStatusDidChange` notification to the GUI process.
|
// This will broadcast the `NEVPNStatusDidChange` notification to the GUI process.
|
||||||
self.packetTunnelProvider?.reasserting = true
|
self.packetTunnelProvider?.reasserting = true
|
||||||
|
|
||||||
self.updateNetworkSettings(tunnelConfiguration: tunnelConfiguration) { (settingsGenerator, error) in
|
self.updateNetworkSettings(tunnelConfiguration: tunnelConfiguration) { settingsGenerator, error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
completionHandler(error)
|
completionHandler(error)
|
||||||
} else {
|
} else {
|
||||||
|
@ -230,7 +230,7 @@ public class WireGuardAdapter {
|
||||||
/// Setup WireGuard log handler.
|
/// Setup WireGuard log handler.
|
||||||
private func setupLogHandler() {
|
private func setupLogHandler() {
|
||||||
let context = Unmanaged.passUnretained(self).toOpaque()
|
let context = Unmanaged.passUnretained(self).toOpaque()
|
||||||
wgSetLogger(context) { (context, logLevel, message) in
|
wgSetLogger(context) { context, logLevel, message in
|
||||||
guard let context = context, let message = message else { return }
|
guard let context = context, let message = message else { return }
|
||||||
|
|
||||||
let unretainedSelf = Unmanaged<WireGuardAdapter>.fromOpaque(context)
|
let unretainedSelf = Unmanaged<WireGuardAdapter>.fromOpaque(context)
|
||||||
|
@ -251,7 +251,10 @@ public class WireGuardAdapter {
|
||||||
let resolvedEndpoints: [Endpoint?]
|
let resolvedEndpoints: [Endpoint?]
|
||||||
|
|
||||||
let resolvePeersResult = Result { try self.resolvePeers(for: tunnelConfiguration) }
|
let resolvePeersResult = Result { try self.resolvePeers(for: tunnelConfiguration) }
|
||||||
.mapError { $0 as! WireGuardAdapterError }
|
.mapError { error -> WireGuardAdapterError in
|
||||||
|
// swiftlint:disable:next force_cast
|
||||||
|
return error as! WireGuardAdapterError
|
||||||
|
}
|
||||||
|
|
||||||
switch resolvePeersResult {
|
switch resolvePeersResult {
|
||||||
case .success(let endpoints):
|
case .success(let endpoints):
|
||||||
|
@ -271,10 +274,10 @@ public class WireGuardAdapter {
|
||||||
condition.lock()
|
condition.lock()
|
||||||
defer { condition.unlock() }
|
defer { condition.unlock() }
|
||||||
|
|
||||||
self.packetTunnelProvider?.setTunnelNetworkSettings(networkSettings, completionHandler: { (error) in
|
self.packetTunnelProvider?.setTunnelNetworkSettings(networkSettings) { error in
|
||||||
systemError = error
|
systemError = error
|
||||||
condition.signal()
|
condition.signal()
|
||||||
})
|
}
|
||||||
|
|
||||||
// Packet tunnel's `setTunnelNetworkSettings` times out in certain
|
// Packet tunnel's `setTunnelNetworkSettings` times out in certain
|
||||||
// scenarios & never calls the given callback.
|
// scenarios & never calls the given callback.
|
||||||
|
@ -301,7 +304,7 @@ public class WireGuardAdapter {
|
||||||
private func resolvePeers(for tunnelConfiguration: TunnelConfiguration) throws -> [Endpoint?] {
|
private func resolvePeers(for tunnelConfiguration: TunnelConfiguration) throws -> [Endpoint?] {
|
||||||
let endpoints = tunnelConfiguration.peers.map { $0.endpoint }
|
let endpoints = tunnelConfiguration.peers.map { $0.endpoint }
|
||||||
let resolutionResults = DNSResolver.resolveSync(endpoints: endpoints)
|
let resolutionResults = DNSResolver.resolveSync(endpoints: endpoints)
|
||||||
let resolutionErrors = resolutionResults.compactMap { (result) -> DNSResolutionError? in
|
let resolutionErrors = resolutionResults.compactMap { result -> DNSResolutionError? in
|
||||||
if case .failure(let error) = result {
|
if case .failure(let error) = result {
|
||||||
return error
|
return error
|
||||||
} else {
|
} else {
|
||||||
|
@ -313,7 +316,8 @@ public class WireGuardAdapter {
|
||||||
throw WireGuardAdapterError.dnsResolution(resolutionErrors)
|
throw WireGuardAdapterError.dnsResolution(resolutionErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
let resolvedEndpoints = resolutionResults.map { (result) -> Endpoint? in
|
let resolvedEndpoints = resolutionResults.map { result -> Endpoint? in
|
||||||
|
// swiftlint:disable:next force_try
|
||||||
return try! result?.get()
|
return try! result?.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1746,7 +1746,7 @@
|
||||||
isa = XCRemoteSwiftPackageReference;
|
isa = XCRemoteSwiftPackageReference;
|
||||||
repositoryURL = "https://git.zx2c4.com/wireguard-apple";
|
repositoryURL = "https://git.zx2c4.com/wireguard-apple";
|
||||||
requirement = {
|
requirement = {
|
||||||
branch = master;
|
branch = "am/wg-adapter-rebased";
|
||||||
kind = branch;
|
kind = branch;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
"package": "WireGuardKit",
|
"package": "WireGuardKit",
|
||||||
"repositoryURL": "https://git.zx2c4.com/wireguard-apple",
|
"repositoryURL": "https://git.zx2c4.com/wireguard-apple",
|
||||||
"state": {
|
"state": {
|
||||||
"branch": "master",
|
"branch": "am/wg-adapter-rebased",
|
||||||
"revision": "737f847c0db36429f7136fb514409c22e13a70ee",
|
"revision": "e52f83b915a985a945dff622e5f48fa52e96f045",
|
||||||
"version": null
|
"version": null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue