Some cleanup especially regarding method references (#516)

* Remove superfluous method arguments in method references

* Use 'Self' for internal static access

* Convert static to instance field in singleton class

* Remove class name prefix in references to local methods

* Remove nested frameworks in all extensions and frameworks
This commit is contained in:
Danny Mösch 2021-10-03 05:46:07 +02:00 committed by GitHub
parent e1cbcb5d7a
commit 32b7c9b635
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 57 additions and 57 deletions

View file

@ -1463,7 +1463,7 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nset -xe\nrm -rf ${BUILT_PRODUCTS_DIR}/passKit.framework/Frameworks\nfind -L ${BUILT_PRODUCTS_DIR}/OneTimePassword_*.framework -type d -name \"Frameworks\" | xargs rm -rf\nfind -L ${BUILT_PRODUCTS_DIR}/passAutoFillExtension.appex -type d -name \"Frameworks\" | xargs rm -rf\nfind -L ${BUILT_PRODUCTS_DIR}/passShortcuts.appex -type d -name \"Frameworks\" | xargs rm -rf\n\n"; shellScript = "set -xe\n\nfind -L \"${BUILT_PRODUCTS_DIR}\" -type d -path \"*.appex/Frameworks\" -o -path \"*.framework/Frameworks\" -maxdepth 2 | xargs rm -rf\n";
}; };
/* End PBXShellScriptBuildPhase section */ /* End PBXShellScriptBuildPhase section */

View file

@ -100,7 +100,7 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
if let numberOfCommits = passwordStore.numberOfCommits { if let numberOfCommits = passwordStore.numberOfCommits {
return String(numberOfCommits) return String(numberOfCommits)
} }
return AboutRepositoryTableViewController.VALUE_NOT_AVAILABLE return Self.VALUE_NOT_AVAILABLE
} }
@objc @objc

View file

@ -21,7 +21,7 @@ class AdvancedSettingsTableViewController: UITableViewController {
let uiSwitch = UISwitch() let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit() uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(encryptInASCIIArmoredAction(_:)), for: UIControl.Event.valueChanged) uiSwitch.addTarget(self, action: #selector(encryptInASCIIArmoredAction), for: UIControl.Event.valueChanged)
return uiSwitch return uiSwitch
}() }()

View file

@ -16,7 +16,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let uiSwitch = UISwitch() let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit() uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(hideUnknownSwitchAction(_:)), for: UIControl.Event.valueChanged) uiSwitch.addTarget(self, action: #selector(hideUnknownSwitchAction), for: UIControl.Event.valueChanged)
return uiSwitch return uiSwitch
}() }()
@ -24,7 +24,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let uiSwitch = UISwitch() let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit() uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(hideOTPSwitchAction(_:)), for: UIControl.Event.valueChanged) uiSwitch.addTarget(self, action: #selector(hideOTPSwitchAction), for: UIControl.Event.valueChanged)
return uiSwitch return uiSwitch
}() }()
@ -32,7 +32,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let uiSwitch = UISwitch() let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit() uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(autoCopyOTPSwitchAction(_:)), for: UIControl.Event.valueChanged) uiSwitch.addTarget(self, action: #selector(autoCopyOTPSwitchAction), for: UIControl.Event.valueChanged)
return uiSwitch return uiSwitch
}() }()
@ -40,7 +40,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let uiSwitch = UISwitch() let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit() uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(rememberPGPPassphraseSwitchAction(_:)), for: UIControl.Event.valueChanged) uiSwitch.addTarget(self, action: #selector(rememberPGPPassphraseSwitchAction), for: UIControl.Event.valueChanged)
uiSwitch.isOn = Defaults.isRememberPGPPassphraseOn uiSwitch.isOn = Defaults.isRememberPGPPassphraseOn
return uiSwitch return uiSwitch
}() }()
@ -49,7 +49,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let uiSwitch = UISwitch() let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit() uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(rememberGitCredentialPassphraseSwitchAction(_:)), for: UIControl.Event.valueChanged) uiSwitch.addTarget(self, action: #selector(rememberGitCredentialPassphraseSwitchAction), for: UIControl.Event.valueChanged)
uiSwitch.isOn = Defaults.isRememberGitCredentialPassphraseOn uiSwitch.isOn = Defaults.isRememberGitCredentialPassphraseOn
return uiSwitch return uiSwitch
}() }()
@ -58,7 +58,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let uiSwitch = UISwitch() let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit() uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(enableGPGIDSwitchAction(_:)), for: UIControl.Event.valueChanged) uiSwitch.addTarget(self, action: #selector(enableGPGIDSwitchAction), for: UIControl.Event.valueChanged)
uiSwitch.isOn = Defaults.isEnableGPGIDOn uiSwitch.isOn = Defaults.isEnableGPGIDOn
return uiSwitch return uiSwitch
}() }()
@ -67,7 +67,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let uiSwitch = UISwitch() let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit() uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(showFolderSwitchAction(_:)), for: UIControl.Event.valueChanged) uiSwitch.addTarget(self, action: #selector(showFolderSwitchAction), for: UIControl.Event.valueChanged)
uiSwitch.isOn = Defaults.isShowFolderOn uiSwitch.isOn = Defaults.isShowFolderOn
return uiSwitch return uiSwitch
}() }()
@ -76,7 +76,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
let uiSwitch = UISwitch() let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit() uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(hidePasswordImagesSwitchAction(_:)), for: UIControl.Event.valueChanged) uiSwitch.addTarget(self, action: #selector(hidePasswordImagesSwitchAction), for: UIControl.Event.valueChanged)
uiSwitch.isOn = Defaults.isHidePasswordImagesOn uiSwitch.isOn = Defaults.isHidePasswordImagesOn
return uiSwitch return uiSwitch
}() }()

