设备唯一标识

This commit is contained in:
DDIsFriend
2023-10-12 15:11:00 +08:00
parent 78b7c88218
commit 06e22d8c6e
29 changed files with 8228 additions and 7653 deletions

View 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
View 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
View File

@@ -0,0 +1,29 @@
# DDPersistenceKit_Private
[![CI Status](https://img.shields.io/travis/DDIsFriend/DDPersistenceKit_Private.svg?style=flat)](https://travis-ci.org/DDIsFriend/DDPersistenceKit_Private)
[![Version](https://img.shields.io/cocoapods/v/DDPersistenceKit_Private.svg?style=flat)](https://cocoapods.org/pods/DDPersistenceKit_Private)
[![License](https://img.shields.io/cocoapods/l/DDPersistenceKit_Private.svg?style=flat)](https://cocoapods.org/pods/DDPersistenceKit_Private)
[![Platform](https://img.shields.io/cocoapods/p/DDPersistenceKit_Private.svg?style=flat)](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.