Refactor logic of request PGP key passphrase
This commit is contained in:
parent
e62f4714e8
commit
e9c5b63c4b
10 changed files with 44 additions and 104 deletions
|
|
@ -31,7 +31,7 @@ class PGPAgentTest: XCTestCase {
|
|||
super.tearDown()
|
||||
}
|
||||
|
||||
func basicEncryptDecrypt(using pgpAgent: PGPAgent, keyID: String, encryptKeyID: String? = nil, requestPassphrase: () -> String = requestPGPKeyPassphrase, encryptInArmored: Bool = true, encryptInArmoredNow: Bool = true) throws -> Data? {
|
||||
func basicEncryptDecrypt(using pgpAgent: PGPAgent, keyID: String, encryptKeyID: String? = nil, requestPassphrase: (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
|
||||
|
|
@ -132,11 +132,11 @@ class PGPAgentTest: XCTestCase {
|
|||
try importKeys(RSA2048.publicKey, RSA2048.privateKey)
|
||||
|
||||
var passphraseRequestCalledCount = 0
|
||||
let provideCorrectPassphrase: () -> String = {
|
||||
let provideCorrectPassphrase: (String) -> String = { _ in
|
||||
passphraseRequestCalledCount = passphraseRequestCalledCount + 1
|
||||
return requestPGPKeyPassphrase()
|
||||
}
|
||||
let provideIncorrectPassphrase: () -> String = {
|
||||
let provideIncorrectPassphrase: (String) -> String = { _ in
|
||||
passphraseRequestCalledCount = passphraseRequestCalledCount + 1
|
||||
return "incorrect passphrase"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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: { "passforios" } )!
|
||||
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: { passphrase } )!
|
||||
return try passwordStore.decrypt(passwordEntity: entity, requestPGPKeyPassphrase: requestPGPKeyPassphrase )!
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ let RSA2048_RSA4096 = MultiPGPKeyTestTriple(
|
|||
passphrase: ["passforios", "passforios"]
|
||||
)
|
||||
|
||||
func requestPGPKeyPassphrase() -> String {
|
||||
func requestPGPKeyPassphrase(keyID: String = "") -> String {
|
||||
return "passforios"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue