From cdedff0d4d22cb97cc71ce8e69f731c8cd6f318e Mon Sep 17 00:00:00 2001 From: Danny Moesch Date: Tue, 28 Dec 2021 02:57:11 +0100 Subject: [PATCH] Use SwiftFormat version 0.49.x and enable some new rules (#527) --- .swiftformat | 19 ++++++++++++++ pass.xcodeproj/project.pbxproj | 16 ++++++------ pass/AppDelegate.swift | 26 +++++++++---------- .../AdvancedSettingsTableViewController.swift | 4 +-- ...epositorySettingsTableViewController.swift | 18 ++++++------- ...PGPKeyArmorImportTableViewController.swift | 4 +-- .../PGPKeyFIleImportTableViewController.swift | 4 +-- ... PGPKeyURLImportTableViewController.swift} | 18 ++++++------- .../PasswordDetailTableViewController.swift | 8 +++--- .../PasswordEditorTableViewController.swift | 4 +-- .../PasswordNavigationViewController.swift | 4 +-- ...SSHKeyArmorImportTableViewController.swift | 2 +- .../SSHKeyFileImportTableViewController.swift | 2 +- ...SSHKeyURLImportTableViewController..swift} | 8 +++--- .../SettingsTableViewController.swift | 18 ++++++------- .../CredentialProviderViewController.swift | 4 +-- .../Controllers/PasswordsViewController.swift | 4 +-- .../Controllers/ExtensionViewController.swift | 4 +-- .../PasscodeLockViewController.swift | 2 +- passKit/Crypto/GopenPGPInterface.swift | 6 ++--- passKit/Crypto/PGPAgent.swift | 8 +++--- passKit/Helpers/CryptographicKeys.swift | 4 +-- passKit/Helpers/FileManagerExtension.swift | 8 ++++-- passKit/Helpers/KeyFileManager.swift | 6 ++--- passKit/Models/GitCredential.swift | 2 +- passKit/Models/Password.swift | 4 +-- passKit/Models/PasswordStore.swift | 24 ++++++++--------- passKitTests/Crypto/PGPAgentTest.swift | 10 +++---- passKitTests/Helpers/KeyFileManagerTest.swift | 16 ++++++------ passKitTests/Models/PasswordStoreTest.swift | 4 +-- passKitTests/Models/PasswordTest.swift | 2 +- scripts/swiftformat.sh | 2 +- 32 files changed, 139 insertions(+), 126 deletions(-) rename pass/Controllers/{PGPKeyUrlImportTableViewController.swift => PGPKeyURLImportTableViewController.swift} (81%) rename pass/Controllers/{SSHKeyUrlImportTableViewController.swift => SSHKeyURLImportTableViewController..swift} (90%) diff --git a/.swiftformat b/.swiftformat index 90e7820..f3feea4 100644 --- a/.swiftformat +++ b/.swiftformat @@ -10,12 +10,16 @@ ## Enabled rules --rules \ + acronyms, \ andOperator, \ anyObjectProtocol, \ + assertionFailures, \ blankLinesAroundMark, \ blankLinesAtEndOfScope, \ blankLinesAtStartOfScope, \ +# blankLinesBetweenImports, \ blankLinesBetweenScopes, \ + blockComments, \ braces, \ consecutiveBlankLines, \ consecutiveSpaces, \ @@ -36,9 +40,11 @@ # markTypes, \ numberFormatting, \ # organizeDeclarations, \ + preferDouble, \ preferKeyPath, \ redundantBackticks, \ redundantBreak, \ + redundantClosure, \ redundantExtensionACL, \ redundantFileprivate, \ redundantGet, \ @@ -81,6 +87,7 @@ wrap, \ wrapArguments, \ wrapAttributes, \ + wrapConditionalBodies, \ # wrapEnumCases, \ # wrapMultilineStatementBraces, \ # wrapSwitchCases, \ @@ -88,6 +95,10 @@ ## Formatting options +### Acronyms to auto-capitalize. Defaults to "ID,URL,UUID". + +--acronyms "GPG, HTTP, HTTPS, ID, PGP, SSH, URI, URL, UUID" + ### Use allman indentation style: "true" or "false" (default) --allman false @@ -272,6 +283,14 @@ --wrapreturntype preserve +### Wrap ternary operators: "default", "before-operators" + +--wrapternary before-operators + +### Wrap typealiases: "before-first", "after-first", "preserve" + +--wraptypealiases preserve + ### Xcode indent guard/enum: "enabled" or "disabled" (default) --xcodeindentation disabled diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index 5942bb1..79996d2 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -180,14 +180,14 @@ DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914941E434301007FF592 /* LabelTableViewCell.swift */; }; DC4914991E434600007FF592 /* PasswordDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */; }; DC5F385B1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC5F385A1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift */; }; - DC8963C01E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8963BF1E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift */; }; + DC8963C01E38EEB900828B09 /* SSHKeyURLImportTableViewController..swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8963BF1E38EEB900828B09 /* SSHKeyURLImportTableViewController..swift */; }; DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC917BD61E2E8231000FDF54 /* AppDelegate.swift */; }; DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDA1E2E8231000FDF54 /* Main.storyboard */; }; DC917BDE1E2E8231000FDF54 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDD1E2E8231000FDF54 /* Assets.xcassets */; }; DC917BE11E2E8231000FDF54 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDF1E2E8231000FDF54 /* LaunchScreen.storyboard */; }; DC962CDF1E4B62C10033B5D8 /* AboutTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC962CDE1E4B62C10033B5D8 /* AboutTableViewController.swift */; }; DCA0499A1E335CC800522E8F /* GitRepositorySettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA049991E335CC800522E8F /* GitRepositorySettingsTableViewController.swift */; }; - DCA0499C1E3362F400522E8F /* PGPKeyUrlImportTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA0499B1E3362F400522E8F /* PGPKeyUrlImportTableViewController.swift */; }; + DCA0499C1E3362F400522E8F /* PGPKeyURLImportTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA0499B1E3362F400522E8F /* PGPKeyURLImportTableViewController.swift */; }; DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */; }; DCC441521E8F6C06008A90C4 /* RawPasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC441511E8F6C06008A90C4 /* RawPasswordViewController.swift */; }; DCC441541E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC441531E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift */; }; @@ -463,7 +463,7 @@ DC4914941E434301007FF592 /* LabelTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelTableViewCell.swift; sourceTree = ""; }; DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailTableViewController.swift; sourceTree = ""; }; DC5F385A1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGPKeyArmorImportTableViewController.swift; sourceTree = ""; }; - DC8963BF1E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSHKeyUrlImportTableViewController.swift; sourceTree = ""; }; + DC8963BF1E38EEB900828B09 /* SSHKeyURLImportTableViewController..swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSHKeyURLImportTableViewController..swift; sourceTree = ""; }; DC917BD31E2E8231000FDF54 /* Pass.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Pass.app; sourceTree = BUILT_PRODUCTS_DIR; }; DC917BD61E2E8231000FDF54 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; DC917BDB1E2E8231000FDF54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -472,7 +472,7 @@ DC917BE21E2E8231000FDF54 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DC962CDE1E4B62C10033B5D8 /* AboutTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutTableViewController.swift; sourceTree = ""; }; DCA049991E335CC800522E8F /* GitRepositorySettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitRepositorySettingsTableViewController.swift; sourceTree = ""; }; - DCA0499B1E3362F400522E8F /* PGPKeyUrlImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGPKeyUrlImportTableViewController.swift; sourceTree = ""; }; + DCA0499B1E3362F400522E8F /* PGPKeyURLImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGPKeyURLImportTableViewController.swift; sourceTree = ""; }; DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsTableViewController.swift; sourceTree = ""; }; DCC441511E8F6C06008A90C4 /* RawPasswordViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawPasswordViewController.swift; sourceTree = ""; }; DCC441531E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSHKeyArmorImportTableViewController.swift; sourceTree = ""; }; @@ -916,7 +916,7 @@ DC5F385A1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift */, 302269B223E634B000F843A3 /* PGPKeyFIleImportTableViewController.swift */, 3066AD6723EE0D6500F65535 /* PGPKeyImporter.swift */, - DCA0499B1E3362F400522E8F /* PGPKeyUrlImportTableViewController.swift */, + DCA0499B1E3362F400522E8F /* PGPKeyURLImportTableViewController.swift */, A2A7813E1E97DBD9001311F5 /* QRScannerController.swift */, DCC441511E8F6C06008A90C4 /* RawPasswordViewController.swift */, DCD3C65D1EFB9BB400CBE842 /* SettingsSplitViewController.swift */, @@ -924,7 +924,7 @@ DC037CA91E4B8EAE00609409 /* SpecialThanksTableViewController.swift */, DCC441531E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift */, 30650E7023F82AF8005CCD5E /* SSHKeyFileImportTableViewController.swift */, - DC8963BF1E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift */, + DC8963BF1E38EEB900828B09 /* SSHKeyURLImportTableViewController..swift */, ); path = Controllers; sourceTree = ""; @@ -1604,7 +1604,7 @@ DCC441541E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift in Sources */, 306D970E24091CDD006C0E2E /* SwitchTableViewCell.swift in Sources */, A2A61C201EEFABAD00CFE063 /* UtilsExtension.swift in Sources */, - DC8963C01E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift in Sources */, + DC8963C01E38EEB900828B09 /* SSHKeyURLImportTableViewController..swift in Sources */, 9AFC87F025B514AD008D6060 /* PasswordDecryptor.swift in Sources */, 3066AD6823EE0D6500F65535 /* PGPKeyImporter.swift in Sources */, 9AFC87E225B3B5C6008D6060 /* PasswordNavigationDataSource.swift in Sources */, @@ -1612,7 +1612,7 @@ DC193FFA1E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift in Sources */, DCFB77AB1E503729008DE471 /* ContentProvider.swift in Sources */, 9AFC880025B51EC3008D6060 /* PasswordEncryptor.swift in Sources */, - DCA0499C1E3362F400522E8F /* PGPKeyUrlImportTableViewController.swift in Sources */, + DCA0499C1E3362F400522E8F /* PGPKeyURLImportTableViewController.swift in Sources */, DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */, DC5F385B1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift in Sources */, DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */, diff --git a/pass/AppDelegate.swift b/pass/AppDelegate.swift index d7ff466..4412ada 100644 --- a/pass/AppDelegate.swift +++ b/pass/AppDelegate.swift @@ -111,12 +111,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: - Core Data stack lazy var persistentContainer: NSPersistentContainer = { - /* - The persistent container for the application. This implementation - creates and returns a container, having loaded the store for the - application to it. This property is optional since there are legitimate - error conditions that could cause the creation of the store to fail. - */ + // The persistent container for the application. This implementation + // creates and returns a container, having loaded the store for the + // application to it. This property is optional since there are legitimate + // error conditions that could cause the creation of the store to fail. let modelURL = Bundle(identifier: Globals.passKitBundleIdentifier)!.url(forResource: "pass", withExtension: "momd")! let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL) let container = NSPersistentContainer(name: "pass", managedObjectModel: managedObjectModel!) @@ -129,14 +127,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - /* - Typical reasons for an error here include: - * The parent directory does not exist, cannot be created, or disallows writing. - * The persistent store is not accessible, due to permissions or data protection when the device is locked. - * The device is out of space. - * The store could not be migrated to the current model version. - Check the error message to determine what the actual problem was. - */ + // Typical reasons for an error here include: + // + // * The parent directory does not exist, cannot be created, or disallows writing. + // * The persistent store is not accessible, due to permissions or data protection when the device is locked. + // * The device is out of space. + // * The store could not be migrated to the current model version. + // + // Check the error message to determine what the actual problem was. fatalError("UnresolvedError".localize("\(error), \(error.userInfo)")) } } diff --git a/pass/Controllers/AdvancedSettingsTableViewController.swift b/pass/Controllers/AdvancedSettingsTableViewController.swift index 677118f..0c055f5 100644 --- a/pass/Controllers/AdvancedSettingsTableViewController.swift +++ b/pass/Controllers/AdvancedSettingsTableViewController.swift @@ -49,7 +49,7 @@ class AdvancedSettingsTableViewController: UITableViewController { if tableView.cellForRow(at: indexPath) == eraseDataTableViewCell { let alert = UIAlertController(title: "ErasePasswordStoreData?".localize(), message: "EraseExplanation.".localize(), preferredStyle: UIAlertController.Style.alert) alert.addAction( - UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ -> Void in + UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in SVProgressHUD.show(withStatus: "Erasing...".localize()) self.passwordStore.erase() self.navigationController!.popViewController(animated: true) @@ -62,7 +62,7 @@ class AdvancedSettingsTableViewController: UITableViewController { } else if tableView.cellForRow(at: indexPath) == discardChangesTableViewCell { let alert = UIAlertController(title: "DiscardAllLocalChanges?".localize(), message: "DiscardExplanation.".localize(), preferredStyle: UIAlertController.Style.alert) alert.addAction( - UIAlertAction(title: "DiscardAllLocalChanges".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ -> Void in + UIAlertAction(title: "DiscardAllLocalChanges".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in SVProgressHUD.show(withStatus: "Resetting...".localize()) do { let numberDiscarded = try self.passwordStore.reset() diff --git a/pass/Controllers/GitRepositorySettingsTableViewController.swift b/pass/Controllers/GitRepositorySettingsTableViewController.swift index 876ed50..9219d8d 100644 --- a/pass/Controllers/GitRepositorySettingsTableViewController.swift +++ b/pass/Controllers/GitRepositorySettingsTableViewController.swift @@ -41,7 +41,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA } } - private var gitUrl: URL { + private var gitURL: URL { get { Defaults.gitURL } set { Defaults.gitURL = newValue } } @@ -60,7 +60,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA override func viewDidLoad() { super.viewDidLoad() - gitURLTextField.text = gitUrl.absoluteString + gitURLTextField.text = gitURL.absoluteString usernameTextField.text = gitUsername branchNameTextField.text = gitBranchName sshLabel = authSSHKeyCell.subviews[0].subviews[0] as? UILabel @@ -70,7 +70,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // Grey out ssh option if ssh_key is not present. - sshLabel?.isEnabled = keychain.contains(key: SshKey.PRIVATE.getKeychainKey()) + sshLabel?.isEnabled = keychain.contains(key: SSHKey.PRIVATE.getKeychainKey()) updateAuthenticationMethodCheckView(for: gitAuthenticationMethod) } @@ -95,7 +95,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA if cell == authPasswordCell { gitAuthenticationMethod = .password } else if cell == authSSHKeyCell { - if !keychain.contains(key: SshKey.PRIVATE.getKeychainKey()) { + if !keychain.contains(key: SSHKey.PRIVATE.getKeychainKey()) { Utils.alert(title: "CannotSelectSshKey".localize(), message: "PleaseSetupSshKeyFirst.".localize(), controller: self) gitAuthenticationMethod = .password } else { @@ -146,7 +146,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA } } - gitUrl = gitURL + self.gitURL = gitURL gitBranchName = branchName.trimmed gitUsername = (gitURL.user ?? usernameTextField.text ?? "git").trimmed @@ -186,7 +186,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA let options = self.gitCredential.getCredentialOptions(passwordProvider: self.present) try self.passwordStore.cloneRepository( - remoteRepoURL: self.gitUrl, + remoteRepoURL: self.gitURL, branchName: self.gitBranchName, options: options, transferProgressBlock: transferProgressBlock, @@ -278,7 +278,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA private func showSSHKeyActionSheet() { let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) optionMenu.addAction( - UIAlertAction(title: SSHKeyUrlImportTableViewController.menuLabel, style: .default) { _ in + UIAlertAction(title: SSHKeyURLImportTableViewController.menuLabel, style: .default) { _ in self.performSegue(withIdentifier: "setGitSSHKeyByURLSegue", sender: self) } ) @@ -354,10 +354,10 @@ extension GitRepositorySettingsTableViewController: KeyImporter { static let label = "ITunesFileSharing".localize() func isReadyToUse() -> Bool { - KeyFileManager.PrivateSsh.doesKeyFileExist() + KeyFileManager.PrivateSSH.doesKeyFileExist() } func importKeys() throws { - try KeyFileManager.PrivateSsh.importKeyFromFileSharing() + try KeyFileManager.PrivateSSH.importKeyFromFileSharing() } } diff --git a/pass/Controllers/PGPKeyArmorImportTableViewController.swift b/pass/Controllers/PGPKeyArmorImportTableViewController.swift index 8376538..ac40769 100644 --- a/pass/Controllers/PGPKeyArmorImportTableViewController.swift +++ b/pass/Controllers/PGPKeyArmorImportTableViewController.swift @@ -109,8 +109,8 @@ extension PGPKeyArmorImportTableViewController: PGPKeyImporter { } func importKeys() throws { - try KeyFileManager.PublicPgp.importKey(from: armorPublicKey ?? "") - try KeyFileManager.PrivatePgp.importKey(from: armorPrivateKey ?? "") + try KeyFileManager.PublicPGP.importKey(from: armorPublicKey ?? "") + try KeyFileManager.PrivatePGP.importKey(from: armorPrivateKey ?? "") } func saveImportedKeys() { diff --git a/pass/Controllers/PGPKeyFIleImportTableViewController.swift b/pass/Controllers/PGPKeyFIleImportTableViewController.swift index e0cf37e..6a6322a 100644 --- a/pass/Controllers/PGPKeyFIleImportTableViewController.swift +++ b/pass/Controllers/PGPKeyFIleImportTableViewController.swift @@ -88,8 +88,8 @@ extension PGPKeyFileImportTableViewController: PGPKeyImporter { guard let publicKey = publicKey, let privateKey = privateKey else { return } - try KeyFileManager.PublicPgp.importKey(from: publicKey) - try KeyFileManager.PrivatePgp.importKey(from: privateKey) + try KeyFileManager.PublicPGP.importKey(from: publicKey) + try KeyFileManager.PrivatePGP.importKey(from: privateKey) } func doAfterImport() { diff --git a/pass/Controllers/PGPKeyUrlImportTableViewController.swift b/pass/Controllers/PGPKeyURLImportTableViewController.swift similarity index 81% rename from pass/Controllers/PGPKeyUrlImportTableViewController.swift rename to pass/Controllers/PGPKeyURLImportTableViewController.swift index 18f966b..9f5e4f3 100644 --- a/pass/Controllers/PGPKeyUrlImportTableViewController.swift +++ b/pass/Controllers/PGPKeyURLImportTableViewController.swift @@ -1,5 +1,5 @@ // -// PGPKeyUrlImportTableViewController.swift +// PGPKeyURLImportTableViewController.swift // pass // // Created by Mingshen Sun on 21/1/2017. @@ -9,7 +9,7 @@ import passKit import UIKit -class PGPKeyUrlImportTableViewController: AutoCellHeightUITableViewController { +class PGPKeyURLImportTableViewController: AutoCellHeightUITableViewController { @IBOutlet var pgpPublicKeyURLTextField: UITextField! @IBOutlet var pgpPrivateKeyURLTextField: UITextField! @@ -40,21 +40,21 @@ class PGPKeyUrlImportTableViewController: AutoCellHeightUITableViewController { } } -extension PGPKeyUrlImportTableViewController: PGPKeyImporter { +extension PGPKeyURLImportTableViewController: PGPKeyImporter { static let keySource = KeySource.url static let label = "DownloadFromUrl".localize() func isReadyToUse() -> Bool { - validate(pgpKeyUrl: pgpPublicKeyURLTextField.text ?? "") - && validate(pgpKeyUrl: pgpPrivateKeyURLTextField.text ?? "") + validate(pgpKeyURL: pgpPublicKeyURLTextField.text ?? "") + && validate(pgpKeyURL: pgpPrivateKeyURLTextField.text ?? "") } func importKeys() throws { Defaults.pgpPrivateKeyURL = pgpPrivateKeyURL Defaults.pgpPublicKeyURL = pgpPublicKeyURL - try KeyFileManager.PublicPgp.importKey(from: Defaults.pgpPublicKeyURL!) - try KeyFileManager.PrivatePgp.importKey(from: Defaults.pgpPrivateKeyURL!) + try KeyFileManager.PublicPGP.importKey(from: Defaults.pgpPublicKeyURL!) + try KeyFileManager.PrivatePGP.importKey(from: Defaults.pgpPrivateKeyURL!) } func doAfterImport() { @@ -65,8 +65,8 @@ extension PGPKeyUrlImportTableViewController: PGPKeyImporter { performSegue(withIdentifier: "savePGPKeySegue", sender: self) } - private func validate(pgpKeyUrl: String) -> Bool { - guard let url = URL(string: pgpKeyUrl) else { + private func validate(pgpKeyURL: String) -> Bool { + guard let url = URL(string: pgpKeyURL) else { Utils.alert(title: "CannotSavePgpKey".localize(), message: "SetPgpKeyUrlsFirst.".localize(), controller: self) return false } diff --git a/pass/Controllers/PasswordDetailTableViewController.swift b/pass/Controllers/PasswordDetailTableViewController.swift index e332c58..3d220da 100644 --- a/pass/Controllers/PasswordDetailTableViewController.swift +++ b/pass/Controllers/PasswordDetailTableViewController.swift @@ -289,10 +289,10 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni } private func updatePasswordImage(urlString: String) { - var newUrlString = urlString + var newURLString = urlString if urlString.lowercased().hasPrefix("http://") { // try to replace http url to https url - newUrlString = urlString.replacingOccurrences( + newURLString = urlString.replacingOccurrences( of: "http://", with: "https://", options: .caseInsensitive, @@ -302,10 +302,10 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni // do nothing here } else { // if a url does not start with http or https, try to add https - newUrlString = "https://\(urlString)" + newURLString = "https://\(urlString)" } - try? FavIcon.downloadPreferred(newUrlString) { [weak self] result in + try? FavIcon.downloadPreferred(newURLString) { [weak self] result in if case let .success(image) = result { let indexPath = IndexPath(row: 0, section: 0) self?.passwordImage = image diff --git a/pass/Controllers/PasswordEditorTableViewController.swift b/pass/Controllers/PasswordEditorTableViewController.swift index 237a51f..5d5bdf6 100644 --- a/pass/Controllers/PasswordEditorTableViewController.swift +++ b/pass/Controllers/PasswordEditorTableViewController.swift @@ -247,7 +247,7 @@ class PasswordEditorTableViewController: UITableViewController { if selectedCell == deletePasswordCell { let alert = UIAlertController(title: "DeletePassword?".localize(), message: nil, preferredStyle: UIAlertController.Style.alert) alert.addAction( - UIAlertAction(title: "Delete".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ -> Void in + UIAlertAction(title: "Delete".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in self.performSegue(withIdentifier: "deletePasswordSegue", sender: self) } ) @@ -440,7 +440,7 @@ extension PasswordEditorTableViewController: SFSafariViewControllerDelegate { message.append(Utils.attributedPassword(plainPassword: generatedPassword)) alert.setValue(message, forKey: "attributedMessage") alert.addAction( - UIAlertAction(title: "Yes", style: UIAlertAction.Style.default) { [unowned self] _ -> Void in + UIAlertAction(title: "Yes", style: UIAlertAction.Style.default) { [unowned self] _ in // update tableData so to make sure reloadData() works correctly self.tableData[self.passwordSection][0][PasswordEditorCellKey.content] = generatedPassword // update cell manually, no need to call reloadData() diff --git a/pass/Controllers/PasswordNavigationViewController.swift b/pass/Controllers/PasswordNavigationViewController.swift index ccd197c..59a9704 100644 --- a/pass/Controllers/PasswordNavigationViewController.swift +++ b/pass/Controllers/PasswordNavigationViewController.swift @@ -40,9 +40,7 @@ class PasswordNavigationViewController: UIViewController { return uiSearchController }() - lazy var searchBar: UISearchBar = { - self.searchController.searchBar - }() + lazy var searchBar: UISearchBar = self.searchController.searchBar lazy var refreshControl: UIRefreshControl = { let refreshControl = UIRefreshControl() diff --git a/pass/Controllers/SSHKeyArmorImportTableViewController.swift b/pass/Controllers/SSHKeyArmorImportTableViewController.swift index 7822b35..650e33c 100644 --- a/pass/Controllers/SSHKeyArmorImportTableViewController.swift +++ b/pass/Controllers/SSHKeyArmorImportTableViewController.swift @@ -92,6 +92,6 @@ extension SSHKeyArmorImportTableViewController: KeyImporter { } func importKeys() throws { - try KeyFileManager.PrivateSsh.importKey(from: armorPrivateKey ?? "") + try KeyFileManager.PrivateSSH.importKey(from: armorPrivateKey ?? "") } } diff --git a/pass/Controllers/SSHKeyFileImportTableViewController.swift b/pass/Controllers/SSHKeyFileImportTableViewController.swift index 456c9d1..9e8e5c4 100644 --- a/pass/Controllers/SSHKeyFileImportTableViewController.swift +++ b/pass/Controllers/SSHKeyFileImportTableViewController.swift @@ -75,6 +75,6 @@ extension SSHKeyFileImportTableViewController: KeyImporter { guard let privateKey = privateKey else { return } - try KeyFileManager.PrivateSsh.importKey(from: privateKey) + try KeyFileManager.PrivateSSH.importKey(from: privateKey) } } diff --git a/pass/Controllers/SSHKeyUrlImportTableViewController.swift b/pass/Controllers/SSHKeyURLImportTableViewController..swift similarity index 90% rename from pass/Controllers/SSHKeyUrlImportTableViewController.swift rename to pass/Controllers/SSHKeyURLImportTableViewController..swift index 3ee4869..e3bf6c7 100644 --- a/pass/Controllers/SSHKeyUrlImportTableViewController.swift +++ b/pass/Controllers/SSHKeyURLImportTableViewController..swift @@ -1,5 +1,5 @@ // -// SSHKeyUrlImportTableViewController.swift +// SSHKeyURLImportTableViewController.swift // pass // // Created by Mingshen Sun on 25/1/2017. @@ -9,7 +9,7 @@ import passKit import SVProgressHUD -class SSHKeyUrlImportTableViewController: AutoCellHeightUITableViewController { +class SSHKeyURLImportTableViewController: AutoCellHeightUITableViewController { @IBOutlet var privateKeyURLTextField: UITextField! var sshPrivateKeyURL: URL? @@ -42,7 +42,7 @@ class SSHKeyUrlImportTableViewController: AutoCellHeightUITableViewController { } } -extension SSHKeyUrlImportTableViewController: KeyImporter { +extension SSHKeyURLImportTableViewController: KeyImporter { static let keySource = KeySource.url static let label = "DownloadFromUrl".localize() @@ -60,6 +60,6 @@ extension SSHKeyUrlImportTableViewController: KeyImporter { func importKeys() throws { Defaults.gitSSHPrivateKeyURL = sshPrivateKeyURL - try KeyFileManager.PrivateSsh.importKey(from: Defaults.gitSSHPrivateKeyURL!) + try KeyFileManager.PrivateSSH.importKey(from: Defaults.gitSSHPrivateKeyURL!) } } diff --git a/pass/Controllers/SettingsTableViewController.swift b/pass/Controllers/SettingsTableViewController.swift index e7ec8dd..0490539 100644 --- a/pass/Controllers/SettingsTableViewController.swift +++ b/pass/Controllers/SettingsTableViewController.swift @@ -150,7 +150,7 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele func showPGPKeyActionSheet() { let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) optionMenu.addAction( - UIAlertAction(title: PGPKeyUrlImportTableViewController.menuLabel, style: .default) { _ in + UIAlertAction(title: PGPKeyURLImportTableViewController.menuLabel, style: .default) { _ in self.performSegue(withIdentifier: "setPGPKeyByURLSegue", sender: self) } ) @@ -184,8 +184,8 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele if Defaults.pgpKeySource != nil { optionMenu.addAction( UIAlertAction(title: "RemovePgpKeys".localize(), style: .destructive) { _ in - self.keychain.removeContent(for: PgpKey.PUBLIC.getKeychainKey()) - self.keychain.removeContent(for: PgpKey.PRIVATE.getKeychainKey()) + self.keychain.removeContent(for: PGPKey.PUBLIC.getKeychainKey()) + self.keychain.removeContent(for: PGPKey.PRIVATE.getKeychainKey()) PGPAgent.shared.uninitKeys() self.pgpKeyTableViewCell.detailTextLabel?.text = "NotSet".localize() Defaults.pgpKeySource = nil @@ -240,19 +240,19 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele func setPasscodeLock() { // prepare the alert for setting the passcode setPasscodeLockAlert = UIAlertController(title: "SetPasscode".localize(), message: "FillInAppPasscode.".localize(), preferredStyle: .alert) - setPasscodeLockAlert?.addTextField { textField -> Void in + setPasscodeLockAlert?.addTextField { textField in textField.placeholder = "Passcode".localize() textField.isSecureTextEntry = true textField.addTarget(self, action: #selector(self.alertTextFieldDidChange), for: UIControl.Event.editingChanged) } - setPasscodeLockAlert?.addTextField { textField -> Void in + setPasscodeLockAlert?.addTextField { textField in textField.placeholder = "PasswordConfirmation".localize() textField.isSecureTextEntry = true textField.addTarget(self, action: #selector(self.alertTextFieldDidChange), for: UIControl.Event.editingChanged) } // save action - let saveAction = UIAlertAction(title: "Save".localize(), style: .default) { (_: UIAlertAction) -> Void in + let saveAction = UIAlertAction(title: "Save".localize(), style: .default) { (_: UIAlertAction) in let passcode: String = self.setPasscodeLockAlert!.textFields![0].text! self.passcodeLock.save(passcode: passcode) // refresh the passcode lock cell ("On") @@ -275,12 +275,12 @@ extension SettingsTableViewController: PGPKeyImporter { static let label = "ITunesFileSharing".localize() func isReadyToUse() -> Bool { - KeyFileManager.PublicPgp.doesKeyFileExist() && KeyFileManager.PrivatePgp.doesKeyFileExist() + KeyFileManager.PublicPGP.doesKeyFileExist() && KeyFileManager.PrivatePGP.doesKeyFileExist() } func importKeys() throws { - try KeyFileManager.PublicPgp.importKeyFromFileSharing() - try KeyFileManager.PrivatePgp.importKeyFromFileSharing() + try KeyFileManager.PublicPGP.importKeyFromFileSharing() + try KeyFileManager.PrivatePGP.importKeyFromFileSharing() } func saveImportedKeys() { diff --git a/passAutoFillExtension/Controllers/CredentialProviderViewController.swift b/passAutoFillExtension/Controllers/CredentialProviderViewController.swift index ab9af29..1b3ea85 100644 --- a/passAutoFillExtension/Controllers/CredentialProviderViewController.swift +++ b/passAutoFillExtension/Controllers/CredentialProviderViewController.swift @@ -14,9 +14,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController { PasscodeExtensionDisplay(extensionContext: extensionContext) }() - private lazy var passwordsViewController: PasswordsViewController = { - (children.first as! UINavigationController).viewControllers.first as! PasswordsViewController - }() + private lazy var passwordsViewController: PasswordsViewController = (children.first as! UINavigationController).viewControllers.first as! PasswordsViewController private lazy var credentialProvider: CredentialProvider = { [unowned self] in CredentialProvider(viewController: self, extensionContext: extensionContext, afterDecryption: NotificationCenterDispatcher.showOTPNotification) diff --git a/passAutoFillExtension/Controllers/PasswordsViewController.swift b/passAutoFillExtension/Controllers/PasswordsViewController.swift index e6c854b..b33c043 100644 --- a/passAutoFillExtension/Controllers/PasswordsViewController.swift +++ b/passAutoFillExtension/Controllers/PasswordsViewController.swift @@ -27,9 +27,7 @@ class PasswordsViewController: UIViewController { return uiSearchController }() - lazy var searchBar: UISearchBar = { - self.searchController.searchBar - }() + lazy var searchBar: UISearchBar = self.searchController.searchBar override func viewDidLoad() { super.viewDidLoad() diff --git a/passExtension/Controllers/ExtensionViewController.swift b/passExtension/Controllers/ExtensionViewController.swift index ab814a0..bd18ecd 100644 --- a/passExtension/Controllers/ExtensionViewController.swift +++ b/passExtension/Controllers/ExtensionViewController.swift @@ -15,9 +15,7 @@ class ExtensionViewController: UIViewController { PasscodeExtensionDisplay(extensionContext: extensionContext!) }() - private lazy var passwordsViewController: PasswordsViewController = { - (children.first as! UINavigationController).viewControllers.first as! PasswordsViewController - }() + private lazy var passwordsViewController: PasswordsViewController = (children.first as! UINavigationController).viewControllers.first as! PasswordsViewController private lazy var credentialProvider: CredentialProvider = { [unowned self] in CredentialProvider(viewController: self, extensionContext: extensionContext!, afterDecryption: NotificationCenterDispatcher.showOTPNotification) diff --git a/passKit/Controllers/PasscodeLockViewController.swift b/passKit/Controllers/PasscodeLockViewController.swift index 5282d3b..d7acb7c 100644 --- a/passKit/Controllers/PasscodeLockViewController.swift +++ b/passKit/Controllers/PasscodeLockViewController.swift @@ -189,7 +189,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate { func forgotPasscodeButtonPressedAction(_: UIButton) { let alert = UIAlertController(title: "ResetPass".localize(), message: "ResetPassExplanation.".localize(), preferredStyle: UIAlertController.Style.alert) alert.addAction( - UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ -> Void in + UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in let myContext = LAContext() // If the device passcode is not set, reset the app. guard myContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil) else { diff --git a/passKit/Crypto/GopenPGPInterface.swift b/passKit/Crypto/GopenPGPInterface.swift index a0f7b6a..7a6a815 100644 --- a/passKit/Crypto/GopenPGPInterface.swift +++ b/passKit/Crypto/GopenPGPInterface.swift @@ -46,7 +46,7 @@ struct GopenPGPInterface: PGPInterface { func extractKeysFromArmored(str: String) -> [String] { var keys: [String] = [] - var key: String = "" + var key = "" for line in str.splitByNewline() { if line.trimmed.uppercased().hasPrefix("-----BEGIN PGP") { key = "" @@ -100,7 +100,7 @@ struct GopenPGPInterface: PGPInterface { throw AppError.decryption } - let message = createPgpMessage(from: encryptedData) + let message = createPGPMessage(from: encryptedData) return try keyRing.decrypt(message, verifyKey: nil, verifyTime: 0).data } catch { throw Self.errorMapping[error.localizedDescription, default: error] @@ -148,7 +148,7 @@ struct GopenPGPInterface: PGPInterface { publicKeys.keys.map { $0.suffix(8).uppercased() } } - private func createPgpMessage(from encryptedData: Data) -> CryptoPGPMessage? { + private func createPGPMessage(from encryptedData: Data) -> CryptoPGPMessage? { // Important note: // Even if Defaults.encryptInArmored is true now, it could be different during the encryption. var error: NSError? diff --git a/passKit/Crypto/PGPAgent.swift b/passKit/Crypto/PGPAgent.swift index 85de975..2278ada 100644 --- a/passKit/Crypto/PGPAgent.swift +++ b/passKit/Crypto/PGPAgent.swift @@ -18,8 +18,8 @@ public class PGPAgent { } public func initKeys() throws { - guard let publicKey: String = keyStore.get(for: PgpKey.PUBLIC.getKeychainKey()), - let privateKey: String = keyStore.get(for: PgpKey.PRIVATE.getKeychainKey()) else { + guard let publicKey: String = keyStore.get(for: PGPKey.PUBLIC.getKeychainKey()), + let privateKey: String = keyStore.get(for: PGPKey.PRIVATE.getKeychainKey()) else { pgpInterface = nil throw AppError.keyImport } @@ -127,8 +127,8 @@ public class PGPAgent { } public var isPrepared: Bool { - keyStore.contains(key: PgpKey.PUBLIC.getKeychainKey()) - && keyStore.contains(key: PgpKey.PRIVATE.getKeychainKey()) + keyStore.contains(key: PGPKey.PUBLIC.getKeychainKey()) + && keyStore.contains(key: PGPKey.PRIVATE.getKeychainKey()) } private func checkAndInit() throws { diff --git a/passKit/Helpers/CryptographicKeys.swift b/passKit/Helpers/CryptographicKeys.swift index addf5f3..ee4c95f 100644 --- a/passKit/Helpers/CryptographicKeys.swift +++ b/passKit/Helpers/CryptographicKeys.swift @@ -11,7 +11,7 @@ public protocol CryptographicKey { func getFileSharingPath() -> String } -public enum PgpKey: CryptographicKey { +public enum PGPKey: CryptographicKey { case PUBLIC case PRIVATE @@ -34,7 +34,7 @@ public enum PgpKey: CryptographicKey { } } -public enum SshKey: CryptographicKey { +public enum SSHKey: CryptographicKey { case PRIVATE public func getKeychainKey() -> String { diff --git a/passKit/Helpers/FileManagerExtension.swift b/passKit/Helpers/FileManagerExtension.swift index d6ac2e1..e91620a 100644 --- a/passKit/Helpers/FileManagerExtension.swift +++ b/passKit/Helpers/FileManagerExtension.swift @@ -50,7 +50,9 @@ public extension FileManager { let contentItemURL = item as! NSURL // Bail out on errors from the errorHandler. - if let error = errorDidOccur { throw error } + if let error = errorDidOccur { + throw error + } let resourceValueForKey: (URLResourceKey) throws -> NSNumber? = { key in var value: AnyObject? @@ -84,7 +86,9 @@ public extension FileManager { } // Bail out on errors from the errorHandler. - if let error = errorDidOccur { throw error } + if let error = errorDidOccur { + throw error + } // We finally got it. return accumulatedSize diff --git a/passKit/Helpers/KeyFileManager.swift b/passKit/Helpers/KeyFileManager.swift index 8ecd95e..cfb5e45 100644 --- a/passKit/Helpers/KeyFileManager.swift +++ b/passKit/Helpers/KeyFileManager.swift @@ -9,9 +9,9 @@ public class KeyFileManager { public typealias KeyHandler = (String, String) -> Void - public static let PublicPgp = KeyFileManager(keyType: PgpKey.PUBLIC) - public static let PrivatePgp = KeyFileManager(keyType: PgpKey.PRIVATE) - public static let PrivateSsh = KeyFileManager(keyType: SshKey.PRIVATE) + public static let PublicPGP = KeyFileManager(keyType: PGPKey.PUBLIC) + public static let PrivatePGP = KeyFileManager(keyType: PGPKey.PRIVATE) + public static let PrivateSSH = KeyFileManager(keyType: SSHKey.PRIVATE) private let keyType: CryptographicKey private let keyPath: String diff --git a/passKit/Models/GitCredential.swift b/passKit/Models/GitCredential.swift index bfa2181..7ab9fcc 100644 --- a/passKit/Models/GitCredential.swift +++ b/passKit/Models/GitCredential.swift @@ -61,7 +61,7 @@ public struct GitCredential { case .password: return Self(credentialType: .http(userName: userName), keyStore: keyStore) case .key: - let privateKey: String = keyStore.get(for: SshKey.PRIVATE.getKeychainKey()) ?? "" + let privateKey: String = keyStore.get(for: SSHKey.PRIVATE.getKeychainKey()) ?? "" return Self(credentialType: .ssh(userName: userName, privateKey: privateKey), keyStore: keyStore) } } diff --git a/passKit/Models/Password.swift b/passKit/Models/Password.swift index 0db3da9..9a2b03f 100644 --- a/passKit/Models/Password.swift +++ b/passKit/Models/Password.swift @@ -139,7 +139,7 @@ public class Password { /// /// otpauth://totp/totp-secret?secret=AAAAAAAAAAAAAAAA&issuer=totp-secret /// - /// See also [Key Uri Format](https://github.com/google/google-authenticator/wiki/Key-Uri-Format). + /// See also [Key URI Format](https://github.com/google/google-authenticator/wiki/Key-URI-Format). /// /// In case no otpauth is given in the password file, try to construct the token from separate fields using a /// `TokenBuilder`. This means that tokens provided as otpauth have higher priority. @@ -150,7 +150,7 @@ public class Password { if !otpauthString.hasPrefix("\(Constants.OTPAUTH):") { otpauthString = "\(Constants.OTPAUTH):\(otpauthString)" } - if let otpauthUrl = URL(string: otpauthString), let token = Token(url: otpauthUrl) { + if let otpauthURL = URL(string: otpauthString), let token = Token(url: otpauthURL) { otpToken = token return } diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index dd69685..b1df8ee 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -67,14 +67,14 @@ public class PasswordStore { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - /* - Typical reasons for an error here include: - * The parent directory does not exist, cannot be created, or disallows writing. - * The persistent store is not accessible, due to permissions or data protection when the device is locked. - * The device is out of space. - * The store could not be migrated to the current model version. - Check the error message to determine what the actual problem was. - */ + // Typical reasons for an error here include: + // + // * The parent directory does not exist, cannot be created, or disallows writing. + // * The persistent store is not accessible, due to permissions or data protection when the device is locked. + // * The device is out of space. + // * The store could not be migrated to the current model version. + // + // Check the error message to determine what the actual problem was. fatalError("UnresolvedError".localize("\(error.localizedDescription), \(error.userInfo)")) } } @@ -128,9 +128,9 @@ public class PasswordStore { private func importExistingKeysIntoKeychain() { // App Store update: v0.5.1 -> v0.6.0 - try? KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyFromFileSharing() - try? KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyFromFileSharing() - try? KeyFileManager(keyType: SshKey.PRIVATE, keyPath: Globals.gitSSHPrivateKeyPath).importKeyFromFileSharing() + try? KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyFromFileSharing() + try? KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyFromFileSharing() + try? KeyFileManager(keyType: SSHKey.PRIVATE, keyPath: Globals.gitSSHPrivateKeyPath).importKeyFromFileSharing() Defaults.remove(\.pgpPublicKeyArmor) Defaults.remove(\.pgpPrivateKeyArmor) Defaults.remove(\.gitSSHPrivateKeyArmor) @@ -733,7 +733,7 @@ public class PasswordStore { Defaults.remove(\.gitSSHKeySource) Defaults.remove(\.gitSSHPrivateKeyArmor) Defaults.remove(\.gitSSHPrivateKeyURL) - AppKeychain.shared.removeContent(for: SshKey.PRIVATE.getKeychainKey()) + AppKeychain.shared.removeContent(for: SSHKey.PRIVATE.getKeychainKey()) gitSSHPrivateKeyPassphrase = nil } } diff --git a/passKitTests/Crypto/PGPAgentTest.swift b/passKitTests/Crypto/PGPAgentTest.swift index 99b8eea..1acd37e 100644 --- a/passKitTests/Crypto/PGPAgentTest.swift +++ b/passKitTests/Crypto/PGPAgentTest.swift @@ -88,7 +88,7 @@ class PGPAgentTest: XCTestCase { } func testNoPrivateKey() throws { - try KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048.publicKey) + try KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048.publicKey) XCTAssertFalse(pgpAgent.isPrepared) XCTAssertThrowsError(try pgpAgent.initKeys()) { XCTAssertEqual($0 as! AppError, AppError.keyImport) @@ -126,8 +126,8 @@ class PGPAgentTest: XCTestCase { try importKeys(ED25519.publicKey, ED25519.privateKey) XCTAssert(pgpAgent.isPrepared) XCTAssertEqual(try basicEncryptDecrypt(using: pgpAgent, keyID: ED25519.fingerprint), testData) - keychain.removeContent(for: PgpKey.PUBLIC.getKeychainKey()) - keychain.removeContent(for: PgpKey.PRIVATE.getKeychainKey()) + keychain.removeContent(for: PGPKey.PUBLIC.getKeychainKey()) + keychain.removeContent(for: PGPKey.PRIVATE.getKeychainKey()) XCTAssertThrowsError(try basicEncryptDecrypt(using: pgpAgent, keyID: ED25519.fingerprint)) { XCTAssertEqual($0 as! AppError, AppError.keyImport) } @@ -162,7 +162,7 @@ class PGPAgentTest: XCTestCase { } private func importKeys(_ publicKey: String, _ privateKey: String) throws { - try KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: publicKey) - try KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: "", keyHandler: keychain.add).importKey(from: privateKey) + try KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: publicKey) + try KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: "", keyHandler: keychain.add).importKey(from: privateKey) } } diff --git a/passKitTests/Helpers/KeyFileManagerTest.swift b/passKitTests/Helpers/KeyFileManagerTest.swift index 4d38e31..3e6a61f 100644 --- a/passKitTests/Helpers/KeyFileManagerTest.swift +++ b/passKitTests/Helpers/KeyFileManagerTest.swift @@ -12,7 +12,7 @@ import XCTest class KeyFileManagerTest: XCTestCase { private static let filePath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("test.txt").path - private static let keyFileManager = KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: filePath) { _, _ in } + private static let keyFileManager = KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: filePath) { _, _ in } override func tearDown() { try? FileManager.default.removeItem(atPath: Self.filePath) @@ -22,39 +22,39 @@ class KeyFileManagerTest: XCTestCase { func testImportKeyFromFileSharing() throws { let fileContent = "content".data(using: .ascii) var storage: [String: String] = [:] - let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 } + let keyFileManager = KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 } FileManager.default.createFile(atPath: Self.filePath, contents: fileContent, attributes: nil) try keyFileManager.importKeyFromFileSharing() XCTAssertFalse(FileManager.default.fileExists(atPath: Self.filePath)) - XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], "content") + XCTAssertEqual(storage[PGPKey.PRIVATE.getKeychainKey()], "content") } func testErrorReadingFile() throws { XCTAssertThrowsError(try Self.keyFileManager.importKeyFromFileSharing()) } - func testImportKeyFromUrl() throws { + func testImportKeyFromURL() throws { let fileContent = "content".data(using: .ascii) let url = URL(fileURLWithPath: Self.filePath) var storage: [String: String] = [:] - let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 } + let keyFileManager = KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 } FileManager.default.createFile(atPath: Self.filePath, contents: fileContent, attributes: nil) try keyFileManager.importKey(from: url) - XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], "content") + XCTAssertEqual(storage[PGPKey.PRIVATE.getKeychainKey()], "content") } func testImportKeyFromString() throws { let string = "content" var storage: [String: String] = [:] - let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 } + let keyFileManager = KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 } try keyFileManager.importKey(from: string) - XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], string) + XCTAssertEqual(storage[PGPKey.PRIVATE.getKeychainKey()], string) } func testImportKeyFromNonAsciiString() throws { diff --git a/passKitTests/Models/PasswordStoreTest.swift b/passKitTests/Models/PasswordStoreTest.swift index 1242726..5ea205d 100644 --- a/passKitTests/Models/PasswordStoreTest.swift +++ b/passKitTests/Models/PasswordStoreTest.swift @@ -32,8 +32,8 @@ class PasswordStoreTest: XCTestCase { } let keychain = AppKeychain.shared - try KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048_RSA4096.publicKeys) - try KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048_RSA4096.privateKeys) + try KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048_RSA4096.publicKeys) + try KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048_RSA4096.privateKeys) try PGPAgent.shared.initKeys() let personal = try decrypt(passwordStore: passwordStore, path: "personal/github.com.gpg", passphrase: "passforios") diff --git a/passKitTests/Models/PasswordTest.swift b/passKitTests/Models/PasswordTest.swift index 35dee53..dddc582 100644 --- a/passKitTests/Models/PasswordTest.swift +++ b/passKitTests/Models/PasswordTest.swift @@ -11,7 +11,7 @@ import XCTest @testable import passKit class PasswordTest: XCTestCase { - func testUrl() { + func testURL() { let password = getPasswordObjectWith(content: "") XCTAssertEqual(password.url, PASSWORD_URL) diff --git a/scripts/swiftformat.sh b/scripts/swiftformat.sh index be52e2a..8c82e26 100755 --- a/scripts/swiftformat.sh +++ b/scripts/swiftformat.sh @@ -1,4 +1,4 @@ -SWIFTFORMAT_VERSION="0.48.*" +SWIFTFORMAT_VERSION="0.49.*" if [[ "${CI}" == "true" ]]; then echo "Running in a Continuous Integration environment. Formatting is skipped."