-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathKeychainable.swift
40 lines (34 loc) · 1.17 KB
/
Keychainable.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Keychainable.swift
// Lockdown
//
// Created by Aliaksandr Dvoineu on 4.05.23.
// Copyright © 2023 Confirmed Inc. All rights reserved.
//
import KeychainAccess
protocol Keychainable: AnyObject {
func saveKeychainBool(_ item: KeychainBoolItem, _ bool: Bool, keychain: Keychain)
func readKeychainBool(_ item: KeychainBoolItem, keychain: Keychain) -> Bool
}
extension Keychainable {
private static var defaultKeychain: Keychain { Keychain(service: LockdownStorageIdentifier.keychainId).synchronizable(true) }
func saveKeychainBool(_ item: KeychainBoolItem, _ bool: Bool, keychain: Keychain = Self.defaultKeychain) {
do {
try keychain.set(String(bool), key: item.rawValue)
} catch let error {
print(error)
}
}
func readKeychainBool(_ item: KeychainBoolItem, keychain: Keychain = Self.defaultKeychain) -> Bool {
do {
let value: String = try keychain.get(item.rawValue) ?? ""
return Bool(value) ?? false
} catch let error {
print(error)
return false
}
}
}
enum KeychainBoolItem: String {
case hasSeenXmasLTO
}