View file

@ -68,7 +68,7 @@ class OpenSourceComponentsTableViewController: BasicStaticTableViewController {
.action: "link", .action: "link",
.link: item[1], .link: item[1],
.accessoryType: UITableViewCell.AccessoryType.detailDisclosureButton, .accessoryType: UITableViewCell.AccessoryType.detailDisclosureButton,
.detailDisclosureAction: #selector(actOnDetailDisclosureButton(_:)), .detailDisclosureAction: #selector(actOnDetailDisclosureButton),
.detailDisclosureData: item[2], .detailDisclosureData: item[2],
] ]
) )

View file

@ -21,7 +21,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
private let keychain = AppKeychain.shared private let keychain = AppKeychain.shared
private lazy var editUIBarButtonItem: UIBarButtonItem = { private lazy var editUIBarButtonItem: UIBarButtonItem = {
let uiBarButtonItem = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(pressEdit(_:))) let uiBarButtonItem = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(pressEdit))
return uiBarButtonItem return uiBarButtonItem
}() }()
@ -47,7 +47,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
tableView.register(UINib(nibName: "LabelTableViewCell", bundle: nil), forCellReuseIdentifier: "labelCell") tableView.register(UINib(nibName: "LabelTableViewCell", bundle: nil), forCellReuseIdentifier: "labelCell")
tableView.register(UINib(nibName: "PasswordDetailTitleTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordDetailTitleTableViewCell") tableView.register(UINib(nibName: "PasswordDetailTitleTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordDetailTitleTableViewCell")
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PasswordDetailTableViewController.tapMenu(recognizer:))) let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapMenu))
tapGesture.cancelsTouchesInView = false tapGesture.cancelsTouchesInView = false
tableView.addGestureRecognizer(tapGesture) tableView.addGestureRecognizer(tapGesture)
tapGesture.delegate = self tapGesture.delegate = self
@ -326,10 +326,10 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
if let tappedCell = tableView.cellForRow(at: tapIndexPath) as? LabelTableViewCell { if let tappedCell = tableView.cellForRow(at: tapIndexPath) as? LabelTableViewCell {
tappedCell.becomeFirstResponder() tappedCell.becomeFirstResponder()
let menuController = UIMenuController.shared let menuController = UIMenuController.shared
let revealItem = UIMenuItem(title: "Reveal".localize(), action: #selector(LabelTableViewCell.revealPassword(_:))) let revealItem = UIMenuItem(title: "Reveal".localize(), action: #selector(LabelTableViewCell.revealPassword))
let concealItem = UIMenuItem(title: "Conceal".localize(), action: #selector(LabelTableViewCell.concealPassword(_:))) let concealItem = UIMenuItem(title: "Conceal".localize(), action: #selector(LabelTableViewCell.concealPassword))
let nextHOTPItem = UIMenuItem(title: "NextPassword".localize(), action: #selector(LabelTableViewCell.getNextHOTP(_:))) let nextHOTPItem = UIMenuItem(title: "NextPassword".localize(), action: #selector(LabelTableViewCell.getNextHOTP))
let openURLItem = UIMenuItem(title: "CopyAndOpen".localize(), action: #selector(LabelTableViewCell.openLink(_:))) let openURLItem = UIMenuItem(title: "CopyAndOpen".localize(), action: #selector(LabelTableViewCell.openLink))
menuController.menuItems = [revealItem, concealItem, nextHOTPItem, openURLItem] menuController.menuItems = [revealItem, concealItem, nextHOTPItem, openURLItem]
menuController.setTargetRect(tappedCell.contentLabel.frame, in: tappedCell.contentLabel.superview!) menuController.setTargetRect(tappedCell.contentLabel.frame, in: tappedCell.contentLabel.superview!)
menuController.setMenuVisible(true, animated: true) menuController.setMenuVisible(true, animated: true)
@ -490,7 +490,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
let section = tableData[indexPath.section] let section = tableData[indexPath.section]
switch section.type { switch section.type {
case .addition, .main: case .addition, .main:
return action == #selector(UIResponderStandardEditActions.copy(_:)) return action == #selector(UIResponderStandardEditActions.copy)
default: default:
return false return false
} }

View file

@ -56,10 +56,10 @@ class PasswordNavigationViewController: UIViewController {
let addPasswordButton = UIButton(type: .system) let addPasswordButton = UIButton(type: .system)
let plusImage = UIImage(systemName: "plus.circle", withConfiguration: UIImage.SymbolConfiguration(weight: .regular)) let plusImage = UIImage(systemName: "plus.circle", withConfiguration: UIImage.SymbolConfiguration(weight: .regular))
addPasswordButton.setImage(plusImage, for: .normal) addPasswordButton.setImage(plusImage, for: .normal)
addPasswordButton.addTarget(self, action: #selector(self.addPasswordAction(_:)), for: .touchDown) addPasswordButton.addTarget(self, action: #selector(self.addPasswordAction), for: .touchDown)
addPasswordUIBarButtonItem.customView = addPasswordButton addPasswordUIBarButtonItem.customView = addPasswordButton
} else { } else {
addPasswordUIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(self.addPasswordAction(_:))) addPasswordUIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(self.addPasswordAction))
} }
return addPasswordUIBarButtonItem return addPasswordUIBarButtonItem
}() }()

View file

@ -66,7 +66,7 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(SettingsTableViewController.actOnPasswordStoreErasedNotification), name: .passwordStoreErased, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(actOnPasswordStoreErasedNotification), name: .passwordStoreErased, object: nil)
passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults.gitURL.host passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults.gitURL.host
setPGPKeyTableViewCellDetailText() setPGPKeyTableViewCellDetailText()
setPasscodeLockCell() setPasscodeLockCell()
@ -243,12 +243,12 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
setPasscodeLockAlert?.addTextField { textField -> Void in setPasscodeLockAlert?.addTextField { textField -> Void 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 -> Void 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

View file

@ -80,16 +80,16 @@ class LabelTableViewCell: UITableViewCell {
switch type { switch type {
case .password: case .password:
if isReveal { if isReveal {
return action == #selector(copy(_:)) || action == #selector(concealPassword(_:)) return action == #selector(copy(_:)) || action == #selector(concealPassword)
} }
return action == #selector(copy(_:)) || action == #selector(revealPassword(_:)) return action == #selector(copy(_:)) || action == #selector(revealPassword)
case .URL: case .URL:
return action == #selector(copy(_:)) || action == #selector(openLink(_:)) return action == #selector(copy(_:)) || action == #selector(openLink)
case .HOTP: case .HOTP:
if isReveal { if isReveal {
return action == #selector(copy(_:)) || action == #selector(concealPassword(_:)) || action == #selector(getNextHOTP(_:)) return action == #selector(copy(_:)) || action == #selector(concealPassword) || action == #selector(getNextHOTP)
} }
return action == #selector(copy(_:)) || action == #selector(revealPassword(_:)) || action == #selector(getNextHOTP(_:)) return action == #selector(copy(_:)) || action == #selector(revealPassword) || action == #selector(getNextHOTP)
default: default:
return action == #selector(copy(_:)) return action == #selector(copy(_:))
} }

View file

@ -31,13 +31,13 @@ class UICodeHighlightingLabel: UILocalizedLabel {
let formattedText = text.splitByNewline() let formattedText = text.splitByNewline()
.map { line -> NSAttributedString in .map { line -> NSAttributedString in
if line.starts(with: " ") { if line.starts(with: " ") {
return NSAttributedString(string: line, attributes: UICodeHighlightingLabel.CODE_ATTRIBUTES) return NSAttributedString(string: line, attributes: Self.CODE_ATTRIBUTES)
} }
return NSAttributedString(string: line) return NSAttributedString(string: line)
} }
.reduce(into: NSMutableAttributedString(string: "")) { .reduce(into: NSMutableAttributedString(string: "")) {
$0.append($1) $0.append($1)
$0.append(UICodeHighlightingLabel.ATTRIBUTED_NEWLINE) $0.append(Self.ATTRIBUTED_NEWLINE)
} }
formattedText.deleteCharacters(in: NSRange(location: formattedText.length - 1, length: 1)) formattedText.deleteCharacters(in: NSRange(location: formattedText.length - 1, length: 1))
return formattedText return formattedText

View file

@ -23,7 +23,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
}() }()
private lazy var passwordsTableEntries = PasswordStore.shared.fetchPasswordEntityCoreData(withDir: false) private lazy var passwordsTableEntries = PasswordStore.shared.fetchPasswordEntityCoreData(withDir: false)
.map(PasswordTableEntry.init(_:)) .map(PasswordTableEntry.init)
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -44,7 +44,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
self.credentialProvider.identifier = serviceIdentifiers.first self.credentialProvider.identifier = serviceIdentifiers.first
let url = serviceIdentifiers.first let url = serviceIdentifiers.first
.map(\.identifier) .map(\.identifier)
.flatMap(URL.init(string:)) .flatMap(URL.init)
self.passwordsViewController.navigationItem.prompt = url?.host self.passwordsViewController.navigationItem.prompt = url?.host
self.passwordsViewController.showPasswordsWithSuggestion(matching: url?.host ?? "") self.passwordsViewController.showPasswordsWithSuggestion(matching: url?.host ?? "")
} }

View file

@ -24,7 +24,7 @@ class ExtensionViewController: UIViewController {
}() }()
private lazy var passwordsTableEntries = PasswordStore.shared.fetchPasswordEntityCoreData(withDir: false) private lazy var passwordsTableEntries = PasswordStore.shared.fetchPasswordEntityCoreData(withDir: false)
.map(PasswordTableEntry.init(_:)) .map(PasswordTableEntry.init)
enum Action { enum Action {
case findLogin, fillBrowser, unknown case findLogin, fillBrowser, unknown

View file

@ -34,7 +34,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
passcodeTextField.isSecureTextEntry = true passcodeTextField.isSecureTextEntry = true
passcodeTextField.clearButtonMode = UITextField.ViewMode.whileEditing passcodeTextField.clearButtonMode = UITextField.ViewMode.whileEditing
passcodeTextField.delegate = self passcodeTextField.delegate = self
passcodeTextField.addTarget(self, action: #selector(passcodeTextFieldDidChange(_:)), for: UIControl.Event.editingChanged) passcodeTextField.addTarget(self, action: #selector(passcodeTextFieldDidChange), for: UIControl.Event.editingChanged)
passcodeTextField.translatesAutoresizingMaskIntoConstraints = false passcodeTextField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(passcodeTextField) view.addSubview(passcodeTextField)
self.passcodeTextField = passcodeTextField self.passcodeTextField = passcodeTextField
@ -46,7 +46,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
let biometryAuthButton = UIButton(type: .custom) let biometryAuthButton = UIButton(type: .custom)
biometryAuthButton.setTitle("", for: .normal) biometryAuthButton.setTitle("", for: .normal)
biometryAuthButton.setTitleColor(Colors.systemBlue, for: .normal) biometryAuthButton.setTitleColor(Colors.systemBlue, for: .normal)
biometryAuthButton.addTarget(self, action: #selector(bioButtonPressedAction(_:)), for: .touchUpInside) biometryAuthButton.addTarget(self, action: #selector(bioButtonPressedAction), for: .touchUpInside)
biometryAuthButton.isHidden = true biometryAuthButton.isHidden = true
biometryAuthButton.translatesAutoresizingMaskIntoConstraints = false biometryAuthButton.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(biometryAuthButton) view.addSubview(biometryAuthButton)
@ -68,7 +68,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
forgotPasscodeButton.setTitle("ForgotYourPasscode?".localize(), for: .normal) forgotPasscodeButton.setTitle("ForgotYourPasscode?".localize(), for: .normal)
forgotPasscodeButton.titleLabel?.font = UIFont.systemFont(ofSize: UIFont.systemFontSize) forgotPasscodeButton.titleLabel?.font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
forgotPasscodeButton.setTitleColor(Colors.systemBlue, for: .normal) forgotPasscodeButton.setTitleColor(Colors.systemBlue, for: .normal)
forgotPasscodeButton.addTarget(self, action: #selector(forgotPasscodeButtonPressedAction(_:)), for: .touchUpInside) forgotPasscodeButton.addTarget(self, action: #selector(forgotPasscodeButtonPressedAction), for: .touchUpInside)
// hide the forgotPasscodeButton if the native app is running // hide the forgotPasscodeButton if the native app is running
forgotPasscodeButton.isHidden = isCancellable forgotPasscodeButton.isHidden = isCancellable
forgotPasscodeButton.translatesAutoresizingMaskIntoConstraints = false forgotPasscodeButton.translatesAutoresizingMaskIntoConstraints = false

View file

@ -9,10 +9,10 @@
public class PasscodeLock { public class PasscodeLock {
public static let shared = PasscodeLock() public static let shared = PasscodeLock()
private static let identifier = Globals.bundleIdentifier + "passcode" private let identifier = Globals.bundleIdentifier + "passcode"
private var passcode: String? { private var passcode: String? {
AppKeychain.shared.get(for: PasscodeLock.identifier) AppKeychain.shared.get(for: identifier)
} }
/// Constructor used to migrate passcode from SharedDefaults to Keychain /// Constructor used to migrate passcode from SharedDefaults to Keychain
@ -28,7 +28,7 @@ public class PasscodeLock {
} }
public func save(passcode: String) { public func save(passcode: String) {
AppKeychain.shared.add(string: passcode, for: PasscodeLock.identifier) AppKeychain.shared.add(string: passcode, for: identifier)
} }
public func check(passcode: String) -> Bool { public func check(passcode: String) -> Bool {
@ -36,6 +36,6 @@ public class PasscodeLock {
} }
public func delete() { public func delete() {
AppKeychain.shared.removeContent(for: PasscodeLock.identifier) AppKeychain.shared.removeContent(for: identifier)
} }
} }

View file

@ -380,7 +380,7 @@ public class PasswordStore {
if Date().timeIntervalSince(lastCommitDate) <= 60 { if Date().timeIntervalSince(lastCommitDate) <= 60 {
return "JustNow".localize() return "JustNow".localize()
} }
return PasswordStore.dateFormatter.string(from: lastCommitDate) return Self.dateFormatter.string(from: lastCommitDate)
} }
public func updateRemoteRepo() {} public func updateRemoteRepo() {}

View file

@ -24,7 +24,7 @@ public class PasswordTableEntry: NSObject {
} }
public func matches(_ searchText: String) -> Bool { public func matches(_ searchText: String) -> Bool {
PasswordTableEntry.match(nameWithCategory: passwordEntity.nameWithCategory, searchText: searchText) Self.match(nameWithCategory: passwordEntity.nameWithCategory, searchText: searchText)
} }
public static func match(nameWithCategory: String, searchText: String) -> Bool { public static func match(nameWithCategory: String, searchText: String) -> Bool {

View file

@ -29,7 +29,7 @@ class Parser {
while lineNumber < purgedAdditionalLines.count { while lineNumber < purgedAdditionalLines.count {
let line = purgedAdditionalLines[lineNumber] let line = purgedAdditionalLines[lineNumber]
lineNumber += 1 lineNumber += 1
var (key, value) = Parser.getKeyValuePair(from: line) var (key, value) = Self.getKeyValuePair(from: line)
if key == nil { if key == nil {
unknownIndex += 1 unknownIndex += 1
key = Constants.unknown(unknownIndex) key = Constants.unknown(unknownIndex)

View file

@ -15,33 +15,33 @@ class KeyFileManagerTest: XCTestCase {
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: KeyFileManagerTest.filePath) try? FileManager.default.removeItem(atPath: Self.filePath)
super.tearDown() super.tearDown()
} }
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: KeyFileManagerTest.filePath) { storage[$1] = $0 } let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 }
FileManager.default.createFile(atPath: KeyFileManagerTest.filePath, contents: fileContent, attributes: nil) FileManager.default.createFile(atPath: Self.filePath, contents: fileContent, attributes: nil)
try keyFileManager.importKeyFromFileSharing() try keyFileManager.importKeyFromFileSharing()
XCTAssertFalse(FileManager.default.fileExists(atPath: KeyFileManagerTest.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 KeyFileManagerTest.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: KeyFileManagerTest.filePath) let url = URL(fileURLWithPath: Self.filePath)
var storage: [String: String] = [:] var storage: [String: String] = [:]
let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: KeyFileManagerTest.filePath) { storage[$1] = $0 } let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Self.filePath) { storage[$1] = $0 }
FileManager.default.createFile(atPath: KeyFileManagerTest.filePath, contents: fileContent, attributes: nil) FileManager.default.createFile(atPath: Self.filePath, contents: fileContent, attributes: nil)
try keyFileManager.importKey(from: url) try keyFileManager.importKey(from: url)
XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], "content") XCTAssertEqual(storage[PgpKey.PRIVATE.getKeychainKey()], "content")
@ -50,7 +50,7 @@ class KeyFileManagerTest: XCTestCase {
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: KeyFileManagerTest.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)
@ -58,18 +58,18 @@ class KeyFileManagerTest: XCTestCase {
} }
func testImportKeyFromNonAsciiString() throws { func testImportKeyFromNonAsciiString() throws {
XCTAssertThrowsError(try KeyFileManagerTest.keyFileManager.importKey(from: "")) { XCTAssertThrowsError(try Self.keyFileManager.importKey(from: "")) {
XCTAssertEqual($0 as! AppError, AppError.encoding) XCTAssertEqual($0 as! AppError, AppError.encoding)
} }
} }
func testFileExists() { func testFileExists() {
FileManager.default.createFile(atPath: KeyFileManagerTest.filePath, contents: nil, attributes: nil) FileManager.default.createFile(atPath: Self.filePath, contents: nil, attributes: nil)
XCTAssertTrue(KeyFileManagerTest.keyFileManager.doesKeyFileExist()) XCTAssertTrue(Self.keyFileManager.doesKeyFileExist())
} }
func testFileDoesNotExist() { func testFileDoesNotExist() {
XCTAssertFalse(KeyFileManagerTest.keyFileManager.doesKeyFileExist()) XCTAssertFalse(Self.keyFileManager.doesKeyFileExist())
} }
} }