You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.4 KiB
66 lines
1.4 KiB
//
|
|
// KeyChain.swift
|
|
// GME Remit
|
|
//
|
|
// Created by InKwon Devik Kim on 08/04/2019.
|
|
// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import KeychainAccess
|
|
|
|
final class KeyChain {
|
|
|
|
enum KeyType: String {
|
|
case password
|
|
case id
|
|
case biometricAuth
|
|
case login
|
|
case temporaryID
|
|
case temporaryPW
|
|
}
|
|
|
|
static let shared = KeyChain()
|
|
private var keychain: Keychain
|
|
|
|
private init() {
|
|
self.keychain = Keychain(service: "com.gme.gmeremit")
|
|
|
|
// There is no userId, it's logout or remove app all and reinstall app.
|
|
if GMEDB.shared.user.string(.userId) == nil {
|
|
try? keychain.removeAll()
|
|
}
|
|
}
|
|
|
|
func save(data: String, key: KeyType) {
|
|
do {
|
|
try self.keychain.set(data, key: key.rawValue)
|
|
} catch let error {
|
|
print("keychain save error: \(error.localizedDescription)")
|
|
}
|
|
}
|
|
|
|
func get(key: KeyType) -> String? {
|
|
guard let pw = ((try? self.keychain.get(key.rawValue)) as String??) else {
|
|
return nil
|
|
}
|
|
|
|
return pw
|
|
}
|
|
|
|
func remove(key: KeyType) {
|
|
do {
|
|
try self.keychain.remove(key.rawValue)
|
|
} catch let error {
|
|
print("keychain remove error: \(error.localizedDescription)")
|
|
}
|
|
}
|
|
|
|
func removeAll() {
|
|
do {
|
|
try self.keychain.removeAll()
|
|
} catch let error {
|
|
print("keychain remove error: \(error.localizedDescription)")
|
|
}
|
|
}
|
|
}
|