设备唯一标识
This commit is contained in:
77
Pods/DDPersistenceKit_Private/DDPersistenceKit_Private/Classes/DDKeychain.swift
generated
Normal file
77
Pods/DDPersistenceKit_Private/DDPersistenceKit_Private/Classes/DDKeychain.swift
generated
Normal file
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// DDKeychain.swift
|
||||
// DDPersistenceKit_Private
|
||||
// Created by DDIsFriend on 2023/9/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Security
|
||||
|
||||
public let DDKC = DDKeychain.default
|
||||
open class DDKeychain : NSObject {
|
||||
public static let `default` = DDKeychain()
|
||||
|
||||
public struct Credentials {
|
||||
var itemKey : String
|
||||
var itemValue : String?
|
||||
public init(itemKey: String, itemValue: String? = nil) {
|
||||
self.itemKey = itemKey
|
||||
self.itemValue = itemValue
|
||||
}
|
||||
}
|
||||
|
||||
public enum KeychainError : Int {
|
||||
case success = 0
|
||||
case failure = 1
|
||||
}
|
||||
|
||||
public func addItem(credentials:Credentials) -> KeychainError {
|
||||
let itemKey = credentials.itemKey
|
||||
guard let itemValue = credentials.itemValue else {
|
||||
return .failure
|
||||
}
|
||||
let itemValueData = itemValue.data(using: .utf8)!
|
||||
let query : [String : Any] = [kSecValueData as String:itemValueData,kSecAttrAccount as String:itemKey,kSecClass as String:kSecClassGenericPassword]
|
||||
let status = SecItemAdd(query as CFDictionary, nil)
|
||||
if status == 0 {
|
||||
return .success
|
||||
}
|
||||
return .failure
|
||||
}
|
||||
|
||||
public func queryItem(credentials:Credentials) -> Data? {
|
||||
let itemKey = credentials.itemKey
|
||||
let query : [String : Any] = [kSecReturnData as String:true,kSecAttrAccount as String:itemKey,kSecClass as String:kSecClassGenericPassword]
|
||||
|
||||
var itemValueData : CFTypeRef?
|
||||
let status = SecItemCopyMatching(query as CFDictionary, &itemValueData)
|
||||
if status == 0 {
|
||||
return itemValueData as? Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public func updateItem(credentials:Credentials) -> KeychainError {
|
||||
let query : [String : Any] = [kSecAttrAccount as String: credentials.itemKey,kSecClass as String:kSecClassGenericPassword]
|
||||
guard let itemValue = credentials.itemValue else {
|
||||
return .failure
|
||||
}
|
||||
let itemValueData = itemValue.data(using: .utf8)!
|
||||
let attributes : [String : Any] = [kSecValueData as String:itemValueData]
|
||||
|
||||
let status = SecItemUpdate(query as CFDictionary, attributes as CFDictionary)
|
||||
if status == 0 {
|
||||
return .success
|
||||
}
|
||||
return .failure
|
||||
}
|
||||
|
||||
public func deleteItem(credentials:Credentials) -> KeychainError {
|
||||
let query : [String : Any] = [kSecClass as String:kSecClassGenericPassword,kSecAttrAccount as String:credentials.itemKey]
|
||||
let status = SecItemDelete(query as CFDictionary)
|
||||
if status == 0 {
|
||||
return .success
|
||||
}
|
||||
return .failure
|
||||
}
|
||||
}
|
||||
19
Pods/DDPersistenceKit_Private/LICENSE
generated
Normal file
19
Pods/DDPersistenceKit_Private/LICENSE
generated
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2023 DDIsFriend <DDIsFriend@163.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
29
Pods/DDPersistenceKit_Private/README.md
generated
Normal file
29
Pods/DDPersistenceKit_Private/README.md
generated
Normal file
@@ -0,0 +1,29 @@
|
||||
# DDPersistenceKit_Private
|
||||
|
||||
[](https://travis-ci.org/DDIsFriend/DDPersistenceKit_Private)
|
||||
[](https://cocoapods.org/pods/DDPersistenceKit_Private)
|
||||
[](https://cocoapods.org/pods/DDPersistenceKit_Private)
|
||||
[](https://cocoapods.org/pods/DDPersistenceKit_Private)
|
||||
|
||||
## Example
|
||||
|
||||
To run the example project, clone the repo, and run `pod install` from the Example directory first.
|
||||
|
||||
## Requirements
|
||||
|
||||
## Installation
|
||||
|
||||
DDPersistenceKit_Private is available through [CocoaPods](https://cocoapods.org). To install
|
||||
it, simply add the following line to your Podfile:
|
||||
|
||||
```ruby
|
||||
pod 'DDPersistenceKit_Private'
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
DDIsFriend, DDIsFriend@163.com
|
||||
|
||||
## License
|
||||
|
||||
DDPersistenceKit_Private is available under the MIT license. See the LICENSE file for more info.
|
||||
Reference in New Issue
Block a user