Skip to content

Commit

Permalink
Rename ignore .gpg-id switch to enalbe .gpg-id
Browse files Browse the repository at this point in the history
  • Loading branch information
mssun committed Jan 11, 2021
1 parent f539d2c commit b49593e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions pass/Controllers/GeneralSettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
return uiSwitch
}()

let ignoreGPGIDSwitch: UISwitch = {
let enableGPGIDSwitch: UISwitch = {
let uiSwitch = UISwitch()
uiSwitch.onTintColor = Colors.systemBlue
uiSwitch.sizeToFit()
uiSwitch.addTarget(self, action: #selector(ignoreGPGIDSwitchAction(_:)), for: UIControl.Event.valueChanged)
uiSwitch.isOn = Defaults.isIgnoreGPGIDOn
uiSwitch.addTarget(self, action: #selector(enableGPGIDSwitchAction(_:)), for: UIControl.Event.valueChanged)
uiSwitch.isOn = Defaults.isEnableGPGIDOn
return uiSwitch
}()

Expand Down Expand Up @@ -86,7 +86,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {

// section 2
[
[.title: "IgnoreGPGID".localize(), .action: "none"],
[.title: "EnableGPGID".localize(), .action: "none"],
[.title: "ShowFolders".localize(), .action: "none"],
[.title: "HidePasswordImages".localize(), .action: "none"],
[.title: "HideUnknownFields".localize(), .action: "none"],
Expand Down Expand Up @@ -139,10 +139,10 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
cell.accessoryType = .none
cell.selectionStyle = .none
cell.accessoryView = showFolderSwitch
case "IgnoreGPGID".localize():
case "EnableGPGID".localize():
cell.accessoryType = .none
cell.selectionStyle = .none
cell.accessoryView = ignoreGPGIDSwitch
cell.accessoryView = enableGPGIDSwitch
case "HidePasswordImages".localize():
cell.accessoryType = .none
let detailButton = UIButton(type: .detailDisclosure)
Expand Down Expand Up @@ -221,8 +221,8 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
}

@objc
func ignoreGPGIDSwitchAction(_: Any?) {
Defaults.isIgnoreGPGIDOn = ignoreGPGIDSwitch.isOn
func enableGPGIDSwitchAction(_: Any?) {
Defaults.isEnableGPGIDOn = enableGPGIDSwitch.isOn
}

@objc
Expand Down
2 changes: 1 addition & 1 deletion pass/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"PasswordGeneratorFlavor" = "Style";
"RememberPgpKeyPassphrase" = "Remember PGP Key Passphrase";
"RememberGitCredentialPassphrase" = "Remember Git Credential Passphrase";
"IgnoreGPGID" = "Ignore .gpg-id";
"EnableGPGID" = "Enable .gpg-id (Experiment)";
"ShowFolders" = "Show Folders";
"HidePasswordImages" = "Hide Password Images";
"HidePasswordImagesExplanation." = "Associated favicon images are loaded and shown based upon the URL associated with an entry. Enable this option to hide these images and prevent them from being loaded.";
Expand Down
2 changes: 1 addition & 1 deletion passKit/Helpers/DefaultsKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public extension DefaultsKeys {
var isHideOTPOn: DefaultsKey<Bool> { .init("isHideOTPOn", defaultValue: false) }
var isRememberPGPPassphraseOn: DefaultsKey<Bool> { .init("isRememberPGPPassphraseOn", defaultValue: false) }
var isRememberGitCredentialPassphraseOn: DefaultsKey<Bool> { .init("isRememberGitCredentialPassphraseOn", defaultValue: false) }
var isIgnoreGPGIDOn: DefaultsKey<Bool> { .init("isIgnoreGPGIDOn", defaultValue: true) }
var isEnableGPGIDOn: DefaultsKey<Bool> { .init("isEnableGPGIDOn", defaultValue: false) }
var isShowFolderOn: DefaultsKey<Bool> { .init("isShowFolderOn", defaultValue: true) }
var isHidePasswordImagesOn: DefaultsKey<Bool> { .init("isHidePasswordImagesOn", defaultValue: false) }
var searchDefault: DefaultsKey<SearchBarScope?> { .init("searchDefault", defaultValue: .all) }
Expand Down
18 changes: 9 additions & 9 deletions passKit/Models/PasswordStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,11 @@ public class PasswordStore {
let encryptedDataPath = storeURL.appendingPathComponent(passwordEntity.getPath())
let encryptedData = try Data(contentsOf: encryptedDataPath)
let data: Data? = try {
if Defaults.isIgnoreGPGIDOn {
return try PGPAgent.shared.decrypt(encryptedData: encryptedData, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
} else {
if Defaults.isEnableGPGIDOn {
let keyID = keyID ?? findGPGID(from: encryptedDataPath)
return try PGPAgent.shared.decrypt(encryptedData: encryptedData, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
} else {
return try PGPAgent.shared.decrypt(encryptedData: encryptedData, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
}
}()
guard let decryptedData = data else {
Expand All @@ -710,20 +710,20 @@ public class PasswordStore {
guard let passwordEntity = fetchPasswordEntity(with: path) else {
throw AppError.decryption
}
if Defaults.isIgnoreGPGIDOn {
return try decrypt(passwordEntity: passwordEntity, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
} else {
if Defaults.isEnableGPGIDOn {
return try decrypt(passwordEntity: passwordEntity, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
} else {
return try decrypt(passwordEntity: passwordEntity, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
}
}

public func encrypt(password: Password, keyID: String? = nil) throws -> Data {
let encryptedDataPath = storeURL.appendingPathComponent(password.url.path)
let keyID = keyID ?? findGPGID(from: encryptedDataPath)
if Defaults.isIgnoreGPGIDOn {
return try PGPAgent.shared.encrypt(plainData: password.plainData)
} else {
if Defaults.isEnableGPGIDOn {
return try PGPAgent.shared.encrypt(plainData: password.plainData, keyID: keyID)
} else {
return try PGPAgent.shared.encrypt(plainData: password.plainData)
}
}

Expand Down
4 changes: 2 additions & 2 deletions passKitTests/Models/PasswordStoreTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PasswordStoreTest: XCTestCase {

func testCloneAndDecryptMultiKeys() throws {
let url = URL(fileURLWithPath: "\(Globals.repositoryPath)-test")
Defaults.isIgnoreGPGIDOn = false
Defaults.isEnableGPGIDOn = true
let passwordStore = PasswordStore(url: url)
try passwordStore.cloneRepository(remoteRepoURL: remoteRepoURL, branchName: "master")
expectation(for: NSPredicate { _, _ in FileManager.default.fileExists(atPath: url.path) }, evaluatedWith: nil)
Expand Down Expand Up @@ -47,7 +47,7 @@ class PasswordStoreTest: XCTestCase {
XCTAssertEqual(testPasswordPlain.plainText, "testpassword")

passwordStore.erase()
Defaults.isIgnoreGPGIDOn = true
Defaults.isEnableGPGIDOn = false
}

private func decrypt(passwordStore: PasswordStore, path: String, passphrase _: String) throws -> Password {
Expand Down

0 comments on commit b49593e

Please sign in to comment.