|
@@ -25,6 +25,9 @@
|
|
|
|
|
|
import Foundation
|
|
import Foundation
|
|
import Security
|
|
import Security
|
|
|
|
+#if os(iOS) || os(OSX)
|
|
|
|
+import LocalAuthentication
|
|
|
|
+#endif
|
|
|
|
|
|
public let KeychainAccessErrorDomain = "com.kishikawakatsumi.KeychainAccess.error"
|
|
public let KeychainAccessErrorDomain = "com.kishikawakatsumi.KeychainAccess.error"
|
|
|
|
|
|
@@ -389,6 +392,13 @@ public final class Keychain {
|
|
return options.authenticationPrompt
|
|
return options.authenticationPrompt
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #if os(iOS) || os(OSX)
|
|
|
|
+ @available(iOS 9.0, OSX 10.11, *)
|
|
|
|
+ public var authenticationContext: LAContext? {
|
|
|
|
+ return options.authenticationContext as? LAContext
|
|
|
|
+ }
|
|
|
|
+ #endif
|
|
|
|
+
|
|
fileprivate let options: Options
|
|
fileprivate let options: Options
|
|
|
|
|
|
// MARK:
|
|
// MARK:
|
|
@@ -489,6 +499,15 @@ public final class Keychain {
|
|
return Keychain(options)
|
|
return Keychain(options)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #if os(iOS) || os(OSX)
|
|
|
|
+ @available(iOS 9.0, OSX 10.11, *)
|
|
|
|
+ public func authenticationContext(_ authenticationContext: LAContext) -> Keychain {
|
|
|
|
+ var options = self.options
|
|
|
|
+ options.authenticationContext = authenticationContext
|
|
|
|
+ return Keychain(options)
|
|
|
|
+ }
|
|
|
|
+ #endif
|
|
|
|
+
|
|
// MARK:
|
|
// MARK:
|
|
|
|
|
|
public func get(_ key: String) throws -> String? {
|
|
public func get(_ key: String) throws -> String? {
|
|
@@ -1050,6 +1069,7 @@ struct Options {
|
|
var comment: String?
|
|
var comment: String?
|
|
|
|
|
|
var authenticationPrompt: String?
|
|
var authenticationPrompt: String?
|
|
|
|
+ var authenticationContext: AnyObject?
|
|
|
|
|
|
var attributes = [String: Any]()
|
|
var attributes = [String: Any]()
|
|
}
|
|
}
|
|
@@ -1186,6 +1206,14 @@ extension Options {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #if !os(watchOS)
|
|
|
|
+ if #available(iOS 9.0, OSX 10.11, *) {
|
|
|
|
+ if authenticationContext != nil {
|
|
|
|
+ query[UseAuthenticationContext] = authenticationContext
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ #endif
|
|
|
|
+
|
|
return query
|
|
return query
|
|
}
|
|
}
|
|
|
|
|