-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce KeyStore protocol in order to provide specialized key store…
… implementations for tests With the DictBasedKeychain the main AppKeychain is not influenced by tests. The previous implementation led to an empty Keychain requiring a new setup of the simulator.
- Loading branch information
1 parent
b424013
commit 5c7d4e5
Showing
6 changed files
with
93 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// KeyStore.swift | ||
// passKit | ||
// | ||
// Created by Danny Moesch on 20.07.19. | ||
// Copyright © 2019 Bob Sun. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol KeyStore { | ||
func add(data: Data?, for key: String) | ||
func add(string: String?, for key: String) | ||
func contains(key: String) -> Bool | ||
func get(for key: String) -> Data? | ||
func get(for key: String) -> String? | ||
func removeContent(for key: String) | ||
func removeAllContent() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// DictBasedKeychain.swift | ||
// passKitTests | ||
// | ||
// Created by Danny Moesch on 20.07.19. | ||
// Copyright © 2019 Bob Sun. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import passKit | ||
|
||
class DictBasedKeychain: KeyStore { | ||
private var store: [String: Any] = [:] | ||
|
||
public func add(data: Data?, for key: String) { | ||
store[key] = data | ||
} | ||
|
||
public func add(string: String?, for key: String) { | ||
store[key] = string | ||
} | ||
|
||
public func contains(key: String) -> Bool { | ||
return store[key] != nil | ||
} | ||
|
||
public func get(for key: String) -> Data? { | ||
return store[key] as? Data | ||
} | ||
|
||
public func get(for key: String) -> String? { | ||
return store[key] as? String | ||
} | ||
|
||
public func removeContent(for key: String) { | ||
store.removeValue(forKey: key) | ||
} | ||
|
||
public func removeAllContent() { | ||
store.removeAll() | ||
} | ||
} |