Fix decryption issue when key without passphrase set

This commit is contained in:
Mingshen Sun 2021-01-10 15:01:21 -08:00
parent 776884e894
commit 011762c4bd
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
4 changed files with 153 additions and 2 deletions

View file

@ -84,7 +84,14 @@ struct GopenPGPInterface: PGPInterface {
}
do {
let unlockedKey = try privateKey.unlock(passphrase.data(using: .utf8))
var isLocked: ObjCBool = false
try privateKey.isLocked(&isLocked)
var unlockedKey: CryptoKey!
if isLocked.boolValue {
unlockedKey = try privateKey.unlock(passphrase.data(using: .utf8))
} else {
unlockedKey = privateKey
}
var error: NSError?
guard let keyRing = CryptoNewKeyRing(unlockedKey, &error) else {