Use SwiftFormat version 0.49.x and enable some new rules (#527)

This commit is contained in:
Danny Moesch 2021-12-28 02:57:11 +01:00 committed by GitHub
parent b62c5fa2e5
commit cdedff0d4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 139 additions and 126 deletions

View file

@ -10,12 +10,16 @@
## Enabled rules ## Enabled rules
--rules \ --rules \
acronyms, \
andOperator, \ andOperator, \
anyObjectProtocol, \ anyObjectProtocol, \
assertionFailures, \
blankLinesAroundMark, \ blankLinesAroundMark, \
blankLinesAtEndOfScope, \ blankLinesAtEndOfScope, \
blankLinesAtStartOfScope, \ blankLinesAtStartOfScope, \
# blankLinesBetweenImports, \
blankLinesBetweenScopes, \ blankLinesBetweenScopes, \
blockComments, \
braces, \ braces, \
consecutiveBlankLines, \ consecutiveBlankLines, \
consecutiveSpaces, \ consecutiveSpaces, \
@ -36,9 +40,11 @@
# markTypes, \ # markTypes, \
numberFormatting, \ numberFormatting, \
# organizeDeclarations, \ # organizeDeclarations, \
preferDouble, \
preferKeyPath, \ preferKeyPath, \
redundantBackticks, \ redundantBackticks, \
redundantBreak, \ redundantBreak, \
redundantClosure, \
redundantExtensionACL, \ redundantExtensionACL, \
redundantFileprivate, \ redundantFileprivate, \
redundantGet, \ redundantGet, \
@ -81,6 +87,7 @@
wrap, \ wrap, \
wrapArguments, \ wrapArguments, \
wrapAttributes, \ wrapAttributes, \
wrapConditionalBodies, \
# wrapEnumCases, \ # wrapEnumCases, \
# wrapMultilineStatementBraces, \ # wrapMultilineStatementBraces, \
# wrapSwitchCases, \ # wrapSwitchCases, \
@ -88,6 +95,10 @@
## Formatting options ## 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) ### Use allman indentation style: "true" or "false" (default)
--allman false --allman false
@ -272,6 +283,14 @@
--wrapreturntype preserve --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) ### Xcode indent guard/enum: "enabled" or "disabled" (default)
--xcodeindentation disabled --xcodeindentation disabled

View file

