Skip to content

Commit

Permalink
Add Swift 1.2 support
Browse files Browse the repository at this point in the history
Merge branch 'ChaosCoder-master'

* ChaosCoder-master:
  Converted to Swift 1.2
  Trying to fix travis builds
  removing comments
  public'ing all the things
  kSecAttrAccessible
  Update README.md
  Update README.md
  Remove false Travis badge
  • Loading branch information
matthewpalmer committed Apr 9, 2015
2 parents 73d14af + fb40300 commit 8d825ab
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# * http://www.objc.io/issue-6/travis-ci.html
# * https://github.com/supermarin/xcpretty#usage

language: objective-c
language: swift
# cache: cocoapods
# podfile: Example/Podfile
# before_install:
Expand Down
28 changes: 25 additions & 3 deletions Pod/Classes/Locksmith.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import UIKit
import Security

public let LocksmithErrorDomain = "com.locksmith.error"
public let LocksmithDefaultService = NSBundle.mainBundle().infoDictionary![kCFBundleIdentifierKey] as String
public let LocksmithDefaultService = NSBundle.mainBundle().infoDictionary![kCFBundleIdentifierKey] as! String


public class Locksmith: NSObject {
// MARK: Perform request
class func performRequest(request: LocksmithRequest) -> (NSDictionary?, NSError?) {
public class func performRequest(request: LocksmithRequest) -> (NSDictionary?, NSError?) {
let type = request.type
//var result: Unmanaged<AnyObject>? = nil
var result: AnyObject?
Expand Down Expand Up @@ -130,6 +130,9 @@ public class Locksmith: NSObject {
options[String(kSecAttrService)] = request.service
options[String(kSecAttrSynchronizable)] = request.synchronizable
options[String(kSecClass)] = securityCode(request.securityClass)
if let accessibleMode = request.accessible {
options[String(kSecAttrAccessible)] = accessible(accessibleMode)
}

for (key, option) in options {
parsedRequest.setOptional(option, forKey: key)
Expand Down Expand Up @@ -220,6 +223,25 @@ public class Locksmith: NSObject {
return kSecClassGenericPassword
}
}

private class func accessible(accessible: Accessible) -> CFStringRef {
switch accessible {
case .WhenUnlock:
return kSecAttrAccessibleWhenUnlocked
case .AfterFirstUnlock:
return kSecAttrAccessibleAfterFirstUnlock
case .Always:
return kSecAttrAccessibleAlways
case .WhenPasscodeSetThisDeviceOnly:
return kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly
case .WhenUnlockedThisDeviceOnly:
return kSecAttrAccessibleWhenUnlockedThisDeviceOnly
case .AfterFirstUnlockThisDeviceOnly:
return kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
case .AlwaysThisDeviceOnly:
return kSecAttrAccessibleAlwaysThisDeviceOnly
}
}
}

// MARK: Convenient Class Methods
Expand Down Expand Up @@ -302,4 +324,4 @@ extension NSMutableDictionary {
self.setObject(object, forKey: key)
}
}
}
}
28 changes: 17 additions & 11 deletions Pod/Classes/LocksmithRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ public enum RequestType: Int {
case Create, Read, Update, Delete
}

public enum Accessible: Int {
case WhenUnlock, AfterFirstUnlock, Always, WhenPasscodeSetThisDeviceOnly,
WhenUnlockedThisDeviceOnly, AfterFirstUnlockThisDeviceOnly, AlwaysThisDeviceOnly
}

public class LocksmithRequest: NSObject, DebugPrintable {
// Keychain Options
// Required
var service: String = NSBundle.mainBundle().infoDictionary![kCFBundleIdentifierKey] as String // Default to Bundle Identifier
var userAccount: String
var type: RequestType = .Read // Default to non-destructive
public var service: String = NSBundle.mainBundle().infoDictionary![kCFBundleIdentifierKey] as! String // Default to Bundle Identifier
public var userAccount: String
public var type: RequestType = .Read // Default to non-destructive

// Optional
var securityClass: SecurityClass = .GenericPassword // Default to password lookup
var group: String?
var data: NSDictionary?
var matchLimit: MatchLimit = .One
var synchronizable = false
public var securityClass: SecurityClass = .GenericPassword // Default to password lookup
public var group: String?
public var data: NSDictionary?
public var matchLimit: MatchLimit = .One
public var synchronizable = false
public var accessible: Accessible?

// Debugging
override public var debugDescription: String {
Expand All @@ -44,13 +50,13 @@ public class LocksmithRequest: NSObject, DebugPrintable {
self.userAccount = userAccount
}

convenience init(userAccount: String, requestType: RequestType, service: String = LocksmithDefaultService) {
public convenience init(userAccount: String, requestType: RequestType, service: String = LocksmithDefaultService) {
self.init(userAccount: userAccount, service: service)
self.type = requestType
}

convenience init(userAccount: String, requestType: RequestType, data: NSDictionary, service: String = LocksmithDefaultService) {
public convenience init(userAccount: String, requestType: RequestType, data: NSDictionary, service: String = LocksmithDefaultService) {
self.init(userAccount: userAccount, requestType: requestType, service: service)
self.data = data
}
}
}
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A sane way to work with the iOS Keychain in Swift.

[![CI Status](http://img.shields.io/travis/matthewpalmer/Locksmith.svg?style=flat)](https://travis-ci.org/matthewpalmer/Locksmith)
<!--[![CI Status](http://img.shields.io/travis/matthewpalmer/Locksmith.svg?style=flat)](https://travis-ci.org/matthewpalmer/Locksmith)-->
[![Version](https://img.shields.io/cocoapods/v/Locksmith.svg?style=flat)](http://cocoadocs.org/docsets/Locksmith)
[![License](https://img.shields.io/cocoapods/l/Locksmith.svg?style=flat)](http://cocoadocs.org/docsets/Locksmith)
[![Platform](https://img.shields.io/cocoapods/p/Locksmith.svg?style=flat)](http://cocoadocs.org/docsets/Locksmith)
Expand All @@ -14,7 +14,9 @@ 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"
pod "Locksmith"

__Note__: Swift pods are currently only available in beta, so you need to `gem install cocoapods --pre` to use Locksmith.

### Manual

Expand Down Expand Up @@ -122,4 +124,4 @@ var synchronizable: Bool // Defaults to false

## License

Locksmith is available under the MIT license. See the LICENSE file for more info.
Locksmith is available under the MIT license. See the LICENSE file for more info.

0 comments on commit 8d825ab

Please sign in to comment.