PGPAgent can encrypt with multiple keys
This commit is contained in:
parent
05324cebe8
commit
ee80f0dbe8
3 changed files with 41 additions and 5 deletions
|
|
@ -138,8 +138,11 @@ struct GopenPGPInterface: PGPInterface {
|
|||
}
|
||||
|
||||
func encrypt(plainData: Data, keyIDs: [String]) throws -> Data {
|
||||
let keys: [CryptoKey] = keyIDs.compactMap { keyID in
|
||||
publicKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) })?.value
|
||||
let keys: [CryptoKey] = try keyIDs.map { keyID in
|
||||
guard let key = publicKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) })?.value else {
|
||||
throw AppError.pgpPublicKeyNotFound(keyID: keyID)
|
||||
}
|
||||
return key
|
||||
}
|
||||
guard let firstKey = keys.first else {
|
||||
throw AppError.encryption
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ public class PGPAgent {
|
|||
return result
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use encrypt(plainData:keyIDs:) instead.")
|
||||
public func encrypt(plainData: Data, keyID: String) throws -> Data {
|
||||
try checkAndInit()
|
||||
guard let pgpInterface else {
|
||||
|
|
@ -100,6 +101,14 @@ public class PGPAgent {
|
|||
return try pgpInterface.encrypt(plainData: plainData, keyIDs: [keyID])
|
||||
}
|
||||
|
||||
public func encrypt(plainData: Data, keyIDs: [String]) throws -> Data {
|
||||
try checkAndInit()
|
||||
guard let pgpInterface else {
|
||||
throw AppError.encryption
|
||||
}
|
||||
return try pgpInterface.encrypt(plainData: plainData, keyIDs: keyIDs)
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Use encrypt(plainData:keyIDs:) or encryptWithAllKeys(plainData:) instead.")
|
||||
public func encrypt(plainData: Data) throws -> Data {
|
||||
try checkAndInit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue