Skip to content

Commit

Permalink
feat(#20): use "cap_sec" keychain wrapper service for ios
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgrube committed Nov 2, 2020
1 parent 54a919b commit 18856dc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import SwiftKeychainWrapper
*/
@objc(SecureStoragePlugin)
public class SecureStoragePlugin: CAPPlugin {
var keychainwrapper: KeychainWrapper = KeychainWrapper.init(serviceName: "cap_sec")

@objc func set(_ call: CAPPluginCall) {
let key = call.getString("key") ?? ""
let value = call.getString("value") ?? ""
let saveSuccessful: Bool = KeychainWrapper.standard.set(value, forKey: key)
let saveSuccessful: Bool = keychainwrapper.set(value, forKey: key)
if(saveSuccessful) {
call.success([
"value": saveSuccessful
Expand All @@ -25,10 +26,10 @@ public class SecureStoragePlugin: CAPPlugin {

@objc func get(_ call: CAPPluginCall) {
let key = call.getString("key") ?? ""
let hasValue = KeychainWrapper.standard.hasValue(forKey: key)
let hasValue = keychainwrapper.hasValue(forKey: key)
if(hasValue) {
call.success([
"value": KeychainWrapper.standard.string(forKey: key) ?? ""
"value": keychainwrapper.string(forKey: key) ?? ""
])
}
else {
Expand All @@ -37,15 +38,15 @@ public class SecureStoragePlugin: CAPPlugin {
}

@objc func keys(_ call: CAPPluginCall) {
let keys = KeychainWrapper.standard.allKeys();
let keys = keychainwrapper.allKeys();
call.success([
"value": keys
])
}

@objc func remove(_ call: CAPPluginCall) {
let key = call.getString("key") ?? ""
let removeSuccessful: Bool = KeychainWrapper.standard.removeObject(forKey: key)
let removeSuccessful: Bool = keychainwrapper.removeObject(forKey: key)
if(removeSuccessful) {
call.success([
"value": removeSuccessful
Expand All @@ -57,7 +58,7 @@ public class SecureStoragePlugin: CAPPlugin {
}

@objc func clear(_ call: CAPPluginCall) {
let clearSuccessful: Bool = KeychainWrapper.standard.removeAllKeys()
let clearSuccessful: Bool = keychainwrapper.removeAllKeys()
if(clearSuccessful) {
call.success([
"value": clearSuccessful
Expand Down

0 comments on commit 18856dc

Please sign in to comment.