Introduce CryptographicKey protocol

This commit is contained in:
Danny Moesch 2019-07-02 20:20:56 +02:00 committed by Mingshen Sun
parent d43a3be6f6
commit 6b95e60ea1
6 changed files with 30 additions and 24 deletions

View file

@ -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: .PUBLIC, keyPath: filePath) { _, _ in }
private static let keyFileManager = KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: filePath) { _, _ in }
override func tearDown() {
try? FileManager.default.removeItem(atPath: KeyFileManagerTest.filePath)
@ -22,13 +22,13 @@ class KeyFileManagerTest: XCTestCase {
func testImportKeyAndDeleteFile() throws {
let fileContent = "content".data(using: .ascii)
var storage: [String: Data] = [:]
let keyFileManager = KeyFileManager(keyType: .PRIVATE, keyPath: KeyFileManagerTest.filePath) { storage[$1] = $0 }
let keyFileManager = KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: KeyFileManagerTest.filePath) { storage[$1] = $0 }
FileManager.default.createFile(atPath: KeyFileManagerTest.filePath, contents: fileContent, attributes: nil)
try keyFileManager.importKeyAndDeleteFile()
XCTAssertFalse(FileManager.default.fileExists(atPath: KeyFileManagerTest.filePath))
XCTAssertTrue(storage[PgpKeyType.PRIVATE.getKeychainKey()] == fileContent)
XCTAssertTrue(storage[PgpKey.PRIVATE.getKeychainKey()] == fileContent)
}
func testErrorReadingFile() throws {