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