Skip to content

Commit a855f11

Browse files
committed
Fixed SwiftLint warnings
1 parent 8dc2823 commit a855f11

17 files changed

+41
-51
lines changed

CryptomatorCommon/Sources/CryptomatorCommonCore/Hub/CryptomatorHubAuthenticator.swift

+2-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public enum CryptomatorHubAuthenticatorError: Error {
3333
case unexpectedResponse
3434
case deviceNameAlreadyExists
3535

36-
case unexpectedPrivateKeyFormat
3736
case invalidVaultConfig
3837
case invalidHubConfig
3938
case invalidBaseURL
@@ -154,13 +153,9 @@ public class CryptomatorHubAuthenticator: HubDeviceRegistering, HubKeyReceiving
154153
}
155154

156155
private func getEncryptedUserKeyJWE(userDto: UserDto, setupCode: String, publicKey: P384.KeyAgreement.PublicKey) throws -> JWE {
157-
guard let privateKey = userDto.privateKey.data(using: .utf8) else {
158-
throw CryptomatorHubAuthenticatorError.unexpectedPrivateKeyFormat
159-
}
156+
let privateKey = Data(userDto.privateKey.utf8)
160157
let jwe = try JWE(compactSerialization: privateKey)
161-
162158
let userKey = try JWEHelper.decryptUserKey(jwe: jwe, setupCode: setupCode)
163-
164159
return try JWEHelper.encryptUserKey(userKey: userKey, deviceKey: publicKey)
165160
}
166161

@@ -239,9 +234,7 @@ public class CryptomatorHubAuthenticator: HubDeviceRegistering, HubKeyReceiving
239234
let httpResponse = response as? HTTPURLResponse
240235
switch httpResponse?.statusCode {
241236
case 200:
242-
guard let body = String(data: data, encoding: .utf8) else {
243-
throw CryptomatorHubAuthenticatorError.unexpectedResponse
244-
}
237+
let body = String(decoding: data, as: UTF8.self)
245238
return .success(encryptedVaultKey: body, header: httpResponse?.allHeaderFields ?? [:])
246239
case 402:
247240
return .licenseExceeded

CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/CloudProviderType.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ extension CloudProviderType: DatabaseValueConvertible {
2525
guard let data = try? jsonEncoder.encode(self) else {
2626
return .null
2727
}
28-
let string = String(data: data, encoding: .utf8)
29-
return string?.databaseValue ?? .null
28+
let string = String(decoding: data, as: UTF8.self)
29+
return string.databaseValue
3030
}
3131

3232
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
3333
guard let string = String.fromDatabaseValue(dbValue) else { return nil }
34-
guard let data = string.data(using: .utf8) else { return nil }
34+
let data = Data(string.utf8)
3535
let jsonDecoder = JSONDecoder()
3636
return try? jsonDecoder.decode(CloudProviderType.self, from: data)
3737
}

CryptomatorCommon/Sources/CryptomatorCommonCore/Manager/VaultPasswordManager.swift

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ public protocol VaultPasswordManager {
1717
}
1818

1919
public enum VaultPasswordManagerError: Error {
20-
case encodingError
2120
case passwordNotFound
2221
}
2322

2423
public class VaultPasswordKeychainManager: VaultPasswordManager {
2524
public init() {}
2625
public func setPassword(_ password: String, forVaultUID vaultUID: String) throws {
27-
guard let data = password.data(using: .utf8) else {
28-
throw VaultPasswordManagerError.encodingError
29-
}
26+
let data = Data(password.utf8)
3027
try CryptomatorUserPresenceKeychain.vaultPassword.set(vaultUID, value: data)
3128
}
3229

@@ -56,9 +53,7 @@ public class VaultPasswordKeychainManager: VaultPasswordManager {
5653
guard let data = CryptomatorUserPresenceKeychain.vaultPassword.getAsData(vaultUID, context: context) else {
5754
throw VaultPasswordManagerError.passwordNotFound
5855
}
59-
guard let password = String(data: data, encoding: .utf8) else {
60-
throw VaultPasswordManagerError.encodingError
61-
}
56+
let password = String(decoding: data, as: UTF8.self)
6257
return password
6358
}
6459
}

