add checks to avoid invalid inputs
This commit is contained in:
parent
0b714ffec2
commit
3145ddacbe
4 changed files with 18 additions and 3 deletions
|
|
@ -18,7 +18,7 @@ class GitRepositoryAuthenticationSettingTableViewController: UITableViewControll
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
navigationItem.title = "Auth Method"
|
navigationItem.title = "Auth Method"
|
||||||
switch selectedMethod! {
|
switch selectedMethod ?? "" {
|
||||||
case "Password":
|
case "Password":
|
||||||
passwordCell.accessoryType = UITableViewCellAccessoryType.checkmark
|
passwordCell.accessoryType = UITableViewCellAccessoryType.checkmark
|
||||||
case "SSH Key":
|
case "SSH Key":
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@ class PGPKeySettingTableViewController: UITableViewController {
|
||||||
|
|
||||||
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
||||||
if identifier == "savePGPKeySegue" {
|
if identifier == "savePGPKeySegue" {
|
||||||
|
guard pgpPublicKeyURLTextField.text != nil else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
guard pgpPrivateKeyURLTextField.text != nil else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if URL(string: pgpPublicKeyURLTextField.text!)!.scheme! == "http" &&
|
if URL(string: pgpPublicKeyURLTextField.text!)!.scheme! == "http" &&
|
||||||
URL(string: pgpPrivateKeyURLTextField.text!)!.scheme! == "http" {
|
URL(string: pgpPrivateKeyURLTextField.text!)!.scheme! == "http" {
|
||||||
let alertMessage = "HTTP connection is not supported."
|
let alertMessage = "HTTP connection is not supported."
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,11 @@ class SettingsTableViewController: UITableViewController {
|
||||||
@IBAction func save(segue: UIStoryboardSegue) {
|
@IBAction func save(segue: UIStoryboardSegue) {
|
||||||
if let controller = segue.source as? PGPKeySettingTableViewController {
|
if let controller = segue.source as? PGPKeySettingTableViewController {
|
||||||
|
|
||||||
if Defaults[.pgpKeyID] == nil {
|
if Defaults[.pgpKeyID] == nil ||
|
||||||
|
Defaults[.pgpPrivateKeyURL] != URL(string: controller.pgpPrivateKeyURLTextField.text!) ||
|
||||||
|
Defaults[.pgpPublicKeyURL] != URL(string: controller.pgpPublicKeyURLTextField.text!) ||
|
||||||
|
Defaults[.pgpKeyPassphrase] != controller.pgpKeyPassphraseTextField.text!
|
||||||
|
{
|
||||||
Defaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!)
|
Defaults[.pgpPrivateKeyURL] = URL(string: controller.pgpPrivateKeyURLTextField.text!)
|
||||||
Defaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!)
|
Defaults[.pgpPublicKeyURL] = URL(string: controller.pgpPublicKeyURLTextField.text!)
|
||||||
Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text!
|
Defaults[.pgpKeyPassphrase] = controller.pgpKeyPassphraseTextField.text!
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,13 @@ class PasswordStore {
|
||||||
try pgpPrivateData.write(to: URL(fileURLWithPath: pgpPrivateKeyLocalPath), options: .atomic)
|
try pgpPrivateData.write(to: URL(fileURLWithPath: pgpPrivateKeyLocalPath), options: .atomic)
|
||||||
|
|
||||||
pgp.importKeys(fromFile: pgpPublicKeyLocalPath, allowDuplicates: false)
|
pgp.importKeys(fromFile: pgpPublicKeyLocalPath, allowDuplicates: false)
|
||||||
|
if pgp.getKeysOf(.public).count == 0 {
|
||||||
|
throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import public key."])
|
||||||
|
}
|
||||||
pgp.importKeys(fromFile: pgpPrivateKeyLocalPath, allowDuplicates: false)
|
pgp.importKeys(fromFile: pgpPrivateKeyLocalPath, allowDuplicates: false)
|
||||||
|
if pgp.getKeysOf(.secret).count == 0 {
|
||||||
|
throw NSError(domain: "me.mssun.pass.error", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot import seceret key."])
|
||||||
|
}
|
||||||
let key = pgp.getKeysOf(.public)[0]
|
let key = pgp.getKeysOf(.public)[0]
|
||||||
Defaults[.pgpKeyID] = key.keyID!.shortKeyString
|
Defaults[.pgpKeyID] = key.keyID!.shortKeyString
|
||||||
if let gpgUser = key.users[0] as? PGPUser {
|
if let gpgUser = key.users[0] as? PGPUser {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue