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
--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

View file

@ -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 = "<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>"; };
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; };
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>"; };
@ -472,7 +472,7 @@
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>"; };
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>"; };
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>"; };
@ -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 = "<group>";
@ -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 */,

View file

@ -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)"))
}
}

View file

@ -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()

View file

@ -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()
}
}

View file

@ -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() {

View file

@ -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() {

View file

@ -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
}

View file

@ -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

View file

@ -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()

View file

@ -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()

View file

@ -92,6 +92,6 @@ extension SSHKeyArmorImportTableViewController: KeyImporter {
}
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 {
return
}
try KeyFileManager.PrivateSsh.importKey(from: privateKey)
try KeyFileManager.PrivateSSH.importKey(from: privateKey)
}
}

View file

@ -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!)
}
}

View file

@ -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() {

View file

@ -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)

View file

@ -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()

View file

@ -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)

View file

@ -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 {

View file

@ -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?

View file

@ -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 {

View file

@ -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 {

View file

@ -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

View file

@ -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

View file

@ -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)
}
}

View file

@ -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
}

View file

@ -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
}
}

View file

@ -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)
}
}

View file

@ -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 {

View file

@ -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")

View file

@ -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)

View file

@ -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."