Fix fail-safe mechanism for other decryption scenarios

This commit is contained in:
Mingshen Sun 2020-04-18 22:35:17 -07:00
parent 3e114daca1
commit fcc8961e46
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
15 changed files with 153 additions and 100 deletions

View file

@ -31,7 +31,7 @@ class PGPAgentTest: XCTestCase {
super.tearDown()
}
func basicEncryptDecrypt(using pgpAgent: PGPAgent, keyID: String, encryptKeyID: String? = nil, requestPassphrase: (String) -> String = requestPGPKeyPassphrase, encryptInArmored: Bool = true, encryptInArmoredNow: Bool = true) throws -> Data? {
func basicEncryptDecrypt(using pgpAgent: PGPAgent, keyID: String, encryptKeyID: String? = nil, requestPassphrase: @escaping (String) -> String = requestPGPKeyPassphrase, encryptInArmored: Bool = true, encryptInArmoredNow: Bool = true) throws -> Data? {
passKit.Defaults.encryptInArmored = encryptInArmored
let encryptedData = try pgpAgent.encrypt(plainData: testData, keyID: keyID)
passKit.Defaults.encryptInArmored = encryptInArmoredNow

View file

@ -57,7 +57,7 @@ class PasswordStoreTest: XCTestCase {
let testPassword = Password(name: "test", url: URL(string: "test.gpg")!, plainText: "testpassword")
let testPasswordEntity = try passwordStore.add(password: testPassword)!
let testPasswordPlain = try passwordStore.decrypt(passwordEntity: testPasswordEntity, requestPGPKeyPassphrase: requestPGPKeyPassphrase )!
let testPasswordPlain = try passwordStore.decrypt(passwordEntity: testPasswordEntity, requestPGPKeyPassphrase: requestPGPKeyPassphrase )
XCTAssertEqual(testPasswordPlain.plainText, "testpassword")
passwordStore.erase()
@ -65,7 +65,7 @@ class PasswordStoreTest: XCTestCase {
private func decrypt(passwordStore: PasswordStore, path: String, passphrase: String) throws -> Password {
let entity = passwordStore.getPasswordEntity(by: path, isDir: false)!
return try passwordStore.decrypt(passwordEntity: entity, requestPGPKeyPassphrase: requestPGPKeyPassphrase )!
return try passwordStore.decrypt(passwordEntity: entity, requestPGPKeyPassphrase: requestPGPKeyPassphrase )
}