move function to be closer to related one
This commit is contained in:
parent
5a92b6fda7
commit
b103337083
1 changed files with 22 additions and 22 deletions
|
|
@ -53,6 +53,28 @@ public class PGPAgent {
|
||||||
return pgpInterface?.getShortKeyIDs(type: type).sorted() ?? []
|
return pgpInterface?.getShortKeyIDs(type: type).sorted() ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func decrypt(encryptedData: Data, requestPGPKeyPassphrase: @escaping (String) -> String) throws -> Data? {
|
||||||
|
// Remember the previous status and set the current status
|
||||||
|
let previousDecryptStatus = latestDecryptStatus
|
||||||
|
latestDecryptStatus = false
|
||||||
|
// Init keys.
|
||||||
|
try checkAndInit()
|
||||||
|
// Get the PGP key passphrase.
|
||||||
|
let providePassPhraseForKey = { (selectedKeyID: String) -> String in
|
||||||
|
if previousDecryptStatus == false {
|
||||||
|
return requestPGPKeyPassphrase(selectedKeyID)
|
||||||
|
}
|
||||||
|
return self.keyStore.get(for: AppKeychain.getPGPKeyPassphraseKey(keyID: selectedKeyID)) ?? requestPGPKeyPassphrase(selectedKeyID)
|
||||||
|
}
|
||||||
|
// Decrypt.
|
||||||
|
guard let result = try pgpInterface!.decrypt(encryptedData: encryptedData, keyIDHint: nil, passPhraseForKey: providePassPhraseForKey) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// The decryption step has succeed.
|
||||||
|
latestDecryptStatus = true
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
public func decrypt(encryptedData: Data, keyID: String, requestPGPKeyPassphrase: @escaping (String) -> String) throws -> Data? {
|
public func decrypt(encryptedData: Data, keyID: String, requestPGPKeyPassphrase: @escaping (String) -> String) throws -> Data? {
|
||||||
// Init keys.
|
// Init keys.
|
||||||
try checkAndInit()
|
try checkAndInit()
|
||||||
|
|
@ -100,28 +122,6 @@ public class PGPAgent {
|
||||||
return try pgpInterface.encryptWithAllKeys(plainData: plainData)
|
return try pgpInterface.encryptWithAllKeys(plainData: plainData)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func decrypt(encryptedData: Data, requestPGPKeyPassphrase: @escaping (String) -> String) throws -> Data? {
|
|
||||||
// Remember the previous status and set the current status
|
|
||||||
let previousDecryptStatus = latestDecryptStatus
|
|
||||||
latestDecryptStatus = false
|
|
||||||
// Init keys.
|
|
||||||
try checkAndInit()
|
|
||||||
// Get the PGP key passphrase.
|
|
||||||
let providePassPhraseForKey = { (selectedKeyID: String) -> String in
|
|
||||||
if previousDecryptStatus == false {
|
|
||||||
return requestPGPKeyPassphrase(selectedKeyID)
|
|
||||||
}
|
|
||||||
return self.keyStore.get(for: AppKeychain.getPGPKeyPassphraseKey(keyID: selectedKeyID)) ?? requestPGPKeyPassphrase(selectedKeyID)
|
|
||||||
}
|
|
||||||
// Decrypt.
|
|
||||||
guard let result = try pgpInterface!.decrypt(encryptedData: encryptedData, keyIDHint: nil, passPhraseForKey: providePassPhraseForKey) else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// The decryption step has succeed.
|
|
||||||
latestDecryptStatus = true
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
public var isPrepared: Bool {
|
public var isPrepared: Bool {
|
||||||
keyStore.contains(key: PGPKey.PUBLIC.getKeychainKey())
|
keyStore.contains(key: PGPKey.PUBLIC.getKeychainKey())
|
||||||
&& keyStore.contains(key: PGPKey.PRIVATE.getKeychainKey())
|
&& keyStore.contains(key: PGPKey.PRIVATE.getKeychainKey())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue