throws exception from initPGP
This commit is contained in:
parent
c4a8751bd8
commit
452316d909
2 changed files with 18 additions and 21 deletions
|
|
@ -70,20 +70,14 @@ class PasswordStore {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initPGP(pgpKeyURL: URL, pgpKeyLocalPath: String) -> Bool {
|
func initPGP(pgpKeyURL: URL, pgpKeyLocalPath: String) throws {
|
||||||
do {
|
let pgpData = try Data(contentsOf: pgpKeyURL)
|
||||||
let pgpData = try Data(contentsOf: pgpKeyURL)
|
try pgpData.write(to: URL(fileURLWithPath: pgpKeyLocalPath), options: .atomic)
|
||||||
try pgpData.write(to: URL(fileURLWithPath: pgpKeyLocalPath), options: .atomic)
|
pgp.importKeys(fromFile: pgpKeyLocalPath, allowDuplicates: false)
|
||||||
pgp.importKeys(fromFile: pgpKeyLocalPath, allowDuplicates: false)
|
let key = pgp.keys[0]
|
||||||
let key = pgp.keys[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 {
|
Defaults[.pgpKeyUserID] = gpgUser.userID
|
||||||
Defaults[.pgpKeyUserID] = gpgUser.userID
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
} catch {
|
|
||||||
print("error")
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,14 +82,17 @@ class SettingsTableViewController: UITableViewController {
|
||||||
SVProgressHUD.setDefaultMaskType(.black)
|
SVProgressHUD.setDefaultMaskType(.black)
|
||||||
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
SVProgressHUD.show(withStatus: "Fetching PGP Key")
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
let ret = PasswordStore.shared.initPGP(pgpKeyURL: Defaults[.pgpKeyURL]!, pgpKeyLocalPath: Globals.shared.secringPath)
|
do {
|
||||||
|
try PasswordStore.shared.initPGP(pgpKeyURL: Defaults[.pgpKeyURL]!, pgpKeyLocalPath: Globals.shared.secringPath)
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if ret {
|
|
||||||
SVProgressHUD.showSuccess(withStatus: "Success")
|
SVProgressHUD.showSuccess(withStatus: "Success")
|
||||||
} else {
|
SVProgressHUD.dismiss(withDelay: 1)
|
||||||
SVProgressHUD.showError(withStatus: "Error")
|
}
|
||||||
}
|
} catch {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
SVProgressHUD.showError(withStatus: error.localizedDescription)
|
||||||
|
SVProgressHUD.dismiss(withDelay: 3)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue