Remove redundant 'else' blocks
This commit is contained in:
parent
ad4ed9419e
commit
1454693308
9 changed files with 22 additions and 57 deletions
|
|
@ -228,9 +228,8 @@ class PasswordEditorTableViewController: UITableViewController {
|
||||||
if section == passwordSection, hidePasswordSettings {
|
if section == passwordSection, hidePasswordSettings {
|
||||||
// hide the password section, only the password should be shown
|
// hide the password section, only the password should be shown
|
||||||
return 1
|
return 1
|
||||||
} else {
|
|
||||||
return tableData[section].count
|
|
||||||
}
|
}
|
||||||
|
return tableData[section].count
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
|
override func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||||
|
|
|
||||||
|
|
@ -102,9 +102,8 @@ class SettingsTableViewController: UITableViewController, UITabBarControllerDele
|
||||||
let gitURL = Defaults.gitURL
|
let gitURL = Defaults.gitURL
|
||||||
if gitURL.scheme == nil {
|
if gitURL.scheme == nil {
|
||||||
return URL(string: "scheme://" + gitURL.absoluteString)?.host
|
return URL(string: "scheme://" + gitURL.absoluteString)?.host
|
||||||
} else {
|
|
||||||
return gitURL.host
|
|
||||||
}
|
}
|
||||||
|
return gitURL.host
|
||||||
}()
|
}()
|
||||||
passwordRepositoryTableViewCell.detailTextLabel?.text = host
|
passwordRepositoryTableViewCell.detailTextLabel?.text = host
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,17 +81,15 @@ class LabelTableViewCell: UITableViewCell {
|
||||||
case .password:
|
case .password:
|
||||||
if isReveal {
|
if isReveal {
|
||||||
return action == #selector(copy(_:)) || action == #selector(concealPassword(_:))
|
return action == #selector(copy(_:)) || action == #selector(concealPassword(_:))
|
||||||
} else {
|
|
||||||
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(_:))
|
||||||
} else {
|
|
||||||
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(_:))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,7 @@ class PasswordsTableDataSource: NSObject, UITableViewDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func numberOfSections(in _: UITableView) -> Int {
|
func numberOfSections(in _: UITableView) -> Int {
|
||||||
if !showSuggestion {
|
!showSuggestion ? 1 : 2
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 2
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
|
func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
|
@ -40,16 +36,13 @@ class PasswordsTableDataSource: NSObject, UITableViewDataSource {
|
||||||
if suggestedPasswordsTableEntries.isEmpty {
|
if suggestedPasswordsTableEntries.isEmpty {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !showSuggestion {
|
if !showSuggestion {
|
||||||
return "All Passwords"
|
return "All Passwords"
|
||||||
}
|
}
|
||||||
|
|
||||||
if section == 0 {
|
if section == 0 {
|
||||||
return "Suggested Passwords"
|
return "Suggested Passwords"
|
||||||
} else {
|
|
||||||
return "Other Passwords"
|
|
||||||
}
|
}
|
||||||
|
return "Other Passwords"
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
@ -97,11 +90,9 @@ class PasswordsTableDataSource: NSObject, UITableViewDataSource {
|
||||||
if showSuggestion {
|
if showSuggestion {
|
||||||
if section == 0 {
|
if section == 0 {
|
||||||
return suggestedPasswordsTableEntries
|
return suggestedPasswordsTableEntries
|
||||||
} else {
|
}
|
||||||
return otherPasswordsTableEntries
|
return otherPasswordsTableEntries
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return filteredPasswordsTableEntries
|
return filteredPasswordsTableEntries
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,15 +100,13 @@ extension NSDictionary {
|
||||||
if let value = self[PassExtensionKey.URLStringKey] as? String {
|
if let value = self[PassExtensionKey.URLStringKey] as? String {
|
||||||
if let host = URL(string: value)?.host {
|
if let host = URL(string: value)?.host {
|
||||||
return host
|
return host
|
||||||
} else {
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
return value
|
||||||
} else if let value = self[NSExtensionJavaScriptPreprocessingResultsKey] as? String {
|
} else if let value = self[NSExtensionJavaScriptPreprocessingResultsKey] as? String {
|
||||||
if let host = URL(string: value)?.host {
|
if let host = URL(string: value)?.host {
|
||||||
return host
|
return host
|
||||||
} else {
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,9 +74,8 @@ struct GopenPGPInterface: PGPInterface {
|
||||||
let key: CryptoKey? = {
|
let key: CryptoKey? = {
|
||||||
if let keyID = keyID {
|
if let keyID = keyID {
|
||||||
return privateKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) })?.value
|
return privateKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) })?.value
|
||||||
} else {
|
|
||||||
return privateKeys.first?.value
|
|
||||||
}
|
}
|
||||||
|
return privateKeys.first?.value
|
||||||
}()
|
}()
|
||||||
|
|
||||||
guard let privateKey = key else {
|
guard let privateKey = key else {
|
||||||
|
|
@ -112,9 +111,8 @@ struct GopenPGPInterface: PGPInterface {
|
||||||
let key: CryptoKey? = {
|
let key: CryptoKey? = {
|
||||||
if let keyID = keyID {
|
if let keyID = keyID {
|
||||||
return publicKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) })?.value
|
return publicKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) })?.value
|
||||||
} else {
|
|
||||||
return publicKeys.first?.value
|
|
||||||
}
|
}
|
||||||
|
return publicKeys.first?.value
|
||||||
}()
|
}()
|
||||||
|
|
||||||
guard let publicKey = key else {
|
guard let publicKey = key else {
|
||||||
|
|
|
||||||
|
|
@ -13,32 +13,28 @@ extension UIView {
|
||||||
var safeTopAnchor: NSLayoutYAxisAnchor {
|
var safeTopAnchor: NSLayoutYAxisAnchor {
|
||||||
if #available(iOS 11.0, *) {
|
if #available(iOS 11.0, *) {
|
||||||
return self.safeAreaLayoutGuide.topAnchor
|
return self.safeAreaLayoutGuide.topAnchor
|
||||||
} else {
|
|
||||||
return topAnchor
|
|
||||||
}
|
}
|
||||||
|
return topAnchor
|
||||||
}
|
}
|
||||||
|
|
||||||
var safeLeftAnchor: NSLayoutXAxisAnchor {
|
var safeLeftAnchor: NSLayoutXAxisAnchor {
|
||||||
if #available(iOS 11.0, *) {
|
if #available(iOS 11.0, *) {
|
||||||
return self.safeAreaLayoutGuide.leftAnchor
|
return self.safeAreaLayoutGuide.leftAnchor
|
||||||
} else {
|
|
||||||
return leftAnchor
|
|
||||||
}
|
}
|
||||||
|
return leftAnchor
|
||||||
}
|
}
|
||||||
|
|
||||||
var safeRightAnchor: NSLayoutXAxisAnchor {
|
var safeRightAnchor: NSLayoutXAxisAnchor {
|
||||||
if #available(iOS 11.0, *) {
|
if #available(iOS 11.0, *) {
|
||||||
return self.safeAreaLayoutGuide.rightAnchor
|
return self.safeAreaLayoutGuide.rightAnchor
|
||||||
} else {
|
|
||||||
return rightAnchor
|
|
||||||
}
|
}
|
||||||
|
return rightAnchor
|
||||||
}
|
}
|
||||||
|
|
||||||
var safeBottomAnchor: NSLayoutYAxisAnchor {
|
var safeBottomAnchor: NSLayoutYAxisAnchor {
|
||||||
if #available(iOS 11.0, *) {
|
if #available(iOS 11.0, *) {
|
||||||
return self.safeAreaLayoutGuide.bottomAnchor
|
return self.safeAreaLayoutGuide.bottomAnchor
|
||||||
} else {
|
}
|
||||||
return bottomAnchor
|
return bottomAnchor
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,8 @@ public extension PasswordEntity {
|
||||||
if let path = path {
|
if let path = path {
|
||||||
if path.hasSuffix(".gpg") {
|
if path.hasSuffix(".gpg") {
|
||||||
return String(path.prefix(upTo: path.index(path.endIndex, offsetBy: -4)))
|
return String(path.prefix(upTo: path.index(path.endIndex, offsetBy: -4)))
|
||||||
} else {
|
|
||||||
return path
|
|
||||||
}
|
}
|
||||||
|
return path
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,12 +144,7 @@ public class PasswordStore {
|
||||||
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||||
do {
|
do {
|
||||||
passwordEntityFetchRequest.predicate = NSPredicate(format: "name = %@ and path = %@", password.name, password.url.path)
|
passwordEntityFetchRequest.predicate = NSPredicate(format: "name = %@ and path = %@", password.name, password.url.path)
|
||||||
let count = try context.count(for: passwordEntityFetchRequest)
|
return try context.count(for: passwordEntityFetchRequest) > 0
|
||||||
if count > 0 {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
fatalError("FailedToFetchPasswordEntities".localize(error))
|
fatalError("FailedToFetchPasswordEntities".localize(error))
|
||||||
}
|
}
|
||||||
|
|
@ -159,12 +154,7 @@ public class PasswordStore {
|
||||||
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||||
do {
|
do {
|
||||||
passwordEntityFetchRequest.predicate = NSPredicate(format: "path = %@", path)
|
passwordEntityFetchRequest.predicate = NSPredicate(format: "path = %@", path)
|
||||||
let count = try context.count(for: passwordEntityFetchRequest)
|
return try context.count(for: passwordEntityFetchRequest) > 0
|
||||||
if count > 0 {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
fatalError("FailedToFetchPasswordEntities".localize(error))
|
fatalError("FailedToFetchPasswordEntities".localize(error))
|
||||||
}
|
}
|
||||||
|
|
@ -704,9 +694,8 @@ public class PasswordStore {
|
||||||
if Defaults.isEnableGPGIDOn {
|
if Defaults.isEnableGPGIDOn {
|
||||||
let keyID = keyID ?? findGPGID(from: encryptedDataPath)
|
let keyID = keyID ?? findGPGID(from: encryptedDataPath)
|
||||||
return try PGPAgent.shared.decrypt(encryptedData: encryptedData, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
return try PGPAgent.shared.decrypt(encryptedData: encryptedData, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||||
} else {
|
|
||||||
return try PGPAgent.shared.decrypt(encryptedData: encryptedData, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
|
||||||
}
|
}
|
||||||
|
return try PGPAgent.shared.decrypt(encryptedData: encryptedData, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||||
}()
|
}()
|
||||||
guard let decryptedData = data else {
|
guard let decryptedData = data else {
|
||||||
throw AppError.decryption
|
throw AppError.decryption
|
||||||
|
|
@ -722,9 +711,8 @@ public class PasswordStore {
|
||||||
}
|
}
|
||||||
if Defaults.isEnableGPGIDOn {
|
if Defaults.isEnableGPGIDOn {
|
||||||
return try decrypt(passwordEntity: passwordEntity, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
return try decrypt(passwordEntity: passwordEntity, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||||
} else {
|
|
||||||
return try decrypt(passwordEntity: passwordEntity, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
|
||||||
}
|
}
|
||||||
|
return try decrypt(passwordEntity: passwordEntity, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encrypt(password: Password, keyID: String? = nil) throws -> Data {
|
public func encrypt(password: Password, keyID: String? = nil) throws -> Data {
|
||||||
|
|
@ -732,9 +720,8 @@ public class PasswordStore {
|
||||||
let keyID = keyID ?? findGPGID(from: encryptedDataPath)
|
let keyID = keyID ?? findGPGID(from: encryptedDataPath)
|
||||||
if Defaults.isEnableGPGIDOn {
|
if Defaults.isEnableGPGIDOn {
|
||||||
return try PGPAgent.shared.encrypt(plainData: password.plainData, keyID: keyID)
|
return try PGPAgent.shared.encrypt(plainData: password.plainData, keyID: keyID)
|
||||||
} else {
|
|
||||||
return try PGPAgent.shared.encrypt(plainData: password.plainData)
|
|
||||||
}
|
}
|
||||||
|
return try PGPAgent.shared.encrypt(plainData: password.plainData)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func removeGitSSHKeys() {
|
public func removeGitSSHKeys() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue