Browse Source

Added ability to return data as reference

Evgenii Neumerzhitckii 6 years ago
parent
commit
aa1f2f9104
5 changed files with 22 additions and 17 deletions
  1. 0 1
      .swift-version
  2. 3 0
      CHANGELOG.md
  3. 1 1
      KeychainSwift.podspec
  4. 14 11
      README.md
  5. 4 4
      Sources/KeychainSwift.swift

+ 0 - 1
.swift-version

@@ -1 +0,0 @@
-5.0

+ 3 - 0
CHANGELOG.md

@@ -1,5 +1,8 @@
 # KeychainSwift version history
 
+## 15.0.0 (2019-04-24)
+
+Added ability to return data as reference ([mediym41](https://github.com/mediym41)).
 
 
 ## 14.0.0 (2019-04-03)

+ 1 - 1
KeychainSwift.podspec

@@ -1,6 +1,6 @@
 Pod::Spec.new do |s|
   s.name        = "KeychainSwift"
-  s.version     = "14.0.2"
+  s.version     = "15.0.0"
   s.license     = { :type => "MIT" }
   s.homepage    = "https://github.com/evgenyneu/keychain-swift"
   s.summary     = "A library for saving text and data in the Keychain with Swift."

+ 14 - 11
README.md

@@ -36,7 +36,7 @@ Simply add [KeychainSwiftDistrib.swift](https://github.com/evgenyneu/keychain-sw
 
 #### Setup with Carthage (iOS 8+)
 
-Alternatively, add `github "evgenyneu/keychain-swift" ~> 14.0` to your Cartfile and run `carthage update`.
+Alternatively, add `github "evgenyneu/keychain-swift" ~> 15.0` to your Cartfile and run `carthage update`.
 
 #### Setup with CocoaPods (iOS 8+)
 
@@ -44,7 +44,7 @@ If you are using CocoaPods add this text to your Podfile and run `pod install`.
 
     use_frameworks!
     target 'Your target name'
-    pod 'KeychainSwift', '~> 14.0'
+    pod 'KeychainSwift', '~> 15.0'
 
 
 #### Setup with Swift Package Manager
@@ -58,7 +58,7 @@ import PackageDescription
 let package = Package(
     name: "MyApp",
     dependencies: [
-        .package(url: "https://github.com/evgenyneu/keychain-swift.git", from: "14.0.0")
+        .package(url: "https://github.com/evgenyneu/keychain-swift.git", from: "15.0.0")
     ],
     targets: [
         .target(
@@ -104,14 +104,6 @@ keychain.set(dataObject, forKey: "my key")
 keychain.getData("my key")
 ```
 
-#### Reference to value
-
-```Swift
-let keychain = KeychainSwift()
-keychain.set(dataObject, forKey: "my key")
-keychain.getData("my key", isReference: true)
-```
-
 #### Removing keys from Keychain
 
 ```Swift
@@ -210,6 +202,16 @@ keychain.set("hello world", forKey: "my key")
 if keychain.lastResultCode != noErr { /* Report error */ }
 ```
 
+### Returning data as reference
+
+Use the `asReference: true` parameter to return the data as reference, which is needed for  [NEVPNProtocol](https://developer.apple.com/documentation/networkextension/nevpnprotocol).
+
+```Swift
+let keychain = KeychainSwift()
+keychain.set(dataObject, forKey: "my key")
+keychain.getData("my key", asReference: true)
+```
+
 ## Using KeychainSwift from Objective-C
 
 [This manual](https://github.com/evgenyneu/keychain-swift/wiki/Using-KeychainSwift-in-Objective-C-project) describes how to use KeychainSwift in Objective-C apps.
@@ -256,6 +258,7 @@ Here are some other Keychain libraries.
 * Thanks to [beny](https://github.com/beny) for adding Swift 4.2 support.
 * Thanks to [xuaninbox](https://github.com/xuaninbox) for fixing watchOS deployment target for Xcode 10.
 * Thanks to [schayes04](https://github.com/schayes04) for adding Swift 5.0 support.
+* Thanks to [mediym41](https://github.com/mediym41) for adding ability to return data as reference.
 
 
 

+ 4 - 4
Sources/KeychainSwift.swift

@@ -153,11 +153,11 @@ open class KeychainSwift {
   Retrieves the data from the keychain that corresponds to the given key.
   
   - parameter key: The key that is used to read the keychain item.
-  - parameter isReference: Flag is used to determine the returning value (reference to the value or value)
+  - parameter asReference: If true, returns the data as reference (needed for things like NEVPNProtocol).
   - returns: The text value from the keychain. Returns nil if unable to read the item.
   
   */
-  open func getData(_ key: String, isReference: Bool = false) -> Data? {
+  open func getData(_ key: String, asReference: Bool = false) -> Data? {
     // The lock prevents the code to be run simlultaneously
     // from multiple threads which may result in crashing
     readLock.lock()
@@ -171,8 +171,8 @@ open class KeychainSwift {
       KeychainSwiftConstants.matchLimit  : kSecMatchLimitOne
     ]
     
-    if isReference {
-      query[KeychainSwiftConstants.returnRefernce] = kCFBooleanTrue
+    if asReference {
+      query[KeychainSwiftConstants.returnReference] = kCFBooleanTrue
     } else {
       query[KeychainSwiftConstants.returnData] =  kCFBooleanTrue
     }