From 072f8241581df41873f6925685ea447bdbc77e7f Mon Sep 17 00:00:00 2001 From: Mingshen Sun Date: Sat, 18 Apr 2020 23:21:50 -0700 Subject: [PATCH] No need to select key for encryption if there only one imported key --- passKit/Crypto/PGPAgent.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/passKit/Crypto/PGPAgent.swift b/passKit/Crypto/PGPAgent.swift index d2260a1..64caadd 100644 --- a/passKit/Crypto/PGPAgent.swift +++ b/passKit/Crypto/PGPAgent.swift @@ -86,8 +86,13 @@ public class PGPAgent { guard let pgpInterface = pgpInterface else { throw AppError.Encryption } + var keyID = keyID if !pgpInterface.containsPublicKey(with: keyID) { - throw AppError.PgpPublicKeyNotFound(keyID: keyID) + if pgpInterface.keyID.count == 1 { + keyID = pgpInterface.keyID.first! + } else { + throw AppError.PgpPublicKeyNotFound(keyID: keyID) + } } return try pgpInterface.encrypt(plainData: plainData, keyID: keyID) }