CryptomatorCommon/Tests/CryptomatorCommonCoreTests/Hub/HubAuthenticationViewModelTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ final class HubAuthenticationViewModelTests: XCTestCase {
242242
private struct TestError: Error {}
243243

244244
private func validHubVaultConfig() -> Data {
245-
"eyJraWQiOiJodWIraHR0cHM6Ly90ZXN0aW5nLmh1Yi5jcnlwdG9tYXRvci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5Gb05tNEJuNjZuVkNKLU9pUUJYN3RhaVUtby1yWSJ9LCJhcHUiOiIiLCJhcHYiOiIifQ.._r7LC8HLc00jk2SI.ooeI0-E29jryMJ_wbGWKVc_IfHOh3Mlfh5geRYEmLTA4GKHItRYmDdZvGsCj9pJRoNORyHdmlAMxXXIXq_v9ZocoCwZrN7EsaB8A3Kukka35i1sr7kpNbksk3G_COsGRmwQ.GJCKBE-OZ7Nm5RMf_9UwVg".utf8)
250250
}
251251
}
252252

CryptomatorCommonHostedTests/Keychain/WebDAVKeychainTests.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class WebDAVKeychainTests: XCTestCase {
2424
let baseURL = URL(string: "www.testurl.com")!
2525
let username = "user"
2626
let password = "pass"
27-
let certificate = "CertificateData".data(using: .utf8)
27+
let certificate = Data("CertificateData".utf8)
2828
let identifier = UUID().uuidString
2929
let credential = WebDAVCredential(baseURL: baseURL, username: username, password: password, allowedCertificate: certificate, identifier: identifier)
3030

@@ -47,7 +47,7 @@ class WebDAVKeychainTests: XCTestCase {
4747
let baseURL = URL(string: "www.testurl.com")!
4848
let username = "user"
4949
let password = "pass"
50-
let certificate = "CertificateData".data(using: .utf8)
50+
let certificate = Data("CertificateData".utf8)
5151
let identifier = UUID().uuidString
5252
let credential = WebDAVCredential(baseURL: baseURL, username: username, password: password, allowedCertificate: certificate, identifier: identifier)
5353

@@ -61,7 +61,7 @@ class WebDAVKeychainTests: XCTestCase {
6161
checkSaveThrowsDuplicateErrorAndKeychainDidNotChange(for: WebDAVCredential(baseURL: baseURL, username: username, password: password + "Foo", allowedCertificate: certificate, identifier: UUID().uuidString), originalCredential: credential)
6262

6363
// Different Certificate is still a duplicate if baseURL and username already exists in the keychain and the identifier does not match
64-
checkSaveThrowsDuplicateErrorAndKeychainDidNotChange(for: WebDAVCredential(baseURL: baseURL, username: username, password: password, allowedCertificate: "CertificateData1".data(using: .utf8), identifier: UUID().uuidString), originalCredential: credential)
64+
checkSaveThrowsDuplicateErrorAndKeychainDidNotChange(for: WebDAVCredential(baseURL: baseURL, username: username, password: password, allowedCertificate: Data("CertificateData1".utf8), identifier: UUID().uuidString), originalCredential: credential)
6565

6666
// Missing Certificate is still a duplicate if baseURL and username already exists in the keychain and the identifier does not match
6767
checkSaveThrowsDuplicateErrorAndKeychainDidNotChange(for: WebDAVCredential(baseURL: baseURL, username: username, password: password, allowedCertificate: nil, identifier: UUID().uuidString), originalCredential: credential)
@@ -72,7 +72,7 @@ class WebDAVKeychainTests: XCTestCase {
7272
let baseURL = URL(string: "www.testurl.com")!
7373
let username = "user"
7474
let password = "pass"
75-
let certificate = "CertificateData".data(using: .utf8)
75+
let certificate = Data("CertificateData".utf8)
7676
let identifier = UUID().uuidString
7777
let credential = WebDAVCredential(baseURL: baseURL, username: username, password: password, allowedCertificate: certificate, identifier: identifier)
7878
XCTAssertNoThrow(try manager.saveCredentialToKeychain(credential))
@@ -85,7 +85,7 @@ class WebDAVKeychainTests: XCTestCase {
8585
let baseURL = URL(string: "www.testurl.com")!
8686
let username = "user"
8787
let password = "pass"
88-
let certificate = "CertificateData".data(using: .utf8)
88+
let certificate = Data("CertificateData".utf8)
8989
let identifier = UUID().uuidString
9090
let credential = WebDAVCredential(baseURL: baseURL, username: username, password: password, allowedCertificate: certificate, identifier: identifier)
9191
XCTAssertNoThrow(try manager.saveCredentialToKeychain(credential))
@@ -112,7 +112,7 @@ class WebDAVKeychainTests: XCTestCase {
112112
let baseURL = URL(string: "www.testurl.com")!
113113
let firstUsername = "user"
114114
let firstPassword = "pass"
115-
let certificate = "CertificateData".data(using: .utf8)
115+
let certificate = Data("CertificateData".utf8)
116116
let firstIdentifier = UUID().uuidString
117117
let firstCredential = WebDAVCredential(baseURL: baseURL, username: firstUsername, password: firstPassword, allowedCertificate: certificate, identifier: firstIdentifier)
118118

@@ -151,7 +151,7 @@ class WebDAVKeychainTests: XCTestCase {
151151
let baseURL = URL(string: "www.testurl.com")!
152152
let firstUsername = "user"
153153
let firstPassword = "pass"
154-
let certificate = "CertificateData".data(using: .utf8)
154+
let certificate = Data("CertificateData".utf8)
155155
let firstIdentifier = UUID().uuidString
156156
let firstCredential = WebDAVCredential(baseURL: baseURL, username: firstUsername, password: firstPassword, allowedCertificate: certificate, identifier: firstIdentifier)
157157
try manager.saveCredentialToKeychain(firstCredential)

CryptomatorFileProvider/FileProviderEnumerator.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
6767

6868
var pageToken: String?
6969
if page != NSFileProviderPage.initialPageSortedByDate as NSFileProviderPage, page != NSFileProviderPage.initialPageSortedByName as NSFileProviderPage {
70-
pageToken = String(data: page.rawValue, encoding: .utf8)
70+
pageToken = String(decoding: page.rawValue, as: UTF8.self)
7171
}
7272
DDLogDebug("enumerateItems called for identifier: \(enumeratedItemIdentifier) - initialPage \(pageToken == nil)")
7373
adapterProvider.unlockMonitor.execute {

CryptomatorFileProvider/Middleware/TaskExecutor/ItemEnumerationTaskExecutor.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class ItemEnumerationTaskExecutor: WorkflowMiddleware {
109109
let localURL = localCachedFileInfo?.localURL
110110
return FileProviderItem(metadata: metadata, domainIdentifier: self.domainIdentifier, newestVersionLocallyCached: newestVersionLocallyCached, localURL: localURL, error: uploadTasks[index]?.failedWithError)
111111
}
112-
if let nextPageTokenData = itemList.nextPageToken?.data(using: .utf8) {
112+
if let nextPageToken = itemList.nextPageToken {
113+
let nextPageTokenData = Data(nextPageToken.utf8)
113114
return FileProviderItemList(items: items, nextPageToken: NSFileProviderPage(nextPageTokenData))
114115
}
115116
try self.cleanUpNoLongerInTheCloudExistingItems(insideParentID: folderMetadata.id!)

CryptomatorFileProviderTests/DB/MetadataManagerTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class MetadataManagerTests: XCTestCase {
236236
let cloudPath = CloudPath("/File.txt")
237237
let itemMetadata = ItemMetadata(name: "File.txt", type: .file, size: 100, parentID: NSFileProviderItemIdentifier.rootContainerDatabaseValue, lastModifiedDate: nil, statusCode: .isUploaded, cloudPath: cloudPath, isPlaceholderItem: false)
238238
try manager.cacheMetadata(itemMetadata)
239-
let tagData = "Foo".data(using: .utf8)!
239+
let tagData = Data("Foo".utf8)
240240
let id = try XCTUnwrap(itemMetadata.id)
241241
try manager.setTagData(to: tagData, forItemWithID: id)
242242

@@ -246,7 +246,7 @@ class MetadataManagerTests: XCTestCase {
246246

247247
func testSetTagDataToNil() throws {
248248
let cloudPath = CloudPath("/File.txt")
249-
let tagData = "Foo".data(using: .utf8)!
249+
let tagData = Data("Foo".utf8)
250250
let itemMetadata = ItemMetadata(name: "File.txt", type: .file, size: 100, parentID: NSFileProviderItemIdentifier.rootContainerDatabaseValue, lastModifiedDate: nil, statusCode: .isUploaded, cloudPath: cloudPath, isPlaceholderItem: false, tagData: tagData)
251251
try manager.cacheMetadata(itemMetadata)
252252

@@ -259,7 +259,7 @@ class MetadataManagerTests: XCTestCase {
259259

260260
func testCacheMetadataDoesNotOverwriteExistingTagData() throws {
261261
let cloudPath = CloudPath("/File.txt")
262-
let tagData = "Foo".data(using: .utf8)!
262+
let tagData = Data("Foo".utf8)
263263
let itemMetadata = ItemMetadata(name: "File.txt", type: .file, size: 100, parentID: NSFileProviderItemIdentifier.rootContainerDatabaseValue, lastModifiedDate: nil, statusCode: .isUploaded, cloudPath: cloudPath, isPlaceholderItem: false, tagData: tagData)
264264
try manager.cacheMetadata(itemMetadata)
265265

CryptomatorFileProviderTests/FileProviderAdapter/FileProviderAdapterImportDocumentTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FileProviderAdapterImportDocumentTests: FileProviderAdapterTestCase {
4040

4141
// Check that file was copied to the url provided by the localURLProvider
4242
XCTAssert(FileManager.default.fileExists(atPath: expectedFileURL.path))
43-
let contentOfCopiedFile = try String(data: Data(contentsOf: expectedFileURL), encoding: .utf8)
43+
let contentOfCopiedFile = try String(decoding: Data(contentsOf: expectedFileURL), as: UTF8.self)
4444
XCTAssertEqual(fileContent, contentOfCopiedFile)
4545
// Check that the original file was not altered
4646
XCTAssert(FileManager.default.contentsEqual(atPath: fileURL.path, andPath: expectedFileURL.path))
@@ -101,7 +101,7 @@ class FileProviderAdapterImportDocumentTests: FileProviderAdapterTestCase {
101101

102102
// Check that existing file at the url provided by the localURLProvider was not overwritten
103103
XCTAssert(FileManager.default.fileExists(atPath: expectedFileURL.path))
104-
let contentOfCopiedFile = try String(data: Data(contentsOf: expectedFileURL), encoding: .utf8)
104+
let contentOfCopiedFile = try String(decoding: Data(contentsOf: expectedFileURL), as: UTF8.self)
105105
XCTAssertEqual(existingFileContent, contentOfCopiedFile)
106106

107107
XCTAssertEqual(1, metadataManagerMock.removedMetadataID.count)
@@ -140,7 +140,7 @@ class FileProviderAdapterImportDocumentTests: FileProviderAdapterTestCase {
140140
XCTAssert(FileManager.default.fileExists(atPath: self.expectedFileURL.path))
141141
let contentOfCopiedFile: String?
142142
do {
143-
contentOfCopiedFile = try String(data: Data(contentsOf: self.expectedFileURL), encoding: .utf8)
143+
contentOfCopiedFile = try String(decoding: Data(contentsOf: self.expectedFileURL), as: UTF8.self)
144144
} catch {
145145
XCTFail("Content of copied file failed with error: \(error)")
146146
return

CryptomatorFileProviderTests/FileProviderAdapter/FileProviderAdapterSetTagDataTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FileProviderAdapterSetTagDataTests: FileProviderAdapterTestCase {
1616
func testSetTagData() throws {
1717
let expectation = XCTestExpectation()
1818
metadataManagerMock.cachedMetadata[2] = ItemMetadata(id: 2, name: "Test", type: .file, size: nil, parentID: 1, lastModifiedDate: nil, statusCode: .isUploaded, cloudPath: CloudPath("/Test"), isPlaceholderItem: false, isCandidateForCacheCleanup: false, favoriteRank: nil, tagData: nil)
19-
let tagData = "Foo".data(using: .utf8)!
19+
let tagData = Data("Foo".utf8)
2020

2121
adapter.setTagData(tagData, forItemIdentifier: itemIdentifier) { item, error in
2222
XCTAssertNil(error)

CryptomatorFileProviderTests/FileProviderAdapter/FileProviderAdapterStartProvidingItemTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class FileProviderAdapterStartProvidingItemTests: FileProviderAdapterTestCase {
174174
private func simulateFileChangeInTheCloud() {
175175
// Simulate an file update in the cloud by enforce an newer lastModifiedDate in the cloud and change the file content in the cloud
176176
cloudProviderMock.lastModifiedDate[cloudPath.path] = Date(timeIntervalSince1970: 10)
177-
cloudProviderMock.files[cloudPath.path] = "Updated File 1 content".data(using: .utf8)
177+
cloudProviderMock.files[cloudPath.path] = Data("Updated File 1 content".utf8)
178178
}
179179

180180
class WorkFlowSchedulerStartProvidingItemMock: WorkflowScheduler {

CryptomatorFileProviderTests/FileProviderEnumeratorTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class FileProviderEnumeratorTests: FileProviderEnumeratorTestCase {
8989
let enumerator = createFullyMockedEnumerator(for: .rootContainer)
9090
let page = NSFileProviderPage(NSFileProviderPage.initialPageSortedByName as Data)
9191
let nextPageToken = "Foo"
92-
let nextFileProviderPage = NSFileProviderPage(nextPageToken.data(using: .utf8)!)
92+
let nextFileProviderPage = NSFileProviderPage(Data(nextPageToken.utf8))
9393
let itemList = FileProviderItemList(items: items, nextPageToken: nextFileProviderPage)
9494
adapterProvidingMock.getAdapterForDomainDbPathDelegateNotificatorTaskRegistratorReturnValue = adapterMock
9595
adapterMock.enumerateItemsForWithPageTokenReturnValue = Promise(itemList)
@@ -107,7 +107,7 @@ class FileProviderEnumeratorTests: FileProviderEnumeratorTestCase {
107107
let expectation = XCTestExpectation()
108108
let enumerator = createFullyMockedEnumerator(for: .rootContainer)
109109
let pageToken = "Foo"
110-
let page = NSFileProviderPage(pageToken.data(using: .utf8)!)
110+
let page = NSFileProviderPage(Data(pageToken.utf8))
111111
let itemList = FileProviderItemList(items: items, nextPageToken: nil)
112112
adapterProvidingMock.getAdapterForDomainDbPathDelegateNotificatorTaskRegistratorReturnValue = adapterMock
113113
adapterMock.enumerateItemsForWithPageTokenReturnValue = Promise(itemList)

CryptomatorFileProviderTests/Middleware/TaskExecutor/ItemEnumerationTaskTests.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class ItemEnumerationTaskTests: CloudTaskExecutorTestCase {
300300
XCTAssertEqual(1, self.itemEnumerationTaskManagerMock.removedTaskRecords.count)
301301
XCTAssert(self.itemEnumerationTaskManagerMock.removedTaskRecords.contains(where: { $0 == enumerationTaskRecord }))
302302
self.cloudProviderMock.files["/File 1"] = nil
303-
self.cloudProviderMock.files["/NewFileFromCloud"] = "NewFileFromCloud content".data(using: .utf8)!
303+
self.cloudProviderMock.files["/NewFileFromCloud"] = Data("NewFileFromCloud content".utf8)
304304
let enumerationTaskRecord = ItemEnumerationTaskRecord(correspondingItem: rootItemMetadata.id!, pageToken: nil)
305305
let secondEnumerationTask = ItemEnumerationTask(taskRecord: enumerationTaskRecord, itemMetadata: rootItemMetadata)
306306
return taskExecutor.execute(task: secondEnumerationTask)
@@ -418,9 +418,10 @@ class ItemEnumerationTaskTests: CloudTaskExecutorTestCase {
418418
XCTAssertEqual(2, fileProviderItemList.items.count)
419419
// Check that a next page exists
420420
XCTAssertNotNil(fileProviderItemList.nextPageToken)
421-
guard let tokenData = fileProviderItemList.nextPageToken, let nextPageToken = String(data: tokenData.rawValue, encoding: .utf8) else {
421+
guard let tokenData = fileProviderItemList.nextPageToken else {
422422
throw NSError(domain: "ItemEnumerationTaskExecutorTestError", code: -100, userInfo: ["localizedDescription": "No page token"])
423423
}
424+
let nextPageToken = String(decoding: tokenData.rawValue, as: UTF8.self)
424425
// Check that the (possible) old items have been marked as maybe outdated
425426
XCTAssert(self.metadataManagerMock.cachedMetadata[2]?.isMaybeOutdated ?? false)
426427
XCTAssert(self.metadataManagerMock.cachedMetadata[3]?.isMaybeOutdated ?? false)

0 commit comments

Comments
 (0)