diff --git a/passKit/Helpers/KeyFileManager.swift b/passKit/Helpers/KeyFileManager.swift index 3070472..2dae9eb 100644 --- a/passKit/Helpers/KeyFileManager.swift +++ b/passKit/Helpers/KeyFileManager.swift @@ -15,19 +15,17 @@ public class KeyFileManager { private let keyType: CryptographicKey private let keyPath: String - private let keyHandler: KeyHandler private convenience init(keyType: CryptographicKey) { self.init(keyType: keyType, keyPath: keyType.getFileSharingPath()) } - public init(keyType: CryptographicKey, keyPath: String, keyHandler: @escaping KeyHandler = AppKeychain.add) { + public init(keyType: CryptographicKey, keyPath: String) { self.keyType = keyType self.keyPath = keyPath - self.keyHandler = keyHandler } - public func importKeyAndDeleteFile() throws { + public func importKeyAndDeleteFile(keyHandler: KeyHandler = AppKeychain.shared.add) throws { guard let keyFileContent = FileManager.default.contents(atPath: keyPath) else { throw AppError.ReadingFile(URL(fileURLWithPath: keyPath).lastPathComponent) } diff --git a/passKitTests/Helpers/KeyFileManagerTest.swift b/passKitTests/Helpers/KeyFileManagerTest.swift index a372d0a..9bed027 100644 --- a/passKitTests/Helpers/KeyFileManagerTest.swift +++ b/passKitTests/Helpers/KeyFileManagerTest.swift @@ -12,7 +12,7 @@ import XCTest class KeyFileManagerTest: XCTestCase { private static let filePath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("test.txt").path - private static let keyFileManager = KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: filePath) { _, _ in } + private static let keyFileManager = KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: filePath) override func tearDown() { try? FileManager.default.removeItem(atPath: KeyFileManagerTest.filePath) @@ -22,17 +22,17 @@ class KeyFileManagerTest: XCTestCase { func testImportKeyAndDeleteFile() throws { let fileContent = "content".data(using: .ascii) var storage: [String: Data] = [:] - let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: KeyFileManagerTest.filePath) { storage[$1] = $0 } + let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: KeyFileManagerTest.filePath) FileManager.default.createFile(atPath: KeyFileManagerTest.filePath, contents: fileContent, attributes: nil) - try keyFileManager.importKeyAndDeleteFile() + try keyFileManager.importKeyAndDeleteFile { storage[$1] = $0 } XCTAssertFalse(FileManager.default.fileExists(atPath: KeyFileManagerTest.filePath)) XCTAssertTrue(storage[PgpKey.PRIVATE.getKeychainKey()] == fileContent) } func testErrorReadingFile() throws { - XCTAssertThrowsError(try KeyFileManagerTest.keyFileManager.importKeyAndDeleteFile()) { + XCTAssertThrowsError(try KeyFileManagerTest.keyFileManager.importKeyAndDeleteFile { _, _ in }) { XCTAssertEqual($0 as! AppError, AppError.ReadingFile("test.txt")) } }