@ -180,14 +180,14 @@
DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914941E434301007FF592 /* LabelTableViewCell.swift */; }; DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914941E434301007FF592 /* LabelTableViewCell.swift */; };
DC4914991E434600007FF592 /* PasswordDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */; }; DC4914991E434600007FF592 /* PasswordDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */; };
DC5F385B1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC5F385A1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.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 */; }; DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC917BD61E2E8231000FDF54 /* AppDelegate.swift */; };
DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDA1E2E8231000FDF54 /* Main.storyboard */; }; DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDA1E2E8231000FDF54 /* Main.storyboard */; };
DC917BDE1E2E8231000FDF54 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDD1E2E8231000FDF54 /* Assets.xcassets */; }; DC917BDE1E2E8231000FDF54 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDD1E2E8231000FDF54 /* Assets.xcassets */; };
DC917BE11E2E8231000FDF54 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDF1E2E8231000FDF54 /* LaunchScreen.storyboard */; }; DC917BE11E2E8231000FDF54 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DC917BDF1E2E8231000FDF54 /* LaunchScreen.storyboard */; };
DC962CDF1E4B62C10033B5D8 /* AboutTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC962CDE1E4B62C10033B5D8 /* AboutTableViewController.swift */; }; DC962CDF1E4B62C10033B5D8 /* AboutTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC962CDE1E4B62C10033B5D8 /* AboutTableViewController.swift */; };
DCA0499A1E335CC800522E8F /* GitRepositorySettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA049991E335CC800522E8F /* GitRepositorySettingsTableViewController.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 */; }; DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */; };
DCC441521E8F6C06008A90C4 /* RawPasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC441511E8F6C06008A90C4 /* RawPasswordViewController.swift */; }; DCC441521E8F6C06008A90C4 /* RawPasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC441511E8F6C06008A90C4 /* RawPasswordViewController.swift */; };
DCC441541E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC441531E916382008A90C4 /* SSHKeyArmorImportTableViewController.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 = "<group>"; }; DC4914941E434301007FF592 /* LabelTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelTableViewCell.swift; sourceTree = "<group>"; };
DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailTableViewController.swift; sourceTree = "<group>"; }; DC4914981E434600007FF592 /* PasswordDetailTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailTableViewController.swift; sourceTree = "<group>"; };
DC5F385A1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGPKeyArmorImportTableViewController.swift; sourceTree = "<group>"; }; DC5F385A1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGPKeyArmorImportTableViewController.swift; sourceTree = "<group>"; };
DC8963BF1E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSHKeyUrlImportTableViewController.swift; sourceTree = "<group>"; }; DC8963BF1E38EEB900828B09 /* SSHKeyURLImportTableViewController..swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSHKeyURLImportTableViewController..swift; sourceTree = "<group>"; };
DC917BD31E2E8231000FDF54 /* Pass.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Pass.app; sourceTree = BUILT_PRODUCTS_DIR; }; 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 = "<group>"; }; DC917BD61E2E8231000FDF54 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
DC917BDB1E2E8231000FDF54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; }; DC917BDB1E2E8231000FDF54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@ -472,7 +472,7 @@
DC917BE21E2E8231000FDF54 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; DC917BE21E2E8231000FDF54 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DC962CDE1E4B62C10033B5D8 /* AboutTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutTableViewController.swift; sourceTree = "<group>"; }; DC962CDE1E4B62C10033B5D8 /* AboutTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutTableViewController.swift; sourceTree = "<group>"; };
DCA049991E335CC800522E8F /* GitRepositorySettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitRepositorySettingsTableViewController.swift; sourceTree = "<group>"; }; DCA049991E335CC800522E8F /* GitRepositorySettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitRepositorySettingsTableViewController.swift; sourceTree = "<group>"; };
DCA0499B1E3362F400522E8F /* PGPKeyUrlImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGPKeyUrlImportTableViewController.swift; sourceTree = "<group>"; }; DCA0499B1E3362F400522E8F /* PGPKeyURLImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGPKeyURLImportTableViewController.swift; sourceTree = "<group>"; };
DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsTableViewController.swift; sourceTree = "<group>"; }; DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsTableViewController.swift; sourceTree = "<group>"; };
DCC441511E8F6C06008A90C4 /* RawPasswordViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawPasswordViewController.swift; sourceTree = "<group>"; }; DCC441511E8F6C06008A90C4 /* RawPasswordViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawPasswordViewController.swift; sourceTree = "<group>"; };
DCC441531E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSHKeyArmorImportTableViewController.swift; sourceTree = "<group>"; }; DCC441531E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSHKeyArmorImportTableViewController.swift; sourceTree = "<group>"; };
@ -916,7 +916,7 @@
DC5F385A1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift */, DC5F385A1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift */,
302269B223E634B000F843A3 /* PGPKeyFIleImportTableViewController.swift */, 302269B223E634B000F843A3 /* PGPKeyFIleImportTableViewController.swift */,
3066AD6723EE0D6500F65535 /* PGPKeyImporter.swift */, 3066AD6723EE0D6500F65535 /* PGPKeyImporter.swift */,
DCA0499B1E3362F400522E8F /* PGPKeyUrlImportTableViewController.swift */, DCA0499B1E3362F400522E8F /* PGPKeyURLImportTableViewController.swift */,
A2A7813E1E97DBD9001311F5 /* QRScannerController.swift */, A2A7813E1E97DBD9001311F5 /* QRScannerController.swift */,
DCC441511E8F6C06008A90C4 /* RawPasswordViewController.swift */, DCC441511E8F6C06008A90C4 /* RawPasswordViewController.swift */,
DCD3C65D1EFB9BB400CBE842 /* SettingsSplitViewController.swift */, DCD3C65D1EFB9BB400CBE842 /* SettingsSplitViewController.swift */,
@ -924,7 +924,7 @@
DC037CA91E4B8EAE00609409 /* SpecialThanksTableViewController.swift */, DC037CA91E4B8EAE00609409 /* SpecialThanksTableViewController.swift */,
DCC441531E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift */, DCC441531E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift */,
30650E7023F82AF8005CCD5E /* SSHKeyFileImportTableViewController.swift */, 30650E7023F82AF8005CCD5E /* SSHKeyFileImportTableViewController.swift */,
DC8963BF1E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift */, DC8963BF1E38EEB900828B09 /* SSHKeyURLImportTableViewController..swift */,
); );
path = Controllers; path = Controllers;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1604,7 +1604,7 @@
DCC441541E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift in Sources */, DCC441541E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift in Sources */,
306D970E24091CDD006C0E2E /* SwitchTableViewCell.swift in Sources */, 306D970E24091CDD006C0E2E /* SwitchTableViewCell.swift in Sources */,
A2A61C201EEFABAD00CFE063 /* UtilsExtension.swift in Sources */, A2A61C201EEFABAD00CFE063 /* UtilsExtension.swift in Sources */,
DC8963C01E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift in Sources */, DC8963C01E38EEB900828B09 /* SSHKeyURLImportTableViewController..swift in Sources */,
9AFC87F025B514AD008D6060 /* PasswordDecryptor.swift in Sources */, 9AFC87F025B514AD008D6060 /* PasswordDecryptor.swift in Sources */,
3066AD6823EE0D6500F65535 /* PGPKeyImporter.swift in Sources */, 3066AD6823EE0D6500F65535 /* PGPKeyImporter.swift in Sources */,
9AFC87E225B3B5C6008D6060 /* PasswordNavigationDataSource.swift in Sources */, 9AFC87E225B3B5C6008D6060 /* PasswordNavigationDataSource.swift in Sources */,
@ -1612,7 +1612,7 @@
DC193FFA1E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift in Sources */, DC193FFA1E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift in Sources */,
DCFB77AB1E503729008DE471 /* ContentProvider.swift in Sources */, DCFB77AB1E503729008DE471 /* ContentProvider.swift in Sources */,
9AFC880025B51EC3008D6060 /* PasswordEncryptor.swift in Sources */, 9AFC880025B51EC3008D6060 /* PasswordEncryptor.swift in Sources */,
DCA0499C1E3362F400522E8F /* PGPKeyUrlImportTableViewController.swift in Sources */, DCA0499C1E3362F400522E8F /* PGPKeyURLImportTableViewController.swift in Sources */,
DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */, DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */,
DC5F385B1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift in Sources */, DC5F385B1E56AADB00C69ACA /* PGPKeyArmorImportTableViewController.swift in Sources */,
DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */, DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */,

View file

@ -111,12 +111,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// MARK: - Core Data stack // MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = { lazy var persistentContainer: NSPersistentContainer = {
/* // The persistent container for the application. This implementation
The persistent container for the application. This implementation // creates and returns a container, having loaded the store for the
creates and returns a container, having loaded the store for the // application to it. This property is optional since there are legitimate
application to it. This property is optional since there are legitimate // error conditions that could cause the creation of the store to fail.
error conditions that could cause the creation of the store to fail.
*/
let modelURL = Bundle(identifier: Globals.passKitBundleIdentifier)!.url(forResource: "pass", withExtension: "momd")! let modelURL = Bundle(identifier: Globals.passKitBundleIdentifier)!.url(forResource: "pass", withExtension: "momd")!
let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL) let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL)
let container = NSPersistentContainer(name: "pass", managedObjectModel: managedObjectModel!) 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. // 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. // 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:
Typical reasons for an error here include: //
* The parent directory does not exist, cannot be created, or disallows writing. // * 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 persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space. // * The device is out of space.
* The store could not be migrated to the current model version. // * The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was. //
*/ // Check the error message to determine what the actual problem was.
fatalError("UnresolvedError".localize("\(error), \(error.userInfo)")) fatalError("UnresolvedError".localize("\(error), \(error.userInfo)"))
} }
} }

