Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35bc00f6de | |||
| 0e72823fee | |||
| 164dabf456 | |||
| e7ece35421 | |||
| 8dd3200ae3 |
+1
-1
@@ -9,7 +9,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Locksmith"
|
||||
s.version = "1.2.1"
|
||||
s.version = "1.2.3"
|
||||
s.summary = "Locksmith is a sane way to work with the iOS Keychain in Swift."
|
||||
s.description = <<-DESC
|
||||
Locksmith is a sane way to work with the iOS Keychain in Swift.
|
||||
|
||||
@@ -25,7 +25,7 @@ class LocksmithTests: XCTestCase {
|
||||
|
||||
// public class func saveData(data: Dictionary<String, String>, inService service: String, forUserAccount userAccount: String) -> NSError?
|
||||
func testSaveData_Once() {
|
||||
var error = Locksmith.saveData(["key": "value"], forUserAccount: "myUserAccount", inService: "myService")
|
||||
let error = Locksmith.saveData(["key": "value"], forUserAccount: "myUserAccount", inService: "myService")
|
||||
XCTAssert(error == nil, "❌: saving data")
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ class LocksmithTests: XCTestCase {
|
||||
setupLoads()
|
||||
|
||||
let (dictionary, error) = Locksmith.loadDataForUserAccount("user1", inService: "myService")
|
||||
let (dictionary2, error2) = Locksmith.loadDataForUserAccount("user2", inService: "myService")
|
||||
let (dictionary3, error3) = Locksmith.loadDataForUserAccount("user3", inService: "myService")
|
||||
let (dictionary2, _) = Locksmith.loadDataForUserAccount("user2", inService: "myService")
|
||||
let (dictionary3, _) = Locksmith.loadDataForUserAccount("user3", inService: "myService")
|
||||
|
||||
XCTAssert(dictionary!.valueForKey("key") as! NSString == "value" && error == nil, "❌: loading multiple items")
|
||||
XCTAssert(dictionary2!.valueForKey("anotherkey") as! NSString == "anothervalue" && error == nil, "❌: loading multiple items")
|
||||
@@ -79,7 +79,7 @@ class LocksmithTests: XCTestCase {
|
||||
setupLoads()
|
||||
|
||||
let error = Locksmith.updateData(["key": "newvalue"], forUserAccount: "user1", inService: "myService")
|
||||
let (dictionary, err) = Locksmith.loadDataForUserAccount("user1", inService: "myService")
|
||||
let (dictionary, _) = Locksmith.loadDataForUserAccount("user1", inService: "myService")
|
||||
|
||||
XCTAssert(dictionary!.valueForKey("key") as! NSString == "newvalue" && error == nil, "❌: updating item")
|
||||
|
||||
|
||||
+11
-15
@@ -9,7 +9,7 @@ import UIKit
|
||||
import Security
|
||||
|
||||
public let LocksmithErrorDomain = "com.locksmith.error"
|
||||
public let LocksmithDefaultService = NSBundle.mainBundle().infoDictionary![kCFBundleIdentifierKey] as? String ?? "com.locksmith.defaultService"
|
||||
public let LocksmithDefaultService = NSBundle.mainBundle().bundleIdentifier ?? "com.locksmith.defaultService"
|
||||
|
||||
|
||||
public class Locksmith: NSObject {
|
||||
@@ -20,9 +20,9 @@ public class Locksmith: NSObject {
|
||||
var result: AnyObject?
|
||||
var status: OSStatus?
|
||||
|
||||
var parsedRequest: NSMutableDictionary = parseRequest(request)
|
||||
let parsedRequest: NSMutableDictionary = parseRequest(request)
|
||||
|
||||
var requestReference = parsedRequest as CFDictionaryRef
|
||||
let requestReference = parsedRequest as CFDictionaryRef
|
||||
|
||||
switch type {
|
||||
case .Create:
|
||||
@@ -33,12 +33,10 @@ public class Locksmith: NSObject {
|
||||
status = SecItemDelete(requestReference)
|
||||
case .Update:
|
||||
status = Locksmith.performUpdate(requestReference, result: &result)
|
||||
default:
|
||||
status = nil
|
||||
}
|
||||
|
||||
if let status = status {
|
||||
var statusCode = Int(status)
|
||||
let statusCode = Int(status)
|
||||
let error = Locksmith.keychainError(forCode: statusCode)
|
||||
var resultsDictionary: NSDictionary?
|
||||
|
||||
@@ -66,7 +64,7 @@ public class Locksmith: NSObject {
|
||||
// Even if the delete request failed (e.g. if the item didn't exist before), still try to save the new item.
|
||||
// If we get an error saving, we'll tell the user about it.
|
||||
|
||||
var status: OSStatus = withUnsafeMutablePointer(&result) { SecItemAdd(request, UnsafeMutablePointer($0)) }
|
||||
let status: OSStatus = withUnsafeMutablePointer(&result) { SecItemAdd(request, UnsafeMutablePointer($0)) }
|
||||
return status
|
||||
}
|
||||
|
||||
@@ -219,8 +217,6 @@ public class Locksmith: NSObject {
|
||||
return kSecClassInternetPassword
|
||||
case .Key:
|
||||
return kSecClassKey
|
||||
default:
|
||||
return kSecClassGenericPassword
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +244,7 @@ public class Locksmith: NSObject {
|
||||
extension Locksmith {
|
||||
public class func saveData(data: Dictionary<String, String>, forUserAccount userAccount: String, inService service: String = LocksmithDefaultService) -> NSError? {
|
||||
let saveRequest = LocksmithRequest(userAccount: userAccount, requestType: .Create, data: data, service: service)
|
||||
let (dictionary, error) = Locksmith.performRequest(saveRequest)
|
||||
let (_, error) = Locksmith.performRequest(saveRequest)
|
||||
return error
|
||||
}
|
||||
|
||||
@@ -259,26 +255,26 @@ extension Locksmith {
|
||||
|
||||
public class func deleteDataForUserAccount(userAccount: String, inService service: String = LocksmithDefaultService) -> NSError? {
|
||||
let deleteRequest = LocksmithRequest(userAccount: userAccount, requestType: .Delete, service: service)
|
||||
let (dictionary, error) = Locksmith.performRequest(deleteRequest)
|
||||
let (_, error) = Locksmith.performRequest(deleteRequest)
|
||||
return error
|
||||
}
|
||||
|
||||
public class func updateData(data: Dictionary<String, String>, forUserAccount userAccount: String, inService service: String = LocksmithDefaultService) -> NSError? {
|
||||
let updateRequest = LocksmithRequest(userAccount: userAccount, requestType: .Update, data: data, service: service)
|
||||
let (dictionary, error) = Locksmith.performRequest(updateRequest)
|
||||
let (_, error) = Locksmith.performRequest(updateRequest)
|
||||
return error
|
||||
}
|
||||
|
||||
public class func clearKeychain() -> NSError? {
|
||||
// Delete all of the keychain data of the given class
|
||||
func deleteDataForSecClass(secClass: CFTypeRef) -> NSError? {
|
||||
var request = NSMutableDictionary()
|
||||
let request = NSMutableDictionary()
|
||||
request.setObject(secClass, forKey: String(kSecClass))
|
||||
|
||||
var status: OSStatus? = SecItemDelete(request as CFDictionaryRef)
|
||||
let status: OSStatus? = SecItemDelete(request as CFDictionaryRef)
|
||||
|
||||
if let status = status {
|
||||
var statusCode = Int(status)
|
||||
let statusCode = Int(status)
|
||||
return Locksmith.keychainError(forCode: statusCode)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public enum Accessible: Int {
|
||||
WhenUnlockedThisDeviceOnly, AfterFirstUnlockThisDeviceOnly, AlwaysThisDeviceOnly
|
||||
}
|
||||
|
||||
public class LocksmithRequest: NSObject, DebugPrintable {
|
||||
public class LocksmithRequest: NSObject, CustomDebugStringConvertible {
|
||||
// Keychain Options
|
||||
// Required
|
||||
public var service: String = LocksmithDefaultService
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
> This is Locksmith’s compatibility branch for Swift 1.2
|
||||
|
||||
# Locksmith
|
||||
|
||||
A sane way to work with the iOS Keychain in Swift.
|
||||
@@ -16,9 +18,7 @@ A sane way to work with the iOS Keychain in Swift.
|
||||
Locksmith is available through [CocoaPods](http://cocoapods.org). To install
|
||||
it, simply add the following line to your Podfile:
|
||||
|
||||
pod "Locksmith"
|
||||
|
||||
Swift 2 support is available via the `2.0` branch.
|
||||
pod "Locksmith", :git => 'https://github.com/matthewpalmer/Locksmith.git', :branch => '1.2.2'
|
||||
|
||||
### Manual
|
||||
|
||||
|
||||
Reference in New Issue
Block a user