Fix fail-safe mechanism for other decryption scenarios
This commit is contained in:
parent
3e114daca1
commit
fcc8961e46
15 changed files with 153 additions and 100 deletions
|
|
@ -45,15 +45,20 @@ public class PGPAgent {
|
|||
return pgpInterface?.shortKeyID.sorted() ?? []
|
||||
}
|
||||
|
||||
public func decrypt(encryptedData: Data, keyID: String, requestPGPKeyPassphrase: (String) -> String) throws -> Data? {
|
||||
public func decrypt(encryptedData: Data, keyID: String, requestPGPKeyPassphrase: @escaping (String) -> String) throws -> Data? {
|
||||
// Init keys.
|
||||
try checkAndInit()
|
||||
guard let pgpInterface = pgpInterface else {
|
||||
throw AppError.Decryption
|
||||
}
|
||||
|
||||
var keyID = keyID;
|
||||
if !pgpInterface.containsPrivateKey(with: keyID) {
|
||||
throw AppError.PgpPrivateKeyNotFound(keyID: keyID)
|
||||
if pgpInterface.keyID.count == 1 {
|
||||
keyID = pgpInterface.keyID.first!
|
||||
} else {
|
||||
throw AppError.PgpPrivateKeyNotFound(keyID: keyID)
|
||||
}
|
||||
}
|
||||
|
||||
// Remember the previous status and set the current status
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue