Ask to save passphrase while setting PGP keys through URLs

This commit is contained in:
Yishi Lin 2017-04-08 23:51:43 +08:00
parent 665746f962
commit bef9e0251c
3 changed files with 66 additions and 51 deletions

View file

@ -22,12 +22,9 @@ class PGPKeyArmorSettingTableViewController: UITableViewController, UITextViewDe
armorPublicKeyTextView.text = Defaults[.pgpPublicKeyArmor]
armorPrivateKeyTextView.text = Defaults[.pgpPrivateKeyArmor]
pgpPassphrase = passwordStore.pgpKeyPassphrase
armorPublicKeyTextView.delegate = self
armorPrivateKeyTextView.delegate = self
}
private func createSavePassphraseAlert() -> UIAlertController {
private func createSavePassphraseAndSegueAlert() -> UIAlertController {
let savePassphraseAlert = UIAlertController(title: "Passphrase", message: "Do you want to save the passphrase for later decryption?", preferredStyle: UIAlertControllerStyle.alert)
savePassphraseAlert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.default) { _ in
Defaults[.isRememberPassphraseOn] = false
@ -44,8 +41,8 @@ class PGPKeyArmorSettingTableViewController: UITableViewController, UITextViewDe
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
self.pgpPassphrase = alert.textFields?.first?.text
let savePassphraseAlert = self.createSavePassphraseAlert()
self.present(savePassphraseAlert, animated: true, completion: nil)
let savePassphraseAndSegueAlert = self.createSavePassphraseAndSegueAlert()
self.present(savePassphraseAndSegueAlert, animated: true, completion: nil)
}))
alert.addTextField(configurationHandler: {(textField: UITextField!) in
textField.text = self.pgpPassphrase
@ -56,7 +53,7 @@ class PGPKeyArmorSettingTableViewController: UITableViewController, UITextViewDe
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if text == UIPasteboard.general.string {
// user pastes somethint, get ready to clear in 10s
// user pastes something, get ready to clear in 10s
recentPastedText = text
DispatchQueue.global(qos: .background).asyncAfter(deadline: DispatchTime.now() + 10) { [weak weakSelf = self] in
if let pasteboardString = UIPasteboard.general.string,

View file

@ -24,6 +24,19 @@ class PGPKeySettingTableViewController: UITableViewController {
pgpPassphrase = passwordStore.pgpKeyPassphrase
}
private func createSavePassphraseAndSegueAlert() -> UIAlertController {
let savePassphraseAlert = UIAlertController(title: "Passphrase", message: "Do you want to save the passphrase for later decryption?", preferredStyle: UIAlertControllerStyle.alert)
savePassphraseAlert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.default) { _ in
Defaults[.isRememberPassphraseOn] = false
self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
})
savePassphraseAlert.addAction(UIAlertAction(title: "Save", style: UIAlertActionStyle.destructive) {_ in
Defaults[.isRememberPassphraseOn] = true
self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
})
return savePassphraseAlert
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "savePGPKeySegue" {
guard let pgpPublicKeyURL = URL(string: pgpPublicKeyURLTextField.text!) else {
@ -46,9 +59,8 @@ class PGPKeySettingTableViewController: UITableViewController {
let alert = UIAlertController(title: "Passphrase", message: "Please fill in the passphrase of your PGP secret key.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
self.pgpPassphrase = alert.textFields?.first?.text
if self.shouldPerformSegue(withIdentifier: "savePGPKeySegue", sender: self) {
self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
}
let savePassphraseAndSegueAlert = self.createSavePassphraseAndSegueAlert()
self.present(savePassphraseAndSegueAlert, animated: true, completion: nil)
}))
alert.addTextField(configurationHandler: {(textField: UITextField!) in
textField.text = self.pgpPassphrase