diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index ad14dc6..b96ff3e 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -1463,7 +1463,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nset -xe\nrm -rf ${BUILT_PRODUCTS_DIR}/passKit.framework/Frameworks\nfind -L ${BUILT_PRODUCTS_DIR}/OneTimePassword_*.framework -type d -name \"Frameworks\" | xargs rm -rf\nfind -L ${BUILT_PRODUCTS_DIR}/passAutoFillExtension.appex -type d -name \"Frameworks\" | xargs rm -rf\nfind -L ${BUILT_PRODUCTS_DIR}/passShortcuts.appex -type d -name \"Frameworks\" | xargs rm -rf\n\n"; + shellScript = "set -xe\n\nfind -L \"${BUILT_PRODUCTS_DIR}\" -type d -path \"*.appex/Frameworks\" -o -path \"*.framework/Frameworks\" -maxdepth 2 | xargs rm -rf\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/pass/Controllers/AboutRepositoryTableViewController.swift b/pass/Controllers/AboutRepositoryTableViewController.swift index 149d918..88636eb 100644 --- a/pass/Controllers/AboutRepositoryTableViewController.swift +++ b/pass/Controllers/AboutRepositoryTableViewController.swift @@ -100,7 +100,7 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController { if let numberOfCommits = passwordStore.numberOfCommits { return String(numberOfCommits) } - return AboutRepositoryTableViewController.VALUE_NOT_AVAILABLE + return Self.VALUE_NOT_AVAILABLE } @objc diff --git a/pass/Controllers/AdvancedSettingsTableViewController.swift b/pass/Controllers/AdvancedSettingsTableViewController.swift index 513747e..30f1ef5 100644 --- a/pass/Controllers/AdvancedSettingsTableViewController.swift +++ b/pass/Controllers/AdvancedSettingsTableViewController.swift @@ -21,7 +21,7 @@ class AdvancedSettingsTableViewController: UITableViewController { let uiSwitch = UISwitch() uiSwitch.onTintColor = Colors.systemBlue uiSwitch.sizeToFit() - uiSwitch.addTarget(self, action: #selector(encryptInASCIIArmoredAction(_:)), for: UIControl.Event.valueChanged) + uiSwitch.addTarget(self, action: #selector(encryptInASCIIArmoredAction), for: UIControl.Event.valueChanged) return uiSwitch }() diff --git a/pass/Controllers/GeneralSettingsTableViewController.swift b/pass/Controllers/GeneralSettingsTableViewController.swift index 4a944b2..46b7203 100644 --- a/pass/Controllers/GeneralSettingsTableViewController.swift +++ b/pass/Controllers/GeneralSettingsTableViewController.swift @@ -16,7 +16,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController { let uiSwitch = UISwitch() uiSwitch.onTintColor = Colors.systemBlue uiSwitch.sizeToFit() - uiSwitch.addTarget(self, action: #selector(hideUnknownSwitchAction(_:)), for: UIControl.Event.valueChanged) + uiSwitch.addTarget(self, action: #selector(hideUnknownSwitchAction), for: UIControl.Event.valueChanged) return uiSwitch }() @@ -24,7 +24,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController { let uiSwitch = UISwitch() uiSwitch.onTintColor = Colors.systemBlue uiSwitch.sizeToFit() - uiSwitch.addTarget(self, action: #selector(hideOTPSwitchAction(_:)), for: UIControl.Event.valueChanged) + uiSwitch.addTarget(self, action: #selector(hideOTPSwitchAction), for: UIControl.Event.valueChanged) return uiSwitch }() @@ -32,7 +32,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController { let uiSwitch = UISwitch() uiSwitch.onTintColor = Colors.systemBlue uiSwitch.sizeToFit() - uiSwitch.addTarget(self, action: #selector(autoCopyOTPSwitchAction(_:)), for: UIControl.Event.valueChanged) + uiSwitch.addTarget(self, action: #selector(autoCopyOTPSwitchAction), for: UIControl.Event.valueChanged) return uiSwitch }() @@ -40,7 +40,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController { let uiSwitch = UISwitch() uiSwitch.onTintColor = Colors.systemBlue uiSwitch.sizeToFit() - uiSwitch.addTarget(self, action: #selector(rememberPGPPassphraseSwitchAction(_:)), for: UIControl.Event.valueChanged) + uiSwitch.addTarget(self, action: #selector(rememberPGPPassphraseSwitchAction), for: UIControl.Event.valueChanged) uiSwitch.isOn = Defaults.isRememberPGPPassphraseOn return uiSwitch }() @@ -49,7 +49,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController { let uiSwitch = UISwitch() uiSwitch.onTintColor = Colors.systemBlue uiSwitch.sizeToFit() - uiSwitch.addTarget(self, action: #selector(rememberGitCredentialPassphraseSwitchAction(_:)), for: UIControl.Event.valueChanged) + uiSwitch.addTarget(self, action: #selector(rememberGitCredentialPassphraseSwitchAction), for: UIControl.Event.valueChanged) uiSwitch.isOn = Defaults.isRememberGitCredentialPassphraseOn return uiSwitch }() @@ -58,7 +58,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController { let uiSwitch = UISwitch() uiSwitch.onTintColor = Colors.systemBlue uiSwitch.sizeToFit() - uiSwitch.addTarget(self, action: #selector(enableGPGIDSwitchAction(_:)), for: UIControl.Event.valueChanged) + uiSwitch.addTarget(self, action: #selector(enableGPGIDSwitchAction), for: UIControl.Event.valueChanged) uiSwitch.isOn = Defaults.isEnableGPGIDOn return uiSwitch }() @@ -67,7 +67,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController { let uiSwitch = UISwitch() uiSwitch.onTintColor = Colors.systemBlue uiSwitch.sizeToFit() - uiSwitch.addTarget(self, action: #selector(showFolderSwitchAction(_:)), for: UIControl.Event.valueChanged) + uiSwitch.addTarget(self, action: #selector(showFolderSwitchAction), for: UIControl.Event.valueChanged) uiSwitch.isOn = Defaults.isShowFolderOn return uiSwitch }() @@ -76,7 +76,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController { let uiSwitch = UISwitch() uiSwitch.onTintColor = Colors.systemBlue uiSwitch.sizeToFit() - uiSwitch.addTarget(self, action: #selector(hidePasswordImagesSwitchAction(_:)), for: UIControl.Event.valueChanged) + uiSwitch.addTarget(self, action: #selector(hidePasswordImagesSwitchAction), for: UIControl.Event.valueChanged) uiSwitch.isOn = Defaults.isHidePasswordImagesOn return uiSwitch }() diff --git a/pass/Controllers/OpenSourceComponentsTableViewController.swift b/pass/Controllers/OpenSourceComponentsTableViewController.swift index 2720eef..572e1a9 100644 --- a/pass/Controllers/OpenSourceComponentsTableViewController.swift +++ b/pass/Controllers/OpenSourceComponentsTableViewController.swift @@ -68,7 +68,7 @@ class OpenSourceComponentsTableViewController: BasicStaticTableViewController { .action: "link", .link: item[1], .accessoryType: UITableViewCell.AccessoryType.detailDisclosureButton, - .detailDisclosureAction: #selector(actOnDetailDisclosureButton(_:)), + .detailDisclosureAction: #selector(actOnDetailDisclosureButton), .detailDisclosureData: item[2], ] ) diff --git a/pass/Controllers/PasswordDetailTableViewController.swift b/pass/Controllers/PasswordDetailTableViewController.swift index 148aa3a..e332c58 100644 --- a/pass/Controllers/PasswordDetailTableViewController.swift +++ b/pass/Controllers/PasswordDetailTableViewController.swift @@ -21,7 +21,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni private let keychain = AppKeychain.shared private lazy var editUIBarButtonItem: UIBarButtonItem = { - let uiBarButtonItem = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(pressEdit(_:))) + let uiBarButtonItem = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(pressEdit)) return uiBarButtonItem }() @@ -47,7 +47,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni tableView.register(UINib(nibName: "LabelTableViewCell", bundle: nil), forCellReuseIdentifier: "labelCell") tableView.register(UINib(nibName: "PasswordDetailTitleTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordDetailTitleTableViewCell") - let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PasswordDetailTableViewController.tapMenu(recognizer:))) + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapMenu)) tapGesture.cancelsTouchesInView = false tableView.addGestureRecognizer(tapGesture) tapGesture.delegate = self @@ -326,10 +326,10 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni if let tappedCell = tableView.cellForRow(at: tapIndexPath) as? LabelTableViewCell { tappedCell.becomeFirstResponder() let menuController = UIMenuController.shared - let revealItem = UIMenuItem(title: "Reveal".localize(), action: #selector(LabelTableViewCell.revealPassword(_:))) - let concealItem = UIMenuItem(title: "Conceal".localize(), action: #selector(LabelTableViewCell.concealPassword(_:))) - let nextHOTPItem = UIMenuItem(title: "NextPassword".localize(), action: #selector(LabelTableViewCell.getNextHOTP(_:))) - let openURLItem = UIMenuItem(title: "CopyAndOpen".localize(), action: #selector(LabelTableViewCell.openLink(_:))) + let revealItem = UIMenuItem(title: "Reveal".localize(), action: #selector(LabelTableViewCell.revealPassword)) + let concealItem = UIMenuItem(title: "Conceal".localize(), action: #selector(LabelTableViewCell.concealPassword)) + let nextHOTPItem = UIMenuItem(title: "NextPassword".localize(), action: #selector(LabelTableViewCell.getNextHOTP)) + let openURLItem = UIMenuItem(title: "CopyAndOpen".localize(), action: #selector(LabelTableViewCell.openLink)) menuController.menuItems = [revealItem, concealItem, nextHOTPItem, openURLItem] menuController.setTargetRect(tappedCell.contentLabel.frame, in: tappedCell.contentLabel.superview!) menuController.setMenuVisible(true, animated: true) @@ -490,7 +490,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni let section = tableData[indexPath.section] switch section.type { case .addition, .main: - return action == #selector(UIResponderStandardEditActions.copy(_:)) + return action == #selector(UIResponderStandardEditActions.copy) default: return false } diff --git a/pass/Controllers/PasswordNavigationViewController.swift b/pass/Controllers/PasswordNavigationViewController.swift index 36e43c0..231821a 100644 --- a/pass/Controllers/PasswordNavigationViewController.swift +++ b/pass/Controllers/PasswordNavigationViewController.swift @@ -56,10 +56,10 @@ class PasswordNavigationViewController: UIViewController { let addPasswordButton = UIButton(type: .system) let plusImage = UIImage(systemName: "plus.circle", withConfiguration: UIImage.SymbolConfiguration(weight: .regular)) addPasswordButton.setImage(plusImage, for: .normal) - addPasswordButton.addTarget(self, action: #selector(self.addPasswordAction(_:)), for: .touchDown) + addPasswordButton.addTarget(self, action: #selector(self.addPasswordAction), for: .touchDown) addPasswordUIBarButtonItem.customView = addPasswordButton } else { - addPasswordUIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(self.addPasswordAction(_:))) + addPasswordUIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(self.addPasswordAction)) } return addPasswordUIBarButtonItem }() diff --git a/pass/Controllers/SettingsTableViewController.swift b/pass/Controllers/SettingsTableViewController.swift index 38574e6..8322d8f 100644 --- a/pass/Controllers/SettingsTableViewController.swift +++ b/pass/Controllers/SettingsTableViewController.swift @@ -66,7 +66,7 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele override func viewDidLoad() { super.viewDidLoad() - NotificationCenter.default.addObserver(self, selector: #selector(SettingsTableViewController.actOnPasswordStoreErasedNotification), name: .passwordStoreErased, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(actOnPasswordStoreErasedNotification), name: .passwordStoreErased, object: nil) passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults.gitURL.host setPGPKeyTableViewCellDetailText() setPasscodeLockCell() @@ -243,12 +243,12 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele setPasscodeLockAlert?.addTextField { textField -> Void in textField.placeholder = "Passcode".localize() textField.isSecureTextEntry = true - textField.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged) + textField.addTarget(self, action: #selector(self.alertTextFieldDidChange), for: UIControl.Event.editingChanged) } setPasscodeLockAlert?.addTextField { textField -> Void in textField.placeholder = "PasswordConfirmation".localize() textField.isSecureTextEntry = true - textField.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: UIControl.Event.editingChanged) + textField.addTarget(self, action: #selector(self.alertTextFieldDidChange), for: UIControl.Event.editingChanged) } // save action diff --git a/pass/Views/LabelTableViewCell.swift b/pass/Views/LabelTableViewCell.swift index b9d4113..7bb74d0 100644 --- a/pass/Views/LabelTableViewCell.swift +++ b/pass/Views/LabelTableViewCell.swift @@ -80,16 +80,16 @@ class LabelTableViewCell: UITableViewCell { switch type { case .password: if isReveal { - return action == #selector(copy(_:)) || action == #selector(concealPassword(_:)) + return action == #selector(copy(_:)) || action == #selector(concealPassword) } - return action == #selector(copy(_:)) || action == #selector(revealPassword(_:)) + return action == #selector(copy(_:)) || action == #selector(revealPassword) case .URL: - return action == #selector(copy(_:)) || action == #selector(openLink(_:)) + return action == #selector(copy(_:)) || action == #selector(openLink) case .HOTP: if isReveal { - return action == #selector(copy(_:)) || action == #selector(concealPassword(_:)) || action == #selector(getNextHOTP(_:)) + return action == #selector(copy(_:)) || action == #selector(concealPassword) || action == #selector(getNextHOTP) } - return action == #selector(copy(_:)) || action == #selector(revealPassword(_:)) || action == #selector(getNextHOTP(_:)) + return action == #selector(copy(_:)) || action == #selector(revealPassword) || action == #selector(getNextHOTP) default: return action == #selector(copy(_:)) } diff --git a/pass/Views/UICodeHighlightingLabel.swift b/pass/Views/UICodeHighlightingLabel.swift index 439e1a0..208168c 100644 --- a/pass/Views/UICodeHighlightingLabel.swift +++ b/pass/Views/UICodeHighlightingLabel.swift @@ -31,13 +31,13 @@ class UICodeHighlightingLabel: UILocalizedLabel { let formattedText = text.splitByNewline() .map { line -> NSAttributedString in if line.starts(with: " ") { - return NSAttributedString(string: line, attributes: UICodeHighlightingLabel.CODE_ATTRIBUTES) + return NSAttributedString(string: line, attributes: Self.CODE_ATTRIBUTES) } return NSAttributedString(string: line) } .reduce(into: NSMutableAttributedString(string: "")) { $0.append($1) - $0.append(UICodeHighlightingLabel.ATTRIBUTED_NEWLINE) + $0.append(Self.ATTRIBUTED_NEWLINE) } formattedText.deleteCharacters(in: NSRange(location: formattedText.length - 1, length: 1)) return formattedText diff --git a/passAutoFillExtension/Controllers/CredentialProviderViewController.swift b/passAutoFillExtension/Controllers/CredentialProviderViewController.swift index 7ad6be1..ab9af29 100644 --- a/passAutoFillExtension/Controllers/CredentialProviderViewController.swift +++ b/passAutoFillExtension/Controllers/CredentialProviderViewController.swift @@ -23,7 +23,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController { }() private lazy var passwordsTableEntries = PasswordStore.shared.fetchPasswordEntityCoreData(withDir: false) - .map(PasswordTableEntry.init(_:)) + .map(PasswordTableEntry.init) override func viewDidLoad() { super.viewDidLoad() @@ -44,7 +44,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController { self.credentialProvider.identifier = serviceIdentifiers.first let url = serviceIdentifiers.first .map(\.identifier) - .flatMap(URL.init(string:)) + .flatMap(URL.init) self.passwordsViewController.navigationItem.prompt = url?.host self.passwordsViewController.showPasswordsWithSuggestion(matching: url?.host ?? "") } diff --git a/passExtension/Controllers/ExtensionViewController.swift b/passExtension/Controllers/ExtensionViewController.swift index 92e3f07..ab814a0 100644 --- a/passExtension/Controllers/ExtensionViewController.swift +++ b/passExtension/Controllers/ExtensionViewController.swift @@ -24,7 +24,7 @@ class ExtensionViewController: UIViewController { }() private lazy var passwordsTableEntries = PasswordStore.shared.fetchPasswordEntityCoreData(withDir: false) - .map(PasswordTableEntry.init(_:)) + .map(PasswordTableEntry.init) enum Action { case findLogin, fillBrowser, unknown diff --git a/passKit/Controllers/PasscodeLockViewController.swift b/passKit/Controllers/PasscodeLockViewController.swift index c9c41d7..5282d3b 100644 --- a/passKit/Controllers/PasscodeLockViewController.swift +++ b/passKit/Controllers/PasscodeLockViewController.swift @@ -34,7 +34,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate { passcodeTextField.isSecureTextEntry = true passcodeTextField.clearButtonMode = UITextField.ViewMode.whileEditing passcodeTextField.delegate = self - passcodeTextField.addTarget(self, action: #selector(passcodeTextFieldDidChange(_:)), for: UIControl.Event.editingChanged) + passcodeTextField.addTarget(self, action: #selector(passcodeTextFieldDidChange), for: UIControl.Event.editingChanged) passcodeTextField.translatesAutoresizingMaskIntoConstraints = false view.addSubview(passcodeTextField) self.passcodeTextField = passcodeTextField @@ -46,7 +46,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate { let biometryAuthButton = UIButton(type: .custom) biometryAuthButton.setTitle("", for: .normal) biometryAuthButton.setTitleColor(Colors.systemBlue, for: .normal) - biometryAuthButton.addTarget(self, action: #selector(bioButtonPressedAction(_:)), for: .touchUpInside) + biometryAuthButton.addTarget(self, action: #selector(bioButtonPressedAction), for: .touchUpInside) biometryAuthButton.isHidden = true biometryAuthButton.translatesAutoresizingMaskIntoConstraints = false view.addSubview(biometryAuthButton) @@ -68,7 +68,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate { forgotPasscodeButton.setTitle("ForgotYourPasscode?".localize(), for: .normal) forgotPasscodeButton.titleLabel?.font = UIFont.systemFont(ofSize: UIFont.systemFontSize) forgotPasscodeButton.setTitleColor(Colors.systemBlue, for: .normal) - forgotPasscodeButton.addTarget(self, action: #selector(forgotPasscodeButtonPressedAction(_:)), for: .touchUpInside) + forgotPasscodeButton.addTarget(self, action: #selector(forgotPasscodeButtonPressedAction), for: .touchUpInside) // hide the forgotPasscodeButton if the native app is running forgotPasscodeButton.isHidden = isCancellable forgotPasscodeButton.translatesAutoresizingMaskIntoConstraints = false diff --git a/passKit/Models/PasscodeLock.swift b/passKit/Models/PasscodeLock.swift index e914499..6d8f69d 100644 --- a/passKit/Models/PasscodeLock.swift +++ b/passKit/Models/PasscodeLock.swift @@ -9,10 +9,10 @@ public class PasscodeLock { public static let shared = PasscodeLock() - private static let identifier = Globals.bundleIdentifier + "passcode" + private let identifier = Globals.bundleIdentifier + "passcode" private var passcode: String? { - AppKeychain.shared.get(for: PasscodeLock.identifier) + AppKeychain.shared.get(for: identifier) } /// Constructor used to migrate passcode from SharedDefaults to Keychain @@ -28,7 +28,7 @@ public class PasscodeLock { } public func save(passcode: String) { - AppKeychain.shared.add(string: passcode, for: PasscodeLock.identifier) + AppKeychain.shared.add(string: passcode, for: identifier) } public func check(passcode: String) -> Bool { @@ -36,6 +36,6 @@ public class PasscodeLock { } public func delete() { - AppKeychain.shared.removeContent(for: PasscodeLock.identifier) + AppKeychain.shared.removeContent(for: identifier) } } diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index c767e4c..9059e8a 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -380,7 +380,7 @@ public class PasswordStore { if Date().timeIntervalSince(lastCommitDate) <= 60 { return "JustNow".localize() } - return PasswordStore.dateFormatter.string(from: lastCommitDate) + return Self.dateFormatter.string(from: lastCommitDate) } public func updateRemoteRepo() {} diff --git a/passKit/Models/PasswordTableEntry.swift b/passKit/Models/PasswordTableEntry.swift index 3828823..c43b2ab 100644 --- a/passKit/Models/PasswordTableEntry.swift +++ b/passKit/Models/PasswordTableEntry.swift @@ -24,7 +24,7 @@ public class PasswordTableEntry: NSObject { } public func matches(_ searchText: String) -> Bool { - PasswordTableEntry.match(nameWithCategory: passwordEntity.nameWithCategory, searchText: searchText) + Self.match(nameWithCategory: passwordEntity.nameWithCategory, searchText: searchText) } public static func match(nameWithCategory: String, searchText: String) -> Bool { diff --git a/passKit/Parser/Parser.swift b/passKit/Parser/Parser.swift index 208f514..933bf13 100644 --- a/passKit/Parser/Parser.swift +++ b/passKit/Parser/Parser.swift @@ -29,7 +29,7 @@ class Parser { while lineNumber < purgedAdditionalLines.count { let line = purgedAdditionalLines[lineNumber] lineNumber += 1 - var (key, value) = Parser.getKeyValuePair(from: line) + var (key, value) = Self.getKeyValuePair(from: line) if key == nil { unknownIndex += 1 key = Constants.unknown(unknownIndex) diff --git a/passKitTests/Helpers/KeyFileManagerTest.swift b/passKitTests/Helpers/KeyFileManagerTest.swift index 18dc830..4d38e31 100644 --- a/passKitTests/Helpers/KeyFileManagerTest.swift +++ b/passKitTests/Helpers/KeyFileManagerTest.swift @@ -15,33 +15,33 @@ class KeyFileManagerTest: XCTestCase { private static let keyFileManager = KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: filePath) { _, _ in } override func tearDown() { - try? FileManager.default.removeItem(atPath: KeyFileManagerTest.filePath) + try? FileManager.default.removeItem(atPath: Self.filePath) super.tearDown() } func testImportKeyFromFileSharing() throws { let fileContent = "content".data(using: .ascii) var storage: [String: String] = [:] - let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: KeyFileManagerTest.filePath) { storage[$1] = $0 } + let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 } - FileManager.default.createFile(atPath: KeyFileManagerTest.filePath, contents: fileContent, attributes: nil) + FileManager.default.createFile(atPath: Self.filePath, contents: fileContent, attributes: nil) try keyFileManager.importKeyFromFileSharing() - XCTAssertFalse(FileManager.default.fileExists(atPath: KeyFileManagerTest.filePath)) + XCTAssertFalse(FileManager.default.fileExists(atPath: Self.filePath)) XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], "content") } func testErrorReadingFile() throws { - XCTAssertThrowsError(try KeyFileManagerTest.keyFileManager.importKeyFromFileSharing()) + XCTAssertThrowsError(try Self.keyFileManager.importKeyFromFileSharing()) } func testImportKeyFromUrl() throws { let fileContent = "content".data(using: .ascii) - let url = URL(fileURLWithPath: KeyFileManagerTest.filePath) + let url = URL(fileURLWithPath: Self.filePath) var storage: [String: String] = [:] - let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: KeyFileManagerTest.filePath) { storage[$1] = $0 } + let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 } - FileManager.default.createFile(atPath: KeyFileManagerTest.filePath, contents: fileContent, attributes: nil) + FileManager.default.createFile(atPath: Self.filePath, contents: fileContent, attributes: nil) try keyFileManager.importKey(from: url) XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], "content") @@ -50,7 +50,7 @@ class KeyFileManagerTest: XCTestCase { func testImportKeyFromString() throws { let string = "content" var storage: [String: String] = [:] - let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: KeyFileManagerTest.filePath) { storage[$1] = $0 } + let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 } try keyFileManager.importKey(from: string) @@ -58,18 +58,18 @@ class KeyFileManagerTest: XCTestCase { } func testImportKeyFromNonAsciiString() throws { - XCTAssertThrowsError(try KeyFileManagerTest.keyFileManager.importKey(from: "≠")) { + XCTAssertThrowsError(try Self.keyFileManager.importKey(from: "≠")) { XCTAssertEqual($0 as! AppError, AppError.encoding) } } func testFileExists() { - FileManager.default.createFile(atPath: KeyFileManagerTest.filePath, contents: nil, attributes: nil) + FileManager.default.createFile(atPath: Self.filePath, contents: nil, attributes: nil) - XCTAssertTrue(KeyFileManagerTest.keyFileManager.doesKeyFileExist()) + XCTAssertTrue(Self.keyFileManager.doesKeyFileExist()) } func testFileDoesNotExist() { - XCTAssertFalse(KeyFileManagerTest.keyFileManager.doesKeyFileExist()) + XCTAssertFalse(Self.keyFileManager.doesKeyFileExist()) } }