aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/ZipArchive
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-12 12:28:27 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-12 12:28:27 -0600
commitd06cff2a360839c67ce42a695f01bb933ba820c0 (patch)
tree3aa166de8c75947345b9bfb8398ee8b7c6b581c7 /WireGuard/WireGuard/ZipArchive
parentAdded swiftlint and fixed all errors (and a bunch, but not all, warnings) (diff)
downloadwireguard-apple-d06cff2a360839c67ce42a695f01bb933ba820c0.tar.xz
wireguard-apple-d06cff2a360839c67ce42a695f01bb933ba820c0.zip
Tons more swiftlint warnings fixed. Still a few remaining.
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'WireGuard/WireGuard/ZipArchive')
-rw-r--r--WireGuard/WireGuard/ZipArchive/ZipArchive.swift31
-rw-r--r--WireGuard/WireGuard/ZipArchive/ZipExporter.swift8
-rw-r--r--WireGuard/WireGuard/ZipArchive/ZipImporter.swift12
3 files changed, 21 insertions, 30 deletions
diff --git a/WireGuard/WireGuard/ZipArchive/ZipArchive.swift b/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
index 900341ec..12cfb698 100644
--- a/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
+++ b/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
@@ -9,7 +9,7 @@ enum ZipArchiveError: WireGuardAppError {
case badArchive
func alertText() -> (String, String)? {
- switch (self) {
+ switch self {
case .cantOpenInputZipFile:
return ("Unable to read zip archive", "The zip archive could not be read.")
case .cantOpenOutputZipFileForWriting:
@@ -49,15 +49,11 @@ class ZipArchive {
defer {
unzClose(zipFile)
}
- guard (unzGoToFirstFile(zipFile) == UNZ_OK) else {
- throw ZipArchiveError.badArchive
- }
+ guard unzGoToFirstFile(zipFile) == UNZ_OK else { throw ZipArchiveError.badArchive }
var resultOfGoToNextFile: Int32
repeat {
- guard (unzOpenCurrentFile(zipFile) == UNZ_OK) else {
- throw ZipArchiveError.badArchive
- }
+ guard unzOpenCurrentFile(zipFile) == UNZ_OK else { throw ZipArchiveError.badArchive }
let bufferSize = 16384 // 16 KiB
var fileNameBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
@@ -68,38 +64,33 @@ class ZipArchive {
dataBuffer.deallocate()
}
- guard (unzGetCurrentFileInfo64(zipFile, nil, fileNameBuffer, UInt(bufferSize), nil, 0, nil, 0) == UNZ_OK) else {
- throw ZipArchiveError.badArchive
- }
+ guard unzGetCurrentFileInfo64(zipFile, nil, fileNameBuffer, UInt(bufferSize), nil, 0, nil, 0) == UNZ_OK else { throw ZipArchiveError.badArchive }
let lastChar = String(cString: fileNameBuffer).suffix(1)
let isDirectory = (lastChar == "/" || lastChar == "\\")
let fileURL = URL(fileURLWithFileSystemRepresentation: fileNameBuffer, isDirectory: isDirectory, relativeTo: nil)
- if (!isDirectory && requiredFileExtensions.contains(fileURL.pathExtension)) {
+ if !isDirectory && requiredFileExtensions.contains(fileURL.pathExtension) {
var unzippedData = Data()
var bytesRead: Int32 = 0
repeat {
bytesRead = unzReadCurrentFile(zipFile, dataBuffer, UInt32(bufferSize))
- if (bytesRead > 0) {
+ if bytesRead > 0 {
let dataRead = dataBuffer.withMemoryRebound(to: UInt8.self, capacity: bufferSize) {
- (buf: UnsafeMutablePointer<UInt8>) -> Data in
- return Data(bytes: buf, count: Int(bytesRead))
+ return Data(bytes: $0, count: Int(bytesRead))
}
unzippedData.append(dataRead)
}
- } while (bytesRead > 0)
+ } while bytesRead > 0
results.append((fileBaseName: fileURL.deletingPathExtension().lastPathComponent, contents: unzippedData))
}
- guard (unzCloseCurrentFile(zipFile) == UNZ_OK) else {
- throw ZipArchiveError.badArchive
- }
+ guard unzCloseCurrentFile(zipFile) == UNZ_OK else { throw ZipArchiveError.badArchive }
resultOfGoToNextFile = unzGoToNextFile(zipFile)
- } while (resultOfGoToNextFile == UNZ_OK)
+ } while resultOfGoToNextFile == UNZ_OK
- if (resultOfGoToNextFile == UNZ_END_OF_LIST_OF_FILE) {
+ if resultOfGoToNextFile == UNZ_END_OF_LIST_OF_FILE {
return results
} else {
throw ZipArchiveError.badArchive
diff --git a/WireGuard/WireGuard/ZipArchive/ZipExporter.swift b/WireGuard/WireGuard/ZipArchive/ZipExporter.swift
index f875e1b8..b0e6b15d 100644
--- a/WireGuard/WireGuard/ZipArchive/ZipExporter.swift
+++ b/WireGuard/WireGuard/ZipArchive/ZipExporter.swift
@@ -7,7 +7,7 @@ enum ZipExporterError: WireGuardAppError {
case noTunnelsToExport
func alertText() -> (String, String)? {
- switch (self) {
+ switch self {
case .noTunnelsToExport:
return ("Nothing to export", "There are no tunnels to export")
}
@@ -18,7 +18,7 @@ class ZipExporter {
static func exportConfigFiles(tunnelConfigurations: [TunnelConfiguration], to url: URL,
completion: @escaping (WireGuardAppError?) -> Void) {
- guard (!tunnelConfigurations.isEmpty) else {
+ guard !tunnelConfigurations.isEmpty else {
completion(ZipExporterError.noTunnelsToExport)
return
}
@@ -28,14 +28,14 @@ class ZipExporter {
for tunnelConfiguration in tunnelConfigurations {
if let contents = WgQuickConfigFileWriter.writeConfigFile(from: tunnelConfiguration) {
let name = tunnelConfiguration.interface.name
- if (name.isEmpty || name == lastTunnelName) { continue }
+ if name.isEmpty || name == lastTunnelName { continue }
inputsToArchiver.append((fileName: "\(name).conf", contents: contents))
lastTunnelName = name
}
}
do {
try ZipArchive.archive(inputs: inputsToArchiver, to: url)
- } catch (let error as WireGuardAppError) {
+ } catch let error as WireGuardAppError {
DispatchQueue.main.async { completion(error) }
return
} catch {
diff --git a/WireGuard/WireGuard/ZipArchive/ZipImporter.swift b/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
index 194dc0ec..e2767f2e 100644
--- a/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
+++ b/WireGuard/WireGuard/ZipArchive/ZipImporter.swift
@@ -7,7 +7,7 @@ enum ZipImporterError: WireGuardAppError {
case noTunnelsInZipArchive
func alertText() -> (String, String)? {
- switch (self) {
+ switch self {
case .noTunnelsInZipArchive:
return ("No tunnels in zip archive", "No .conf tunnel files were found inside the zip archive.")
}
@@ -23,17 +23,17 @@ class ZipImporter {
for (index, unarchivedFile) in unarchivedFiles.enumerated().reversed() {
let fileBaseName = unarchivedFile.fileBaseName
let trimmedName = fileBaseName.trimmingCharacters(in: .whitespacesAndNewlines)
- if (!trimmedName.isEmpty) {
+ if !trimmedName.isEmpty {
unarchivedFiles[index].fileBaseName = trimmedName
} else {
unarchivedFiles.remove(at: index)
}
}
- if (unarchivedFiles.isEmpty) {
+ if unarchivedFiles.isEmpty {
throw ZipImporterError.noTunnelsInZipArchive
}
- } catch (let error as WireGuardAppError) {
+ } catch let error as WireGuardAppError {
DispatchQueue.main.async { completion(.failure(error)) }
return
} catch {
@@ -41,9 +41,9 @@ class ZipImporter {
}
unarchivedFiles.sort { $0.fileBaseName < $1.fileBaseName }
- var configs = Array<TunnelConfiguration?>(repeating: nil, count: unarchivedFiles.count)
+ var configs: [TunnelConfiguration?] = Array(repeating: nil, count: unarchivedFiles.count)
for (index, file) in unarchivedFiles.enumerated() {
- if (index > 0 && file == unarchivedFiles[index - 1]) {
+ if index > 0 && file == unarchivedFiles[index - 1] {
continue
}
guard let fileContents = String(data: file.contents, encoding: .utf8) else {