From a1b40bfc47b3dc849ed775e63d9bfcaed445a57b Mon Sep 17 00:00:00 2001 From: Tobias Hagemann Date: Thu, 12 Sep 2024 10:39:46 +0200 Subject: [PATCH] Fixed SwiftLint warnings --- .../Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift | 2 +- .../Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift | 2 +- Sources/CryptomatorCloudAccess/Logging/HTTPDebugLogger.swift | 2 -- Tests/CryptomatorCloudAccessTests/Crypto/CryptorMock.swift | 2 +- Tests/CryptomatorCloudAccessTests/Crypto/VaultConfigTests.swift | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/CryptomatorCloudAccess/Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift b/Sources/CryptomatorCloudAccess/Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift index f90486f..66544b5 100644 --- a/Sources/CryptomatorCloudAccess/Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift +++ b/Sources/CryptomatorCloudAccess/Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift @@ -121,7 +121,7 @@ class VaultFormat6ShortenedNameCache { return Promise(originalName) } else { return loadLngFile(shortenedName).then { data -> String in - let originalName = String(decoding: data, as: UTF8.self) + let originalName = String(data: data, encoding: .utf8)! try? self.addToCache(shortenedName, originalName: originalName) return originalName } diff --git a/Sources/CryptomatorCloudAccess/Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift b/Sources/CryptomatorCloudAccess/Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift index c4ce566..a0ce300 100644 --- a/Sources/CryptomatorCloudAccess/Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift +++ b/Sources/CryptomatorCloudAccess/Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift @@ -181,7 +181,7 @@ class VaultFormat7ShortenedNameCache { return Promise(originalName) } else { return loadNameC9S(c9sDirPath).then { data -> String in - let originalName = String(decoding: data, as: UTF8.self) + let originalName = String(data: data, encoding: .utf8)! try? self.addToCache(shortenedName, originalName: originalName) return originalName } diff --git a/Sources/CryptomatorCloudAccess/Logging/HTTPDebugLogger.swift b/Sources/CryptomatorCloudAccess/Logging/HTTPDebugLogger.swift index 5d375da..e7f60d3 100644 --- a/Sources/CryptomatorCloudAccess/Logging/HTTPDebugLogger.swift +++ b/Sources/CryptomatorCloudAccess/Logging/HTTPDebugLogger.swift @@ -42,7 +42,6 @@ enum HTTPDebugLogger { guard let bodyData = request.httpBody else { return .none } - // swiftlint:disable:next non_optional_string_data_conversion if let body = String(data: bodyData, encoding: .utf8) { if body.isEmpty { return .empty @@ -103,7 +102,6 @@ enum HTTPDebugLogger { if let contentEncodingHeaderField = response.value(forHTTPHeaderField: "Content-Encoding"), contentEncodingHeaderField.caseInsensitiveCompare("identity") != .orderedSame { return .encoded } - // swiftlint:disable:next non_optional_string_data_conversion if let body = String(data: bodyData, encoding: .utf8) { if body.isEmpty { return .empty diff --git a/Tests/CryptomatorCloudAccessTests/Crypto/CryptorMock.swift b/Tests/CryptomatorCloudAccessTests/Crypto/CryptorMock.swift index 3d8b888..88704f1 100644 --- a/Tests/CryptomatorCloudAccessTests/Crypto/CryptorMock.swift +++ b/Tests/CryptomatorCloudAccessTests/Crypto/CryptorMock.swift @@ -55,7 +55,7 @@ public class CryptorMock: Cryptor { } override public func encryptDirId(_ dirId: Data) throws -> String { - if let dirId = dirIds[String(decoding: dirId, as: UTF8.self)] { + if let dirId = dirIds[String(data: dirId, encoding: .utf8)!] { return dirId } else { return "99ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" diff --git a/Tests/CryptomatorCloudAccessTests/Crypto/VaultConfigTests.swift b/Tests/CryptomatorCloudAccessTests/Crypto/VaultConfigTests.swift index 2ba2624..82a4671 100644 --- a/Tests/CryptomatorCloudAccessTests/Crypto/VaultConfigTests.swift +++ b/Tests/CryptomatorCloudAccessTests/Crypto/VaultConfigTests.swift @@ -86,7 +86,7 @@ class VaultConfigTests: XCTestCase { let vaultConfig = VaultConfig(id: "ABB9F673-F3E8-41A7-A43B-D29F5DA65068", format: 8, cipherCombo: .sivCtrMac, shorteningThreshold: 220) let rawKey = [UInt8](repeating: 0x55, count: 64) let token = try vaultConfig.toToken(keyId: "masterkeyfile:masterkey.cryptomator", rawKey: rawKey) - let tokenComponents = String(decoding: token, as: UTF8.self).split(separator: ".") + let tokenComponents = String(data: token, encoding: .utf8)!.split(separator: ".") // check header let header: [String: String] = try decodeTokenComponent(String(tokenComponents[0])) XCTAssertEqual(["typ": "JWT", "alg": "HS256", "kid": "masterkeyfile:masterkey.cryptomator"], header)