No need to select key for encryption if there only one imported key

This commit is contained in:
Mingshen Sun 2020-04-18 23:21:50 -07:00
parent fcc8961e46
commit 072f824158
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4

View file

@ -86,9 +86,14 @@ public class PGPAgent {
guard let pgpInterface = pgpInterface else {
throw AppError.Encryption
}
var keyID = keyID
if !pgpInterface.containsPublicKey(with: keyID) {
if pgpInterface.keyID.count == 1 {
keyID = pgpInterface.keyID.first!
} else {
throw AppError.PgpPublicKeyNotFound(keyID: keyID)
}
}
return try pgpInterface.encrypt(plainData: plainData, keyID: keyID)
}