View file

@ -49,7 +49,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
if tableView.cellForRow(at: indexPath) == eraseDataTableViewCell { if tableView.cellForRow(at: indexPath) == eraseDataTableViewCell {
let alert = UIAlertController(title: "ErasePasswordStoreData?".localize(), message: "EraseExplanation.".localize(), preferredStyle: UIAlertController.Style.alert) let alert = UIAlertController(title: "ErasePasswordStoreData?".localize(), message: "EraseExplanation.".localize(), preferredStyle: UIAlertController.Style.alert)
alert.addAction( 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()) SVProgressHUD.show(withStatus: "Erasing...".localize())
self.passwordStore.erase() self.passwordStore.erase()
self.navigationController!.popViewController(animated: true) self.navigationController!.popViewController(animated: true)
@ -62,7 +62,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
} else if tableView.cellForRow(at: indexPath) == discardChangesTableViewCell { } else if tableView.cellForRow(at: indexPath) == discardChangesTableViewCell {
let alert = UIAlertController(title: "DiscardAllLocalChanges?".localize(), message: "DiscardExplanation.".localize(), preferredStyle: UIAlertController.Style.alert) let alert = UIAlertController(title: "DiscardAllLocalChanges?".localize(), message: "DiscardExplanation.".localize(), preferredStyle: UIAlertController.Style.alert)
alert.addAction( 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()) SVProgressHUD.show(withStatus: "Resetting...".localize())
do { do {
let numberDiscarded = try self.passwordStore.reset() let numberDiscarded = try self.passwordStore.reset()

View file

@ -41,7 +41,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
} }
} }
private var gitUrl: URL { private var gitURL: URL {
get { Defaults.gitURL } get { Defaults.gitURL }
set { Defaults.gitURL = newValue } set { Defaults.gitURL = newValue }
} }
@ -60,7 +60,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
gitURLTextField.text = gitUrl.absoluteString gitURLTextField.text = gitURL.absoluteString
usernameTextField.text = gitUsername usernameTextField.text = gitUsername
branchNameTextField.text = gitBranchName branchNameTextField.text = gitBranchName
sshLabel = authSSHKeyCell.subviews[0].subviews[0] as? UILabel sshLabel = authSSHKeyCell.subviews[0].subviews[0] as? UILabel
@ -70,7 +70,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
// Grey out ssh option if ssh_key is not present. // 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) updateAuthenticationMethodCheckView(for: gitAuthenticationMethod)
} }
@ -95,7 +95,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
if cell == authPasswordCell { if cell == authPasswordCell {
gitAuthenticationMethod = .password gitAuthenticationMethod = .password
} else if cell == authSSHKeyCell { } 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) Utils.alert(title: "CannotSelectSshKey".localize(), message: "PleaseSetupSshKeyFirst.".localize(), controller: self)
gitAuthenticationMethod = .password gitAuthenticationMethod = .password
} else { } else {
@ -146,7 +146,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
} }
} }
gitUrl = gitURL self.gitURL = gitURL
gitBranchName = branchName.trimmed gitBranchName = branchName.trimmed
gitUsername = (gitURL.user ?? usernameTextField.text ?? "git").trimmed gitUsername = (gitURL.user ?? usernameTextField.text ?? "git").trimmed
@ -186,7 +186,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
let options = self.gitCredential.getCredentialOptions(passwordProvider: self.present) let options = self.gitCredential.getCredentialOptions(passwordProvider: self.present)
try self.passwordStore.cloneRepository( try self.passwordStore.cloneRepository(
remoteRepoURL: self.gitUrl, remoteRepoURL: self.gitURL,
branchName: self.gitBranchName, branchName: self.gitBranchName,
options: options, options: options,
transferProgressBlock: transferProgressBlock, transferProgressBlock: transferProgressBlock,
@ -278,7 +278,7 @@ class GitRepositorySettingsTableViewController: UITableViewController, PasswordA
private func showSSHKeyActionSheet() { private func showSSHKeyActionSheet() {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
optionMenu.addAction( optionMenu.addAction(
UIAlertAction(title: SSHKeyUrlImportTableViewController.menuLabel, style: .default) { _ in UIAlertAction(title: SSHKeyURLImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setGitSSHKeyByURLSegue", sender: self) self.performSegue(withIdentifier: "setGitSSHKeyByURLSegue", sender: self)
} }
) )
@ -354,10 +354,10 @@ extension GitRepositorySettingsTableViewController: KeyImporter {
static let label = "ITunesFileSharing".localize() static let label = "ITunesFileSharing".localize()
func isReadyToUse() -> Bool { func isReadyToUse() -> Bool {
KeyFileManager.PrivateSsh.doesKeyFileExist() KeyFileManager.PrivateSSH.doesKeyFileExist()
} }
func importKeys() throws { func importKeys() throws {
try KeyFileManager.PrivateSsh.importKeyFromFileSharing() try KeyFileManager.PrivateSSH.importKeyFromFileSharing()
} }
} }

View file

@ -109,8 +109,8 @@ extension PGPKeyArmorImportTableViewController: PGPKeyImporter {
} }
func importKeys() throws { func importKeys() throws {
try KeyFileManager.PublicPgp.importKey(from: armorPublicKey ?? "") try KeyFileManager.PublicPGP.importKey(from: armorPublicKey ?? "")
try KeyFileManager.PrivatePgp.importKey(from: armorPrivateKey ?? "") try KeyFileManager.PrivatePGP.importKey(from: armorPrivateKey ?? "")
} }
func saveImportedKeys() { func saveImportedKeys() {

View file

@ -88,8 +88,8 @@ extension PGPKeyFileImportTableViewController: PGPKeyImporter {
guard let publicKey = publicKey, let privateKey = privateKey else { guard let publicKey = publicKey, let privateKey = privateKey else {
return return
} }
try KeyFileManager.PublicPgp.importKey(from: publicKey) try KeyFileManager.PublicPGP.importKey(from: publicKey)
try KeyFileManager.PrivatePgp.importKey(from: privateKey) try KeyFileManager.PrivatePGP.importKey(from: privateKey)
} }
func doAfterImport() { func doAfterImport() {

View file

@ -1,5 +1,5 @@
// //
// PGPKeyUrlImportTableViewController.swift // PGPKeyURLImportTableViewController.swift
// pass // pass
// //
// Created by Mingshen Sun on 21/1/2017. // Created by Mingshen Sun on 21/1/2017.
@ -9,7 +9,7 @@
import passKit import passKit
import UIKit import UIKit
class PGPKeyUrlImportTableViewController: AutoCellHeightUITableViewController { class PGPKeyURLImportTableViewController: AutoCellHeightUITableViewController {
@IBOutlet var pgpPublicKeyURLTextField: UITextField! @IBOutlet var pgpPublicKeyURLTextField: UITextField!
@IBOutlet var pgpPrivateKeyURLTextField: 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 keySource = KeySource.url
static let label = "DownloadFromUrl".localize() static let label = "DownloadFromUrl".localize()
func isReadyToUse() -> Bool { func isReadyToUse() -> Bool {
validate(pgpKeyUrl: pgpPublicKeyURLTextField.text ?? "") validate(pgpKeyURL: pgpPublicKeyURLTextField.text ?? "")
&& validate(pgpKeyUrl: pgpPrivateKeyURLTextField.text ?? "") && validate(pgpKeyURL: pgpPrivateKeyURLTextField.text ?? "")
} }
func importKeys() throws { func importKeys() throws {
Defaults.pgpPrivateKeyURL = pgpPrivateKeyURL Defaults.pgpPrivateKeyURL = pgpPrivateKeyURL
Defaults.pgpPublicKeyURL = pgpPublicKeyURL Defaults.pgpPublicKeyURL = pgpPublicKeyURL
try KeyFileManager.PublicPgp.importKey(from: Defaults.pgpPublicKeyURL!) try KeyFileManager.PublicPGP.importKey(from: Defaults.pgpPublicKeyURL!)
try KeyFileManager.PrivatePgp.importKey(from: Defaults.pgpPrivateKeyURL!) try KeyFileManager.PrivatePGP.importKey(from: Defaults.pgpPrivateKeyURL!)
} }
func doAfterImport() { func doAfterImport() {
@ -65,8 +65,8 @@ extension PGPKeyUrlImportTableViewController: PGPKeyImporter {
performSegue(withIdentifier: "savePGPKeySegue", sender: self) performSegue(withIdentifier: "savePGPKeySegue", sender: self)
} }
private func validate(pgpKeyUrl: String) -> Bool { private func validate(pgpKeyURL: String) -> Bool {
guard let url = URL(string: pgpKeyUrl) else { guard let url = URL(string: pgpKeyURL) else {
Utils.alert(title: "CannotSavePgpKey".localize(), message: "SetPgpKeyUrlsFirst.".localize(), controller: self) Utils.alert(title: "CannotSavePgpKey".localize(), message: "SetPgpKeyUrlsFirst.".localize(), controller: self)
return false return false
} }

View file

@ -289,10 +289,10 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
} }
private func updatePasswordImage(urlString: String) { private func updatePasswordImage(urlString: String) {
var newUrlString = urlString var newURLString = urlString
if urlString.lowercased().hasPrefix("http://") { if urlString.lowercased().hasPrefix("http://") {
// try to replace http url to https url // try to replace http url to https url
newUrlString = urlString.replacingOccurrences( newURLString = urlString.replacingOccurrences(
of: "http://", of: "http://",
with: "https://", with: "https://",
options: .caseInsensitive, options: .caseInsensitive,
@ -302,10 +302,10 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
// do nothing here // do nothing here
} else { } else {
// if a url does not start with http or https, try to add https // 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 { if case let .success(image) = result {
let indexPath = IndexPath(row: 0, section: 0) let indexPath = IndexPath(row: 0, section: 0)
self?.passwordImage = image self?.passwordImage = image

View file

@ -247,7 +247,7 @@ class PasswordEditorTableViewController: UITableViewController {
if selectedCell == deletePasswordCell { if selectedCell == deletePasswordCell {
let alert = UIAlertController(title: "DeletePassword?".localize(), message: nil, preferredStyle: UIAlertController.Style.alert) let alert = UIAlertController(title: "DeletePassword?".localize(), message: nil, preferredStyle: UIAlertController.Style.alert)
alert.addAction( 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) self.performSegue(withIdentifier: "deletePasswordSegue", sender: self)
} }
) )
@ -440,7 +440,7 @@ extension PasswordEditorTableViewController: SFSafariViewControllerDelegate {
message.append(Utils.attributedPassword(plainPassword: generatedPassword)) message.append(Utils.attributedPassword(plainPassword: generatedPassword))
alert.setValue(message, forKey: "attributedMessage") alert.setValue(message, forKey: "attributedMessage")
alert.addAction( 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 // update tableData so to make sure reloadData() works correctly
self.tableData[self.passwordSection][0][PasswordEditorCellKey.content] = generatedPassword self.tableData[self.passwordSection][0][PasswordEditorCellKey.content] = generatedPassword
// update cell manually, no need to call reloadData() // update cell manually, no need to call reloadData()

View file

@ -40,9 +40,7 @@ class PasswordNavigationViewController: UIViewController {
return uiSearchController return uiSearchController
}() }()
lazy var searchBar: UISearchBar = { lazy var searchBar: UISearchBar = self.searchController.searchBar
self.searchController.searchBar
}()
lazy var refreshControl: UIRefreshControl = { lazy var refreshControl: UIRefreshControl = {
let refreshControl = UIRefreshControl() let refreshControl = UIRefreshControl()

View file

@ -92,6 +92,6 @@ extension SSHKeyArmorImportTableViewController: KeyImporter {
} }
func importKeys() throws { func importKeys() throws {
try KeyFileManager.PrivateSsh.importKey(from: armorPrivateKey ?? "") try KeyFileManager.PrivateSSH.importKey(from: armorPrivateKey ?? "")
} }
} }

View file

@ -75,6 +75,6 @@ extension SSHKeyFileImportTableViewController: KeyImporter {
guard let privateKey = privateKey else { guard let privateKey = privateKey else {
return return
} }
try KeyFileManager.PrivateSsh.importKey(from: privateKey) try KeyFileManager.PrivateSSH.importKey(from: privateKey)
} }
} }

View file

@ -1,5 +1,5 @@
// //
// SSHKeyUrlImportTableViewController.swift // SSHKeyURLImportTableViewController.swift
// pass // pass
// //
// Created by Mingshen Sun on 25/1/2017. // Created by Mingshen Sun on 25/1/2017.
@ -9,7 +9,7 @@
import passKit import passKit
import SVProgressHUD import SVProgressHUD
class SSHKeyUrlImportTableViewController: AutoCellHeightUITableViewController { class SSHKeyURLImportTableViewController: AutoCellHeightUITableViewController {
@IBOutlet var privateKeyURLTextField: UITextField! @IBOutlet var privateKeyURLTextField: UITextField!
var sshPrivateKeyURL: URL? var sshPrivateKeyURL: URL?
@ -42,7 +42,7 @@ class SSHKeyUrlImportTableViewController: AutoCellHeightUITableViewController {
} }
} }
extension SSHKeyUrlImportTableViewController: KeyImporter { extension SSHKeyURLImportTableViewController: KeyImporter {
static let keySource = KeySource.url static let keySource = KeySource.url
static let label = "DownloadFromUrl".localize() static let label = "DownloadFromUrl".localize()
@ -60,6 +60,6 @@ extension SSHKeyUrlImportTableViewController: KeyImporter {
func importKeys() throws { func importKeys() throws {
Defaults.gitSSHPrivateKeyURL = sshPrivateKeyURL Defaults.gitSSHPrivateKeyURL = sshPrivateKeyURL
try KeyFileManager.PrivateSsh.importKey(from: Defaults.gitSSHPrivateKeyURL!) try KeyFileManager.PrivateSSH.importKey(from: Defaults.gitSSHPrivateKeyURL!)
} }
} }

View file

@ -150,7 +150,7 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
func showPGPKeyActionSheet() { func showPGPKeyActionSheet() {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
optionMenu.addAction( optionMenu.addAction(
UIAlertAction(title: PGPKeyUrlImportTableViewController.menuLabel, style: .default) { _ in UIAlertAction(title: PGPKeyURLImportTableViewController.menuLabel, style: .default) { _ in
self.performSegue(withIdentifier: "setPGPKeyByURLSegue", sender: self) self.performSegue(withIdentifier: "setPGPKeyByURLSegue", sender: self)
} }
) )
@ -184,8 +184,8 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
if Defaults.pgpKeySource != nil { if Defaults.pgpKeySource != nil {
optionMenu.addAction( optionMenu.addAction(
UIAlertAction(title: "RemovePgpKeys".localize(), style: .destructive) { _ in UIAlertAction(title: "RemovePgpKeys".localize(), style: .destructive) { _ in
self.keychain.removeContent(for: PgpKey.PUBLIC.getKeychainKey()) self.keychain.removeContent(for: PGPKey.PUBLIC.getKeychainKey())
self.keychain.removeContent(for: PgpKey.PRIVATE.getKeychainKey()) self.keychain.removeContent(for: PGPKey.PRIVATE.getKeychainKey())
PGPAgent.shared.uninitKeys() PGPAgent.shared.uninitKeys()
self.pgpKeyTableViewCell.detailTextLabel?.text = "NotSet".localize() self.pgpKeyTableViewCell.detailTextLabel?.text = "NotSet".localize()
Defaults.pgpKeySource = nil Defaults.pgpKeySource = nil
@ -240,19 +240,19 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
func setPasscodeLock() { func setPasscodeLock() {
// prepare the alert for setting the passcode // prepare the alert for setting the passcode
setPasscodeLockAlert = UIAlertController(title: "SetPasscode".localize(), message: "FillInAppPasscode.".localize(), preferredStyle: .alert) setPasscodeLockAlert = UIAlertController(title: "SetPasscode".localize(), message: "FillInAppPasscode.".localize(), preferredStyle: .alert)
setPasscodeLockAlert?.addTextField { textField -> Void in setPasscodeLockAlert?.addTextField { textField in
textField.placeholder = "Passcode".localize() textField.placeholder = "Passcode".localize()
textField.isSecureTextEntry = true 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 setPasscodeLockAlert?.addTextField { textField in
textField.placeholder = "PasswordConfirmation".localize() textField.placeholder = "PasswordConfirmation".localize()
textField.isSecureTextEntry = true 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 // 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! let passcode: String = self.setPasscodeLockAlert!.textFields![0].text!
self.passcodeLock.save(passcode: passcode) self.passcodeLock.save(passcode: passcode)
// refresh the passcode lock cell ("On") // refresh the passcode lock cell ("On")
@ -275,12 +275,12 @@ extension SettingsTableViewController: PGPKeyImporter {
static let label = "ITunesFileSharing".localize() static let label = "ITunesFileSharing".localize()
func isReadyToUse() -> Bool { func isReadyToUse() -> Bool {
KeyFileManager.PublicPgp.doesKeyFileExist() && KeyFileManager.PrivatePgp.doesKeyFileExist() KeyFileManager.PublicPGP.doesKeyFileExist() && KeyFileManager.PrivatePGP.doesKeyFileExist()
} }
func importKeys() throws { func importKeys() throws {
try KeyFileManager.PublicPgp.importKeyFromFileSharing() try KeyFileManager.PublicPGP.importKeyFromFileSharing()
try KeyFileManager.PrivatePgp.importKeyFromFileSharing() try KeyFileManager.PrivatePGP.importKeyFromFileSharing()
} }
func saveImportedKeys() { func saveImportedKeys() {

View file

@ -14,9 +14,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
PasscodeExtensionDisplay(extensionContext: extensionContext) PasscodeExtensionDisplay(extensionContext: extensionContext)
}() }()
private lazy var passwordsViewController: PasswordsViewController = { private lazy var passwordsViewController: PasswordsViewController = (children.first as! UINavigationController).viewControllers.first as! PasswordsViewController
(children.first as! UINavigationController).viewControllers.first as! PasswordsViewController
}()
private lazy var credentialProvider: CredentialProvider = { [unowned self] in private lazy var credentialProvider: CredentialProvider = { [unowned self] in
CredentialProvider(viewController: self, extensionContext: extensionContext, afterDecryption: NotificationCenterDispatcher.showOTPNotification) CredentialProvider(viewController: self, extensionContext: extensionContext, afterDecryption: NotificationCenterDispatcher.showOTPNotification)

View file

@ -27,9 +27,7 @@ class PasswordsViewController: UIViewController {
return uiSearchController return uiSearchController
}() }()
lazy var searchBar: UISearchBar = { lazy var searchBar: UISearchBar = self.searchController.searchBar
self.searchController.searchBar
}()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()

View file

@ -15,9 +15,7 @@ class ExtensionViewController: UIViewController {
PasscodeExtensionDisplay(extensionContext: extensionContext!) PasscodeExtensionDisplay(extensionContext: extensionContext!)
}() }()
private lazy var passwordsViewController: PasswordsViewController = { private lazy var passwordsViewController: PasswordsViewController = (children.first as! UINavigationController).viewControllers.first as! PasswordsViewController
(children.first as! UINavigationController).viewControllers.first as! PasswordsViewController
}()
private lazy var credentialProvider: CredentialProvider = { [unowned self] in private lazy var credentialProvider: CredentialProvider = { [unowned self] in
CredentialProvider(viewController: self, extensionContext: extensionContext!, afterDecryption: NotificationCenterDispatcher.showOTPNotification) CredentialProvider(viewController: self, extensionContext: extensionContext!, afterDecryption: NotificationCenterDispatcher.showOTPNotification)

View file

@ -189,7 +189,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
func forgotPasscodeButtonPressedAction(_: UIButton) { func forgotPasscodeButtonPressedAction(_: UIButton) {
let alert = UIAlertController(title: "ResetPass".localize(), message: "ResetPassExplanation.".localize(), preferredStyle: UIAlertController.Style.alert) let alert = UIAlertController(title: "ResetPass".localize(), message: "ResetPassExplanation.".localize(), preferredStyle: UIAlertController.Style.alert)
alert.addAction( 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() let myContext = LAContext()
// If the device passcode is not set, reset the app. // If the device passcode is not set, reset the app.
guard myContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil) else { guard myContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil) else {

View file

@ -46,7 +46,7 @@ struct GopenPGPInterface: PGPInterface {
func extractKeysFromArmored(str: String) -> [String] { func extractKeysFromArmored(str: String) -> [String] {
var keys: [String] = [] var keys: [String] = []
var key: String = "" var key = ""
for line in str.splitByNewline() { for line in str.splitByNewline() {
if line.trimmed.uppercased().hasPrefix("-----BEGIN PGP") { if line.trimmed.uppercased().hasPrefix("-----BEGIN PGP") {
key = "" key = ""
@ -100,7 +100,7 @@ struct GopenPGPInterface: PGPInterface {
throw AppError.decryption throw AppError.decryption
} }
let message = createPgpMessage(from: encryptedData) let message = createPGPMessage(from: encryptedData)
return try keyRing.decrypt(message, verifyKey: nil, verifyTime: 0).data return try keyRing.decrypt(message, verifyKey: nil, verifyTime: 0).data
} catch { } catch {
throw Self.errorMapping[error.localizedDescription, default: error] throw Self.errorMapping[error.localizedDescription, default: error]
@ -148,7 +148,7 @@ struct GopenPGPInterface: PGPInterface {
publicKeys.keys.map { $0.suffix(8).uppercased() } publicKeys.keys.map { $0.suffix(8).uppercased() }
} }
private func createPgpMessage(from encryptedData: Data) -> CryptoPGPMessage? { private func createPGPMessage(from encryptedData: Data) -> CryptoPGPMessage? {
// Important note: // Important note:
// Even if Defaults.encryptInArmored is true now, it could be different during the encryption. // Even if Defaults.encryptInArmored is true now, it could be different during the encryption.
var error: NSError? var error: NSError?

View file

@ -18,8 +18,8 @@ public class PGPAgent {
} }
public func initKeys() throws { public func initKeys() throws {
guard let publicKey: String = keyStore.get(for: PgpKey.PUBLIC.getKeychainKey()), guard let publicKey: String = keyStore.get(for: PGPKey.PUBLIC.getKeychainKey()),
let privateKey: String = keyStore.get(for: PgpKey.PRIVATE.getKeychainKey()) else { let privateKey: String = keyStore.get(for: PGPKey.PRIVATE.getKeychainKey()) else {
pgpInterface = nil pgpInterface = nil
throw AppError.keyImport throw AppError.keyImport
} }
@ -127,8 +127,8 @@ public class PGPAgent {
} }
public var isPrepared: Bool { public var isPrepared: Bool {
keyStore.contains(key: PgpKey.PUBLIC.getKeychainKey()) keyStore.contains(key: PGPKey.PUBLIC.getKeychainKey())
&& keyStore.contains(key: PgpKey.PRIVATE.getKeychainKey()) && keyStore.contains(key: PGPKey.PRIVATE.getKeychainKey())
} }
private func checkAndInit() throws { private func checkAndInit() throws {

View file

@ -11,7 +11,7 @@ public protocol CryptographicKey {
func getFileSharingPath() -> String func getFileSharingPath() -> String
} }
public enum PgpKey: CryptographicKey { public enum PGPKey: CryptographicKey {
case PUBLIC case PUBLIC
case PRIVATE case PRIVATE
@ -34,7 +34,7 @@ public enum PgpKey: CryptographicKey {
} }
} }
public enum SshKey: CryptographicKey { public enum SSHKey: CryptographicKey {
case PRIVATE case PRIVATE
public func getKeychainKey() -> String { public func getKeychainKey() -> String {

View file

@ -50,7 +50,9 @@ public extension FileManager {
let contentItemURL = item as! NSURL let contentItemURL = item as! NSURL
// Bail out on errors from the errorHandler. // 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 let resourceValueForKey: (URLResourceKey) throws -> NSNumber? = { key in
var value: AnyObject? var value: AnyObject?
@ -84,7 +86,9 @@ public extension FileManager {
} }
// Bail out on errors from the errorHandler. // Bail out on errors from the errorHandler.
if let error = errorDidOccur { throw error } if let error = errorDidOccur {
throw error
}
// We finally got it. // We finally got it.
return accumulatedSize return accumulatedSize

View file

@ -9,9 +9,9 @@
public class KeyFileManager { public class KeyFileManager {
public typealias KeyHandler = (String, String) -> Void public typealias KeyHandler = (String, String) -> Void
public static let PublicPgp = KeyFileManager(keyType: PgpKey.PUBLIC) public static let PublicPGP = KeyFileManager(keyType: PGPKey.PUBLIC)
public static let PrivatePgp = KeyFileManager(keyType: PgpKey.PRIVATE) public static let PrivatePGP = KeyFileManager(keyType: PGPKey.PRIVATE)
public static let PrivateSsh = KeyFileManager(keyType: SshKey.PRIVATE) public static let PrivateSSH = KeyFileManager(keyType: SSHKey.PRIVATE)
private let keyType: CryptographicKey private let keyType: CryptographicKey
private let keyPath: String private let keyPath: String

View file

@ -61,7 +61,7 @@ public struct GitCredential {
case .password: case .password:
return Self(credentialType: .http(userName: userName), keyStore: keyStore) return Self(credentialType: .http(userName: userName), keyStore: keyStore)
case .key: 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) return Self(credentialType: .ssh(userName: userName, privateKey: privateKey), keyStore: keyStore)
} }
} }

View file

@ -139,7 +139,7 @@ public class Password {
/// ///
/// otpauth://totp/totp-secret?secret=AAAAAAAAAAAAAAAA&issuer=totp-secret /// 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 /// 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. /// `TokenBuilder`. This means that tokens provided as otpauth have higher priority.
@ -150,7 +150,7 @@ public class Password {
if !otpauthString.hasPrefix("\(Constants.OTPAUTH):") { if !otpauthString.hasPrefix("\(Constants.OTPAUTH):") {
otpauthString = "\(Constants.OTPAUTH):\(otpauthString)" 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 otpToken = token
return return
} }

View file

@ -67,14 +67,14 @@ public class PasswordStore {
// Replace this implementation with code to handle the error appropriately. // 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. // 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:
Typical reasons for an error here include: //
* The parent directory does not exist, cannot be created, or disallows writing. // * 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 persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space. // * The device is out of space.
* The store could not be migrated to the current model version. // * The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was. //
*/ // Check the error message to determine what the actual problem was.
fatalError("UnresolvedError".localize("\(error.localizedDescription), \(error.userInfo)")) fatalError("UnresolvedError".localize("\(error.localizedDescription), \(error.userInfo)"))
} }
} }
@ -128,9 +128,9 @@ public class PasswordStore {
private func importExistingKeysIntoKeychain() { private func importExistingKeysIntoKeychain() {
// App Store update: v0.5.1 -> v0.6.0 // App Store update: v0.5.1 -> v0.6.0
try? KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyFromFileSharing() try? KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyFromFileSharing()
try? KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyFromFileSharing() try? KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyFromFileSharing()
try? KeyFileManager(keyType: SshKey.PRIVATE, keyPath: Globals.gitSSHPrivateKeyPath).importKeyFromFileSharing() try? KeyFileManager(keyType: SSHKey.PRIVATE, keyPath: Globals.gitSSHPrivateKeyPath).importKeyFromFileSharing()
Defaults.remove(\.pgpPublicKeyArmor) Defaults.remove(\.pgpPublicKeyArmor)
Defaults.remove(\.pgpPrivateKeyArmor) Defaults.remove(\.pgpPrivateKeyArmor)
Defaults.remove(\.gitSSHPrivateKeyArmor) Defaults.remove(\.gitSSHPrivateKeyArmor)
@ -733,7 +733,7 @@ public class PasswordStore {
Defaults.remove(\.gitSSHKeySource) Defaults.remove(\.gitSSHKeySource)
Defaults.remove(\.gitSSHPrivateKeyArmor) Defaults.remove(\.gitSSHPrivateKeyArmor)
Defaults.remove(\.gitSSHPrivateKeyURL) Defaults.remove(\.gitSSHPrivateKeyURL)
AppKeychain.shared.removeContent(for: SshKey.PRIVATE.getKeychainKey()) AppKeychain.shared.removeContent(for: SSHKey.PRIVATE.getKeychainKey())
gitSSHPrivateKeyPassphrase = nil gitSSHPrivateKeyPassphrase = nil
} }
} }

View file

@ -88,7 +88,7 @@ class PGPAgentTest: XCTestCase {
} }
func testNoPrivateKey() throws { 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) XCTAssertFalse(pgpAgent.isPrepared)
XCTAssertThrowsError(try pgpAgent.initKeys()) { XCTAssertThrowsError(try pgpAgent.initKeys()) {
XCTAssertEqual($0 as! AppError, AppError.keyImport) XCTAssertEqual($0 as! AppError, AppError.keyImport)
@ -126,8 +126,8 @@ class PGPAgentTest: XCTestCase {
try importKeys(ED25519.publicKey, ED25519.privateKey) try importKeys(ED25519.publicKey, ED25519.privateKey)
XCTAssert(pgpAgent.isPrepared) XCTAssert(pgpAgent.isPrepared)
XCTAssertEqual(try basicEncryptDecrypt(using: pgpAgent, keyID: ED25519.fingerprint), testData) XCTAssertEqual(try basicEncryptDecrypt(using: pgpAgent, keyID: ED25519.fingerprint), testData)
keychain.removeContent(for: PgpKey.PUBLIC.getKeychainKey()) keychain.removeContent(for: PGPKey.PUBLIC.getKeychainKey())
keychain.removeContent(for: PgpKey.PRIVATE.getKeychainKey()) keychain.removeContent(for: PGPKey.PRIVATE.getKeychainKey())
XCTAssertThrowsError(try basicEncryptDecrypt(using: pgpAgent, keyID: ED25519.fingerprint)) { XCTAssertThrowsError(try basicEncryptDecrypt(using: pgpAgent, keyID: ED25519.fingerprint)) {
XCTAssertEqual($0 as! AppError, AppError.keyImport) XCTAssertEqual($0 as! AppError, AppError.keyImport)
} }
@ -162,7 +162,7 @@ class PGPAgentTest: XCTestCase {
} }
private func importKeys(_ publicKey: String, _ privateKey: String) throws { private func importKeys(_ publicKey: String, _ privateKey: String) throws {
try KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: publicKey) 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.PRIVATE, keyPath: "", keyHandler: keychain.add).importKey(from: privateKey)
} }
} }

View file

@ -12,7 +12,7 @@ import XCTest
class KeyFileManagerTest: XCTestCase { class KeyFileManagerTest: XCTestCase {
private static let filePath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("test.txt").path 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() { override func tearDown() {
try? FileManager.default.removeItem(atPath: Self.filePath) try? FileManager.default.removeItem(atPath: Self.filePath)
@ -22,39 +22,39 @@ class KeyFileManagerTest: XCTestCase {
func testImportKeyFromFileSharing() throws { func testImportKeyFromFileSharing() throws {
let fileContent = "content".data(using: .ascii) let fileContent = "content".data(using: .ascii)
var storage: [String: String] = [:] 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) FileManager.default.createFile(atPath: Self.filePath, contents: fileContent, attributes: nil)
try keyFileManager.importKeyFromFileSharing() try keyFileManager.importKeyFromFileSharing()
XCTAssertFalse(FileManager.default.fileExists(atPath: Self.filePath)) XCTAssertFalse(FileManager.default.fileExists(atPath: Self.filePath))
XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], "content") XCTAssertEqual(storage[PGPKey.PRIVATE.getKeychainKey()], "content")
} }
func testErrorReadingFile() throws { func testErrorReadingFile() throws {
XCTAssertThrowsError(try Self.keyFileManager.importKeyFromFileSharing()) XCTAssertThrowsError(try Self.keyFileManager.importKeyFromFileSharing())
} }
func testImportKeyFromUrl() throws { func testImportKeyFromURL() throws {
let fileContent = "content".data(using: .ascii) let fileContent = "content".data(using: .ascii)
let url = URL(fileURLWithPath: Self.filePath) let url = URL(fileURLWithPath: Self.filePath)
var storage: [String: String] = [:] 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) FileManager.default.createFile(atPath: Self.filePath, contents: fileContent, attributes: nil)
try keyFileManager.importKey(from: url) try keyFileManager.importKey(from: url)
XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], "content") XCTAssertEqual(storage[PGPKey.PRIVATE.getKeychainKey()], "content")
} }
func testImportKeyFromString() throws { func testImportKeyFromString() throws {
let string = "content" let string = "content"
var storage: [String: String] = [:] 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) try keyFileManager.importKey(from: string)
XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], string) XCTAssertEqual(storage[PGPKey.PRIVATE.getKeychainKey()], string)
} }
func testImportKeyFromNonAsciiString() throws { func testImportKeyFromNonAsciiString() throws {

View file

@ -32,8 +32,8 @@ class PasswordStoreTest: XCTestCase {
} }
let keychain = AppKeychain.shared let keychain = AppKeychain.shared
try KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048_RSA4096.publicKeys) 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.PRIVATE, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048_RSA4096.privateKeys)
try PGPAgent.shared.initKeys() try PGPAgent.shared.initKeys()
let personal = try decrypt(passwordStore: passwordStore, path: "personal/github.com.gpg", passphrase: "passforios") let personal = try decrypt(passwordStore: passwordStore, path: "personal/github.com.gpg", passphrase: "passforios")

View file

@ -11,7 +11,7 @@ import XCTest
@testable import passKit @testable import passKit
class PasswordTest: XCTestCase { class PasswordTest: XCTestCase {
func testUrl() { func testURL() {
let password = getPasswordObjectWith(content: "") let password = getPasswordObjectWith(content: "")
XCTAssertEqual(password.url, PASSWORD_URL) XCTAssertEqual(password.url, PASSWORD_URL)

View file

@ -1,4 +1,4 @@
SWIFTFORMAT_VERSION="0.48.*" SWIFTFORMAT_VERSION="0.49.*"
if [[ "${CI}" == "true" ]]; then if [[ "${CI}" == "true" ]]; then
echo "Running in a Continuous Integration environment. Formatting is skipped." echo "Running in a Continuous Integration environment. Formatting is skipped."