Implement fail-safe mechanism if key id is not found
This commit is contained in:
parent
0cae6af60d
commit
3e114daca1
11 changed files with 161 additions and 58 deletions
|
|
@ -42,16 +42,12 @@ public class PGPAgent {
|
|||
|
||||
public func getShortKeyID() throws -> [String] {
|
||||
try checkAndInit()
|
||||
return pgpInterface?.shortKeyID ?? []
|
||||
return pgpInterface?.shortKeyID.sorted() ?? []
|
||||
}
|
||||
|
||||
public func decrypt(encryptedData: Data, keyID: String, requestPGPKeyPassphrase: (String) -> String) throws -> Data? {
|
||||
// Remember the previous status and set the current status
|
||||
let previousDecryptStatus = self.latestDecryptStatus
|
||||
self.latestDecryptStatus = false
|
||||
// Init keys.
|
||||
try checkAndInit()
|
||||
|
||||
guard let pgpInterface = pgpInterface else {
|
||||
throw AppError.Decryption
|
||||
}
|
||||
|
|
@ -60,6 +56,10 @@ public class PGPAgent {
|
|||
throw AppError.PgpPrivateKeyNotFound(keyID: keyID)
|
||||
}
|
||||
|
||||
// Remember the previous status and set the current status
|
||||
let previousDecryptStatus = self.latestDecryptStatus
|
||||
self.latestDecryptStatus = false
|
||||
|
||||
// Get the PGP key passphrase.
|
||||
var passphrase = ""
|
||||
if previousDecryptStatus == false {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue