Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log

## [1.0](https://github.com/idevelopers-in/FKSecureStore/releases/tag/1.0)
Released on ??, ?? ??, 2022.

#### Added
* Initial release.
13 changes: 13 additions & 0 deletions FKSecureStore.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Pod::Spec.new do |s|
s.name = 'FKSecureStore'
s.version = '1.0'
s.platform = :ios, '9.0'
s.license = { :type => 'MIT' }
s.homepage = 'https://github.com/idevelopers-in/FKSecureStore'
s.authors = { 'Firoz Khan' => 'f90khan@gmail.com' }
s.summary = 'A helper for keeping data secured in the keychain'
s.source = { :git => 'https://github.com/idevelopers-in/FKSecureStore.git', :tag => s.version }
s.source_files = 'FKSecureStore/*.{swift}'
s.frameworks = 'Security'
s.requires_arc = true
end
35 changes: 20 additions & 15 deletions FKSecureStore/FKSecureStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import Security

private let kSecureKeyPrefix = Bundle.main.bundleIdentifier! + ".FKSecureStore."

@objc class FKSecureStore: NSObject
@objc public class FKSecureStore: NSObject
{
@objc enum Status: Int
@objc public enum Status: Int
{
case success
case noData
Expand Down Expand Up @@ -59,13 +59,13 @@ private let kSecureKeyPrefix = Bundle.main.bundleIdentifier! + ".FKSecureStore."
Save any `String` for a particular key inside the keychain.

- Parameters:
- string: The string to be saved.
- key: The key for which the string should be saved.
- string: The string to be saved.
- key: The key for which the string should be saved.

- Returns: An enum containing the status of the operation.
*/
@discardableResult
@objc class func save(string: String, key: String) -> Status {
@objc public class func save(string: String, key: String) -> Status {

if let stringData = string.data(using: .utf8, allowLossyConversion: false) {
return save(data: stringData, key: key)
Expand All @@ -77,13 +77,13 @@ private let kSecureKeyPrefix = Bundle.main.bundleIdentifier! + ".FKSecureStore."
Save any `Data` for a particular key inside the keychain.

- Parameters:
- data: The data to be saved.
- key: The key for which the data should be saved.
- data: The data to be saved.
- key: The key for which the data should be saved.

- Returns: An enum containing the status of the operation.
*/
@discardableResult
@objc class func save(data: Data, key: String) -> Status {
@objc public class func save(data: Data, key: String) -> Status {

let query: [String: Any] = [
String(kSecClass): kSecClassKey,
Expand All @@ -102,11 +102,13 @@ private let kSecureKeyPrefix = Bundle.main.bundleIdentifier! + ".FKSecureStore."
/**
Retrieve any saved `String` for a particular key inside the keychain.

- Parameter key: The key for which the `String` should be retrieved.
- Parameters:
- key: The key for which the `String` should be retrieved.

- Returns: An optional `String` object.
*/
@objc class func load(key: String) -> String? {
@discardableResult
@objc public class func load(key: String) -> String? {

if let data = load(dataForKey: key){
return String(data: data, encoding: .utf8)
Expand All @@ -117,11 +119,13 @@ private let kSecureKeyPrefix = Bundle.main.bundleIdentifier! + ".FKSecureStore."
/**
Retrieve any saved `Data` for a particular key inside the keychain.

- Parameter key: The key for which the `Data` should be retrieved.
- Parameters:
- key: The key for which the `Data` should be retrieved.

- Returns: An optional `Data` object.
*/
@objc class func load(dataForKey key: String) -> Data? {
@discardableResult
@objc public class func load(dataForKey key: String) -> Data? {

let query = [
String(kSecClass): kSecClassKey,
Expand All @@ -141,12 +145,13 @@ private let kSecureKeyPrefix = Bundle.main.bundleIdentifier! + ".FKSecureStore."
/**
Delete stored data for a particular key inside the keychain.

- Parameter key: The key for which the data should be deleted.
- Parameters:
- key: The key for which the data should be deleted.

- Returns: An enum containing the status of the operation.
*/
@discardableResult
@objc class func delete(key: String) -> Status {
@objc public class func delete(key: String) -> Status {

let query = [
String(kSecClass): kSecClassKey,
Expand All @@ -163,7 +168,7 @@ private let kSecureKeyPrefix = Bundle.main.bundleIdentifier! + ".FKSecureStore."
- Returns: An enum containing the status of the operation.
*/
@discardableResult
@objc class func clear() -> Status {
@objc public class func clear() -> Status {

let query = [
String(kSecClass): kSecClassKey,
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ Delete any saved data for a particular key in the keychain.
```
Delete all saved data for the app in the keychain. All data for any key you might have saved will be deleted.

#### Note
Saved data will persist in keychain even after application is deleted or device is restarted.
**Note:** Saved data will persist in keychain even after application is deleted or device is restarted.

# To-do

* Option to clear keychain data if app is uninstalled. [Might help?](https://developer.apple.com/forums/thread/36442)
* ~~Check if podspec requires linking to `Security` framework~~
* ~~Add description of library to repo page and podspec~~

# License

Expand Down