Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ec6d2f4ee7 | |||
| c302757509 | |||
| 267a0559b9 | |||
| 02f824664a | |||
| 6665a7e16f | |||
| 82b46fc760 | |||
| 6c30f710b2 | |||
| 7a6395f189 | |||
| c48ce652bd | |||
| 716759b767 | |||
| 3da0e97cc6 | |||
| 03b5015f4f | |||
| 1b0c092708 | |||
| 25917eaf15 | |||
| 4dce464fb0 | |||
| 5e508a7551 | |||
| a2e58ce87f | |||
| 825d7d2485 | |||
| 0418e37185 | |||
| c218c1fbea | |||
| 68515bdc2c | |||
| f38046bb9e | |||
| e804dd0452 | |||
| 04c6084a8f | |||
| fbc549973b | |||
| 4ad7ca14e6 | |||
| 582f74e305 | |||
| 1758691bc2 | |||
| 2a21d9d0d1 | |||
| ca70968264 | |||
| 8017ad0d4e | |||
| e77cffad00 | |||
| 8d825ab368 | |||
| fb4030034d | |||
| 8f21125a77 | |||
| 3d6ce4d5f0 | |||
| 4caf3e99b4 | |||
| d04d2fe9b7 | |||
| 440de6f490 | |||
| 658233b596 | |||
| 4246e19952 | |||
| b988530bce | |||
| 73d14afcfa |
+1
-1
@@ -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:
|
||||
|
||||
@@ -203,6 +203,7 @@
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
CLASSPREFIX = Locksmith;
|
||||
LastSwiftUpdateCheck = 0700;
|
||||
LastUpgradeCheck = 0510;
|
||||
ORGANIZATIONNAME = matthewpalmer;
|
||||
TargetAttributes = {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
source 'https://github.com/CocoaPods/Specs.git'
|
||||
|
||||
use_frameworks!
|
||||
|
||||
platform :ios, '8.0'
|
||||
|
||||
target 'Locksmith', :exclusive => true do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
PODS:
|
||||
- Expecta (0.3.1)
|
||||
- Locksmith (1.2.0)
|
||||
- Locksmith (1.2.1)
|
||||
- Specta (0.2.1)
|
||||
|
||||
DEPENDENCIES:
|
||||
@@ -10,11 +10,11 @@ DEPENDENCIES:
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Locksmith:
|
||||
:path: ../
|
||||
:path: "../"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Expecta: 03aabd0a89d8dea843baecb19a7fd7466a69a31d
|
||||
Locksmith: 392ae330eb455e824dab5b714b6719eb29ef5038
|
||||
Specta: 9141310f46b1f68b676650ff2854e1ed0b74163a
|
||||
Expecta: a354d4633409dd9fe8c4f5ff5130426adbe31628
|
||||
Locksmith: 770f6c5c6e5c5c712d1f00e709c62b8a7240c716
|
||||
Specta: 15a276a6343867b426d5ed135d5aa4d04123a573
|
||||
|
||||
COCOAPODS: 0.36.0.beta.1
|
||||
COCOAPODS: 0.36.3
|
||||
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
#
|
||||
# Be sure to run `pod lib lint Locksmith.podspec' to ensure this is a
|
||||
# valid spec and remove all comments before submitting the spec.
|
||||
#
|
||||
# Any lines starting with a # are optional, but encouraged
|
||||
#
|
||||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
|
||||
#
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Locksmith"
|
||||
s.version = "1.2.0"
|
||||
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.
|
||||
It provides a fast and intuitive way to work with the C Keychain API.
|
||||
Results are provided as tuples, and errors are informative and easily detected.
|
||||
DESC
|
||||
s.homepage = "https://github.com/matthewpalmer/Locksmith"
|
||||
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
|
||||
s.license = 'MIT'
|
||||
s.author = { "matthewpalmer" => "matt@matthewpalmer.net" }
|
||||
s.source = { :git => "https://github.com/matthewpalmer/Locksmith.git", :tag => s.version.to_s }
|
||||
s.social_media_url = 'https://twitter.com/_matthewpalmer'
|
||||
|
||||
s.platform = :ios, '8.0'
|
||||
s.requires_arc = true
|
||||
|
||||
s.source_files = 'Pod/Classes'
|
||||
s.resource_bundles = {
|
||||
'Locksmith' => ['Pod/Assets/*.png']
|
||||
}
|
||||
|
||||
# s.public_header_files = 'Pod/Classes/**/*.h'
|
||||
# s.frameworks = 'UIKit', 'MapKit'
|
||||
# s.dependency 'AFNetworking', '~> 2.3'
|
||||
end
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Locksmith",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"summary": "Locksmith is a sane way to work with the iOS Keychain in Swift.",
|
||||
"description": " Locksmith is a sane way to work with the iOS Keychain in Swift.\n It provides a fast and intuitive way to work with the C Keychain API.\n Results are provided as tuples, and errors are informative and easily detected.\n",
|
||||
"homepage": "https://github.com/matthewpalmer/Locksmith",
|
||||
@@ -10,7 +10,7 @@
|
||||
},
|
||||
"source": {
|
||||
"git": "https://github.com/matthewpalmer/Locksmith.git",
|
||||
"tag": "1.2.0"
|
||||
"tag": "1.2.1"
|
||||
},
|
||||
"social_media_url": "https://twitter.com/_matthewpalmer",
|
||||
"platforms": {
|
||||
|
||||
Generated
+6
-6
@@ -1,6 +1,6 @@
|
||||
PODS:
|
||||
- Expecta (0.3.1)
|
||||
- Locksmith (1.2.0)
|
||||
- Locksmith (1.2.1)
|
||||
- Specta (0.2.1)
|
||||
|
||||
DEPENDENCIES:
|
||||
@@ -10,11 +10,11 @@ DEPENDENCIES:
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Locksmith:
|
||||
:path: ../
|
||||
:path: "../"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Expecta: 03aabd0a89d8dea843baecb19a7fd7466a69a31d
|
||||
Locksmith: 392ae330eb455e824dab5b714b6719eb29ef5038
|
||||
Specta: 9141310f46b1f68b676650ff2854e1ed0b74163a
|
||||
Expecta: a354d4633409dd9fe8c4f5ff5130426adbe31628
|
||||
Locksmith: 770f6c5c6e5c5c712d1f00e709c62b8a7240c716
|
||||
Specta: 15a276a6343867b426d5ed135d5aa4d04123a573
|
||||
|
||||
COCOAPODS: 0.36.0.beta.1
|
||||
COCOAPODS: 0.36.3
|
||||
|
||||
+1747
-6151
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.2.0</string>
|
||||
<string>1.2.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
Example/Pods/Target Support Files/Pods-Locksmith-Locksmith/Pods-Locksmith-Locksmith-Private.xcconfig
Generated
+4
-3
@@ -3,7 +3,8 @@ CONFIGURATION_BUILD_DIR = $PODS_FRAMEWORK_BUILD_PATH
|
||||
FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH"
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/Locksmith" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Expecta" "${PODS_ROOT}/Headers/Public/Locksmith" "${PODS_ROOT}/Headers/Public/Specta"
|
||||
OTHER_LDFLAGS = -ObjC
|
||||
OTHER_SWIFT_FLAGS = "-D COCOAPODS"
|
||||
OTHER_LDFLAGS = ${PODS_LOCKSMITH_LOCKSMITH_OTHER_LDFLAGS} -ObjC
|
||||
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
|
||||
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-Locksmith
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
SKIP_INSTALL = YES
|
||||
Generated
+1
@@ -0,0 +1 @@
|
||||
PODS_LOCKSMITH_LOCKSMITH_OTHER_LDFLAGS = -framework "Security" -framework "UIKit"
|
||||
+1
-1
@@ -10,5 +10,5 @@
|
||||
#define COCOAPODS_POD_AVAILABLE_Locksmith
|
||||
#define COCOAPODS_VERSION_MAJOR_Locksmith 1
|
||||
#define COCOAPODS_VERSION_MINOR_Locksmith 2
|
||||
#define COCOAPODS_VERSION_PATCH_Locksmith 0
|
||||
#define COCOAPODS_VERSION_PATCH_Locksmith 1
|
||||
|
||||
|
||||
+7
-4
@@ -11,7 +11,7 @@ install_framework()
|
||||
local source="${BUILT_PRODUCTS_DIR}/Pods-Locksmith/$1"
|
||||
local destination="${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
|
||||
if [ -L ${source} ]; then
|
||||
if [ -L "${source}" ]; then
|
||||
echo "Symlinked..."
|
||||
source=$(readlink "${source}")
|
||||
fi
|
||||
@@ -28,10 +28,13 @@ install_framework()
|
||||
local basename
|
||||
basename=$(echo $1 | sed -E s/\\..+// && exit ${PIPESTATUS[0]})
|
||||
local swift_runtime_libs
|
||||
swift_runtime_libs=$(xcrun otool -LX "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/$1/${basename}" | grep @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]})
|
||||
swift_runtime_libs=$(xcrun otool -LX "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/$1/${basename}" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]})
|
||||
for lib in $swift_runtime_libs; do
|
||||
echo "rsync -av \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
|
||||
rsync -av "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
|
||||
echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
|
||||
rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
|
||||
if [ "${CODE_SIGNING_REQUIRED}" == "YES" ]; then
|
||||
code_sign "${destination}/${lib}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -6,6 +6,8 @@ mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt
|
||||
> "$RESOURCES_TO_COPY"
|
||||
|
||||
XCASSET_FILES=""
|
||||
|
||||
install_resource()
|
||||
{
|
||||
case $1 in
|
||||
@@ -36,6 +38,7 @@ install_resource()
|
||||
xcrun mapc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm"
|
||||
;;
|
||||
*.xcassets)
|
||||
XCASSET_FILES="$XCASSET_FILES '${PODS_ROOT}/$1'"
|
||||
;;
|
||||
/*)
|
||||
echo "$1"
|
||||
@@ -54,7 +57,7 @@ if [[ "${ACTION}" == "install" ]]; then
|
||||
fi
|
||||
rm -f "$RESOURCES_TO_COPY"
|
||||
|
||||
if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ `find . -name '*.xcassets' | wc -l` -ne 0 ]
|
||||
if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ]
|
||||
then
|
||||
case "${TARGETED_DEVICE_FAMILY}" in
|
||||
1,2)
|
||||
@@ -70,5 +73,6 @@ then
|
||||
TARGET_DEVICE_ARGS="--target-device mac"
|
||||
;;
|
||||
esac
|
||||
find "${PWD}" -name "*.xcassets" -print0 | xargs -0 actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
while read line; do XCASSET_FILES="$XCASSET_FILES '$line'"; done <<<$(find "$PWD" -name "*.xcassets" | egrep -v "^$PODS_ROOT")
|
||||
echo $XCASSET_FILES | xargs actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
fi
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@ FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH"
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
|
||||
OTHER_CFLAGS = $(inherited) -iquote "$PODS_FRAMEWORK_BUILD_PATH/Locksmith.framework/Headers"
|
||||
OTHER_LDFLAGS = -ObjC -framework "Locksmith"
|
||||
OTHER_LDFLAGS = $(inherited) -ObjC -framework "Locksmith"
|
||||
OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS)
|
||||
OTHER_SWIFT_FLAGS = "-D COCOAPODS"
|
||||
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
|
||||
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-Locksmith
|
||||
PODS_ROOT = ${SRCROOT}/Pods
|
||||
+2
-2
@@ -2,8 +2,8 @@ FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH"
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
|
||||
OTHER_CFLAGS = $(inherited) -iquote "$PODS_FRAMEWORK_BUILD_PATH/Locksmith.framework/Headers"
|
||||
OTHER_LDFLAGS = -ObjC -framework "Locksmith"
|
||||
OTHER_LDFLAGS = $(inherited) -ObjC -framework "Locksmith"
|
||||
OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS)
|
||||
OTHER_SWIFT_FLAGS = "-D COCOAPODS"
|
||||
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
|
||||
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-Locksmith
|
||||
PODS_ROOT = ${SRCROOT}/Pods
|
||||
+2
-1
@@ -5,4 +5,5 @@ GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/Expecta" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Expecta" "${PODS_ROOT}/Headers/Public/Locksmith" "${PODS_ROOT}/Headers/Public/Specta"
|
||||
OTHER_LDFLAGS = ${PODS_TESTS_EXPECTA_OTHER_LDFLAGS} -ObjC
|
||||
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-Tests
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
SKIP_INSTALL = YES
|
||||
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.2.0</string>
|
||||
<string>1.2.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
Generated
+4
-3
@@ -3,7 +3,8 @@ CONFIGURATION_BUILD_DIR = $PODS_FRAMEWORK_BUILD_PATH
|
||||
FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH"
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/Locksmith" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Expecta" "${PODS_ROOT}/Headers/Public/Locksmith" "${PODS_ROOT}/Headers/Public/Specta"
|
||||
OTHER_LDFLAGS = -ObjC
|
||||
OTHER_SWIFT_FLAGS = "-D COCOAPODS"
|
||||
OTHER_LDFLAGS = ${PODS_TESTS_LOCKSMITH_OTHER_LDFLAGS} -ObjC
|
||||
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
|
||||
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-Tests
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
SKIP_INSTALL = YES
|
||||
+1
@@ -0,0 +1 @@
|
||||
PODS_TESTS_LOCKSMITH_OTHER_LDFLAGS = -framework "Security" -framework "UIKit"
|
||||
+2
-1
@@ -5,4 +5,5 @@ GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/Specta" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/Expecta" "${PODS_ROOT}/Headers/Public/Locksmith" "${PODS_ROOT}/Headers/Public/Specta"
|
||||
OTHER_LDFLAGS = ${PODS_TESTS_SPECTA_OTHER_LDFLAGS} -ObjC
|
||||
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-Tests
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
PODS_ROOT = ${SRCROOT}
|
||||
SKIP_INSTALL = YES
|
||||
@@ -16,7 +16,7 @@
|
||||
#define COCOAPODS_POD_AVAILABLE_Locksmith
|
||||
#define COCOAPODS_VERSION_MAJOR_Locksmith 1
|
||||
#define COCOAPODS_VERSION_MINOR_Locksmith 2
|
||||
#define COCOAPODS_VERSION_PATCH_Locksmith 0
|
||||
#define COCOAPODS_VERSION_PATCH_Locksmith 1
|
||||
|
||||
// Specta
|
||||
#define COCOAPODS_POD_AVAILABLE_Specta
|
||||
|
||||
@@ -11,7 +11,7 @@ install_framework()
|
||||
local source="${BUILT_PRODUCTS_DIR}/Pods-Tests/$1"
|
||||
local destination="${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
|
||||
|
||||
if [ -L ${source} ]; then
|
||||
if [ -L "${source}" ]; then
|
||||
echo "Symlinked..."
|
||||
source=$(readlink "${source}")
|
||||
fi
|
||||
@@ -28,10 +28,13 @@ install_framework()
|
||||
local basename
|
||||
basename=$(echo $1 | sed -E s/\\..+// && exit ${PIPESTATUS[0]})
|
||||
local swift_runtime_libs
|
||||
swift_runtime_libs=$(xcrun otool -LX "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/$1/${basename}" | grep @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]})
|
||||
swift_runtime_libs=$(xcrun otool -LX "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/$1/${basename}" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]})
|
||||
for lib in $swift_runtime_libs; do
|
||||
echo "rsync -av \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
|
||||
rsync -av "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
|
||||
echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
|
||||
rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
|
||||
if [ "${CODE_SIGNING_REQUIRED}" == "YES" ]; then
|
||||
code_sign "${destination}/${lib}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt
|
||||
> "$RESOURCES_TO_COPY"
|
||||
|
||||
XCASSET_FILES=""
|
||||
|
||||
install_resource()
|
||||
{
|
||||
case $1 in
|
||||
@@ -36,6 +38,7 @@ install_resource()
|
||||
xcrun mapc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm"
|
||||
;;
|
||||
*.xcassets)
|
||||
XCASSET_FILES="$XCASSET_FILES '${PODS_ROOT}/$1'"
|
||||
;;
|
||||
/*)
|
||||
echo "$1"
|
||||
@@ -54,7 +57,7 @@ if [[ "${ACTION}" == "install" ]]; then
|
||||
fi
|
||||
rm -f "$RESOURCES_TO_COPY"
|
||||
|
||||
if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ `find . -name '*.xcassets' | wc -l` -ne 0 ]
|
||||
if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ]
|
||||
then
|
||||
case "${TARGETED_DEVICE_FAMILY}" in
|
||||
1,2)
|
||||
@@ -70,5 +73,6 @@ then
|
||||
TARGET_DEVICE_ARGS="--target-device mac"
|
||||
;;
|
||||
esac
|
||||
find "${PWD}" -name "*.xcassets" -print0 | xargs -0 actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
while read line; do XCASSET_FILES="$XCASSET_FILES '$line'"; done <<<$(find "$PWD" -name "*.xcassets" | egrep -v "^$PODS_ROOT")
|
||||
echo $XCASSET_FILES | xargs actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
|
||||
fi
|
||||
|
||||
@@ -2,8 +2,8 @@ FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH"
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
|
||||
OTHER_CFLAGS = $(inherited) -iquote "$PODS_FRAMEWORK_BUILD_PATH/Expecta.framework/Headers" -iquote "$PODS_FRAMEWORK_BUILD_PATH/Locksmith.framework/Headers" -iquote "$PODS_FRAMEWORK_BUILD_PATH/Specta.framework/Headers"
|
||||
OTHER_LDFLAGS = -ObjC -framework "Expecta" -framework "Locksmith" -framework "Specta"
|
||||
OTHER_LDFLAGS = $(inherited) -ObjC -framework "Expecta" -framework "Locksmith" -framework "Specta"
|
||||
OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS)
|
||||
OTHER_SWIFT_FLAGS = "-D COCOAPODS"
|
||||
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
|
||||
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-Tests
|
||||
PODS_ROOT = ${SRCROOT}/Pods
|
||||
@@ -2,8 +2,8 @@ FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH"
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
|
||||
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
|
||||
OTHER_CFLAGS = $(inherited) -iquote "$PODS_FRAMEWORK_BUILD_PATH/Expecta.framework/Headers" -iquote "$PODS_FRAMEWORK_BUILD_PATH/Locksmith.framework/Headers" -iquote "$PODS_FRAMEWORK_BUILD_PATH/Specta.framework/Headers"
|
||||
OTHER_LDFLAGS = -ObjC -framework "Expecta" -framework "Locksmith" -framework "Specta"
|
||||
OTHER_LDFLAGS = $(inherited) -ObjC -framework "Expecta" -framework "Locksmith" -framework "Specta"
|
||||
OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS)
|
||||
OTHER_SWIFT_FLAGS = "-D COCOAPODS"
|
||||
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
|
||||
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-Tests
|
||||
PODS_ROOT = ${SRCROOT}/Pods
|
||||
@@ -2,23 +2,18 @@
|
||||
// LocksmithTests.swift
|
||||
// LocksmithTests
|
||||
//
|
||||
// Copyright (c) 2014 Mathew Palmer. All rights reserved.
|
||||
// Created by Matthew Palmer on 27/06/2015.
|
||||
// Copyright © 2015 Matthew Palmer. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import XCTest
|
||||
import Locksmith
|
||||
|
||||
let myService = "myService"
|
||||
let sampleData = ["key": "value"]
|
||||
let myUserAccount = "myUserAccount"
|
||||
|
||||
class LocksmithTests: XCTestCase {
|
||||
class LocksmithDemoTests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
Locksmith.clearKeychain()
|
||||
try! Locksmith.clearKeychain()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
@@ -26,99 +21,92 @@ class LocksmithTests: XCTestCase {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
// public class func saveData(data: Dictionary<String, String>, inService service: String, forUserAccount userAccount: String) -> NSError?
|
||||
func testSaveData_Once() {
|
||||
let error = Locksmith.saveData(["key": "value"], forUserAccount: myUserAccount, inService: myService)
|
||||
XCTAssert(error == nil, "❌: saving data")
|
||||
try! Locksmith.saveData(["key": "value"], forUserAccount: "myUserAccount", inService: "myService")
|
||||
// XCTAssert(error == nil, "❌: saving data")
|
||||
}
|
||||
|
||||
func testSaveData_Multiple() {
|
||||
var errors: [NSError?] = []
|
||||
// var errors: [NSError?] = []
|
||||
for i in 0...10 {
|
||||
errors.append(Locksmith.saveData(["key": "value \(i)"], forUserAccount: "myAccount\(i)", inService: "myService"))
|
||||
try! Locksmith.saveData(["key": "value \(i)"], forUserAccount: "myAccount\(i)", inService: "myService")
|
||||
}
|
||||
XCTAssert(errors.filter({ $0 != nil }).isEmpty, "❌: saving multiple items")
|
||||
// XCTAssert(errors.filter({ $0 != nil }).isEmpty, "❌: saving multiple items")
|
||||
}
|
||||
|
||||
func testSaveData_Duplicate() {
|
||||
// Should be successful
|
||||
|
||||
let error1 = Locksmith.saveData(sampleData, forUserAccount: "user", inService: myService)
|
||||
try! Locksmith.saveData(["key": "value"], forUserAccount: "user", inService: "myService")
|
||||
|
||||
// Should fail
|
||||
let error2 = Locksmith.saveData(sampleData, forUserAccount: "user", inService: "myService")
|
||||
|
||||
XCTAssert(error1 == nil && error2 != nil, "❌: saving duplicate data")
|
||||
}
|
||||
|
||||
// Test using default values for the service
|
||||
func testWorkflow_Defaults() {
|
||||
let error1 = Locksmith.saveData(sampleData, forUserAccount: "me")
|
||||
let error2 = Locksmith.saveData(sampleData, forUserAccount: "me2")
|
||||
|
||||
XCTAssert(error1 == nil && error2 == nil, "❌: saving with default service")
|
||||
|
||||
let (dict1, err1) = Locksmith.loadDataForUserAccount("me")
|
||||
let (dict2, err2) = Locksmith.loadDataForUserAccount("me2")
|
||||
|
||||
XCTAssert(dict1 != nil && dict2 != nil && err1 == nil && err2 == nil, "❌: loading with default service")
|
||||
do {
|
||||
try Locksmith.saveData(["key": "value"], forUserAccount: "user", inService: "myService")
|
||||
} catch {
|
||||
XCTAssert(true)
|
||||
}
|
||||
}
|
||||
|
||||
// Setup the keychain for requests that use pre-existing values on the keychain (update, read, delete)
|
||||
func setupLoads() {
|
||||
Locksmith.saveData(["key": "value"], forUserAccount: "user1", inService: "myService")
|
||||
Locksmith.saveData(["anotherkey": "anothervalue"], forUserAccount: "user2", inService: "myService")
|
||||
Locksmith.saveData(["word": "definition"], forUserAccount: "user3", inService: "myService")
|
||||
try! Locksmith.saveData(["key": "value"], forUserAccount: "user1", inService: "myService")
|
||||
try! Locksmith.saveData(["anotherkey": "anothervalue"], forUserAccount: "user2", inService: "myService")
|
||||
try! Locksmith.saveData(["word": "definition"], forUserAccount: "user3", inService: "myService")
|
||||
}
|
||||
|
||||
// public class func loadDataInService(service: String, forUserAccount userAccount: String) -> (NSDictionary?, NSError?)
|
||||
func testLoadData_Once() {
|
||||
setupLoads()
|
||||
|
||||
let (dictionary, error) = Locksmith.loadDataForUserAccount("user1", inService: "myService")
|
||||
XCTAssert(dictionary!.valueForKey("key")! as NSString == "value" && error == nil, "❌: loading one item")
|
||||
let dictionary = Locksmith.loadDataForUserAccount("user1", inService: "myService")
|
||||
XCTAssert(dictionary!.valueForKey("key") as! NSString == "value", "❌: loading one item")
|
||||
}
|
||||
|
||||
func testLoadData_Multiple() {
|
||||
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")
|
||||
|
||||
XCTAssert(dictionary!.valueForKey("key")! as NSString == "value" && error == nil, "❌: loading multiple items")
|
||||
XCTAssert(dictionary2!.valueForKey("anotherkey")! as NSString == "anothervalue" && error == nil, "❌: loading multiple items")
|
||||
XCTAssert(dictionary3!.valueForKey("word")! as NSString == "definition" && error == nil, "❌: loading multiple items")
|
||||
do {
|
||||
let dictionary = Locksmith.loadDataForUserAccount("user1", inService: "myService")
|
||||
let dictionary2 = Locksmith.loadDataForUserAccount("user2", inService: "myService")
|
||||
let dictionary3 = Locksmith.loadDataForUserAccount("user3", inService: "myService")
|
||||
|
||||
XCTAssert(dictionary!.valueForKey("key") as! NSString == "value", "❌: loading multiple items")
|
||||
XCTAssert(dictionary2!.valueForKey("anotherkey") as! NSString == "anothervalue", "❌: loading multiple items")
|
||||
XCTAssert(dictionary3!.valueForKey("word") as! NSString == "definition", "❌: loading multiple items")
|
||||
} catch {
|
||||
XCTAssert(false)
|
||||
}
|
||||
}
|
||||
|
||||
// public class func updateData(data: Dictionary<String, String>, inService service: String, forUserAccount userAccount: String) -> NSError?
|
||||
func testUpdateData() {
|
||||
setupLoads()
|
||||
|
||||
let error = Locksmith.updateData(["key": "newvalue"], forUserAccount: "user1", inService: "myService")
|
||||
let (dictionary, err) = Locksmith.loadDataForUserAccount("user1", inService: "myService")
|
||||
XCTAssert(dictionary!.valueForKey("key")! as NSString == "newvalue" && error == nil, "❌: updating item")
|
||||
try! Locksmith.updateData(["key": "newvalue"], forUserAccount: "user1", inService: "myService")
|
||||
let dictionary = Locksmith.loadDataForUserAccount("user1", inService: "myService")
|
||||
|
||||
XCTAssert(dictionary!.valueForKey("key") as! NSString == "newvalue", "❌: updating item")
|
||||
|
||||
// Updating an item that doesn't exist should create that item (i.e. performs a regular create request)
|
||||
let error2 = Locksmith.updateData(["key": "anothervalue"], forUserAccount: "user1", inService: "myService")
|
||||
XCTAssert(error2 == nil, "❌: updating item that doesn't exist")
|
||||
try! Locksmith.updateData(["key": "anothervalue"], forUserAccount: "user1", inService: "myService")
|
||||
XCTAssert(true, "❌: updating item that doesn't exist")
|
||||
}
|
||||
|
||||
// public class func deleteDataInService(service: String, forUserAccount userAccount: String) -> NSError?
|
||||
func testDeleteData() {
|
||||
setupLoads()
|
||||
|
||||
let error = Locksmith.deleteDataForUserAccount("user1", inService: "myService")
|
||||
XCTAssert(error == nil, "❌: deleting existing item")
|
||||
try! Locksmith.deleteDataForUserAccount("user1", inService: "myService")
|
||||
XCTAssert(true, "❌: deleting existing item")
|
||||
|
||||
let error2 = Locksmith.deleteDataForUserAccount("user1", inService: "myService")
|
||||
XCTAssert(error2 != nil, "❌: deleting non existent item")
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measureBlock() {
|
||||
// Put the code you want to measure the time of here.
|
||||
do {
|
||||
// Should fail
|
||||
try Locksmith.deleteDataForUserAccount("user1", inService: "myService")
|
||||
XCTAssert(false, "❌: did not throw error on deleting non existent item")
|
||||
} catch {
|
||||
XCTAssert(true, "❌: deleting non existent item")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Locksmith"
|
||||
s.version = "1.2.0"
|
||||
s.version = "2.0"
|
||||
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.
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
BFFB19D61A4870A300CCFFC3 /* Locksmith.h in Headers */ = {isa = PBXBuildFile; fileRef = BFFB19D51A4870A300CCFFC3 /* Locksmith.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
9D60D8141B10927B00BE14A9 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9D60D8131B10927B00BE14A9 /* Info.plist */; };
|
||||
9DF0A2C01B0E394F0049F83A /* Locksmith.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DF0A2BE1B0E394F0049F83A /* Locksmith.swift */; };
|
||||
9DF0A2C11B0E394F0049F83A /* LocksmithRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DF0A2BF1B0E394F0049F83A /* LocksmithRequest.swift */; };
|
||||
9DF0A2C81B0E3D370049F83A /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9DF0A2C71B0E3D370049F83A /* Info.plist */; };
|
||||
BFFB19DC1A4870A300CCFFC3 /* Locksmith.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFFB19D01A4870A300CCFFC3 /* Locksmith.framework */; };
|
||||
BFFB19E31A4870A300CCFFC3 /* LocksmithTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFFB19E21A4870A300CCFFC3 /* LocksmithTests.swift */; };
|
||||
BFFB19EE1A4870E400CCFFC3 /* LocksmithRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFFB19EC1A4870E400CCFFC3 /* LocksmithRequest.swift */; };
|
||||
BFFB19EF1A4870E400CCFFC3 /* Locksmith.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFFB19ED1A4870E400CCFFC3 /* Locksmith.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -25,14 +26,13 @@
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
9D60D8131B10927B00BE14A9 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Pod/Info.plist; sourceTree = SOURCE_ROOT; };
|
||||
9DF0A2BE1B0E394F0049F83A /* Locksmith.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Locksmith.swift; path = Pod/Classes/Locksmith.swift; sourceTree = SOURCE_ROOT; };
|
||||
9DF0A2BF1B0E394F0049F83A /* LocksmithRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LocksmithRequest.swift; path = Pod/Classes/LocksmithRequest.swift; sourceTree = SOURCE_ROOT; };
|
||||
9DF0A2C71B0E3D370049F83A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
BFFB19D01A4870A300CCFFC3 /* Locksmith.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Locksmith.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
BFFB19D41A4870A300CCFFC3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
BFFB19D51A4870A300CCFFC3 /* Locksmith.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Locksmith.h; sourceTree = "<group>"; };
|
||||
BFFB19DB1A4870A300CCFFC3 /* LocksmithTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LocksmithTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
BFFB19E11A4870A300CCFFC3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
BFFB19E21A4870A300CCFFC3 /* LocksmithTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocksmithTests.swift; sourceTree = "<group>"; };
|
||||
BFFB19EC1A4870E400CCFFC3 /* LocksmithRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocksmithRequest.swift; sourceTree = "<group>"; };
|
||||
BFFB19ED1A4870E400CCFFC3 /* Locksmith.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Locksmith.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -75,9 +75,8 @@
|
||||
BFFB19D21A4870A300CCFFC3 /* Locksmith */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
BFFB19EC1A4870E400CCFFC3 /* LocksmithRequest.swift */,
|
||||
BFFB19ED1A4870E400CCFFC3 /* Locksmith.swift */,
|
||||
BFFB19D51A4870A300CCFFC3 /* Locksmith.h */,
|
||||
9DF0A2BE1B0E394F0049F83A /* Locksmith.swift */,
|
||||
9DF0A2BF1B0E394F0049F83A /* LocksmithRequest.swift */,
|
||||
BFFB19D31A4870A300CCFFC3 /* Supporting Files */,
|
||||
);
|
||||
path = Locksmith;
|
||||
@@ -86,7 +85,7 @@
|
||||
BFFB19D31A4870A300CCFFC3 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
BFFB19D41A4870A300CCFFC3 /* Info.plist */,
|
||||
9D60D8131B10927B00BE14A9 /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
@@ -103,7 +102,7 @@
|
||||
BFFB19E01A4870A300CCFFC3 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
BFFB19E11A4870A300CCFFC3 /* Info.plist */,
|
||||
9DF0A2C71B0E3D370049F83A /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
@@ -115,7 +114,6 @@
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
BFFB19D61A4870A300CCFFC3 /* Locksmith.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -164,6 +162,7 @@
|
||||
BFFB19C71A4870A300CCFFC3 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0700;
|
||||
LastUpgradeCheck = 0610;
|
||||
ORGANIZATIONNAME = "Mathew Palmer";
|
||||
TargetAttributes = {
|
||||
@@ -198,6 +197,7 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
9D60D8141B10927B00BE14A9 /* Info.plist in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -205,6 +205,7 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
9DF0A2C81B0E3D370049F83A /* Info.plist in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -215,8 +216,8 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
BFFB19EF1A4870E400CCFFC3 /* Locksmith.swift in Sources */,
|
||||
BFFB19EE1A4870E400CCFFC3 /* LocksmithRequest.swift in Sources */,
|
||||
9DF0A2C11B0E394F0049F83A /* LocksmithRequest.swift in Sources */,
|
||||
9DF0A2C01B0E394F0049F83A /* Locksmith.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -274,7 +275,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
@@ -314,7 +315,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
@@ -327,11 +328,13 @@
|
||||
BFFB19E71A4870A300CCFFC3 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INFOPLIST_FILE = Locksmith/Info.plist;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Pod/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -343,11 +346,13 @@
|
||||
BFFB19E81A4870A300CCFFC3 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INFOPLIST_FILE = Locksmith/Info.plist;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Pod/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -367,7 +372,7 @@
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
INFOPLIST_FILE = LocksmithTests/Info.plist;
|
||||
INFOPLIST_FILE = LockSmithTests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
@@ -380,7 +385,7 @@
|
||||
"$(SDKROOT)/Developer/Library/Frameworks",
|
||||
"$(inherited)",
|
||||
);
|
||||
INFOPLIST_FILE = LocksmithTests/Info.plist;
|
||||
INFOPLIST_FILE = LockSmithTests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0630"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "BFFB19CF1A4870A300CCFFC3"
|
||||
BuildableName = "Locksmith.framework"
|
||||
BlueprintName = "Locksmith"
|
||||
ReferencedContainer = "container:Locksmith.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "BFFB19DA1A4870A300CCFFC3"
|
||||
BuildableName = "LocksmithTests.xctest"
|
||||
BlueprintName = "LocksmithTests"
|
||||
ReferencedContainer = "container:Locksmith.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
buildConfiguration = "Debug">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "BFFB19DA1A4870A300CCFFC3"
|
||||
BuildableName = "LocksmithTests.xctest"
|
||||
BlueprintName = "LocksmithTests"
|
||||
ReferencedContainer = "container:Locksmith.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "BFFB19CF1A4870A300CCFFC3"
|
||||
BuildableName = "Locksmith.framework"
|
||||
BlueprintName = "Locksmith"
|
||||
ReferencedContainer = "container:Locksmith.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Debug"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "BFFB19CF1A4870A300CCFFC3"
|
||||
BuildableName = "Locksmith.framework"
|
||||
BlueprintName = "Locksmith"
|
||||
ReferencedContainer = "container:Locksmith.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Release"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "BFFB19CF1A4870A300CCFFC3"
|
||||
BuildableName = "Locksmith.framework"
|
||||
BlueprintName = "Locksmith"
|
||||
ReferencedContainer = "container:Locksmith.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -1,108 +1,243 @@
|
||||
//
|
||||
// LocksmithTests.swift
|
||||
// LocksmithTests
|
||||
// Locksmith.swift
|
||||
//
|
||||
// Created by Michael Hahn on 12/22/14.
|
||||
// Copyright (c) 2014 Mathew Palmer. All rights reserved.
|
||||
// Created by Matthew Palmer on 26/10/2014.
|
||||
// Copyright (c) 2014 Colour Coding. All rights reserved.
|
||||
//
|
||||
|
||||
@testable import Locksmith
|
||||
import CoreFoundation
|
||||
import UIKit
|
||||
import XCTest
|
||||
import Locksmith
|
||||
import Security
|
||||
|
||||
class LocksmithTests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
Locksmith.clearKeychain()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
public let LocksmithDefaultService = NSBundle.mainBundle().infoDictionary![String(kCFBundleIdentifierKey)] as? String ?? "com.locksmith.defaultService"
|
||||
|
||||
// public class func saveData(data: Dictionary<String, String>, inService service: String, forUserAccount userAccount: String) -> NSError?
|
||||
func testSaveData_Once() {
|
||||
var error = Locksmith.saveData(["key": "value"], inService: "myService", forUserAccount: "myUserAccount")
|
||||
XCTAssert(error == nil, "❌: saving data")
|
||||
}
|
||||
// MARK: Locksmith Error
|
||||
public enum LocksmithError: String, ErrorType {
|
||||
case Allocate = "Failed to allocate memory."
|
||||
case AuthFailed = "Authorization/Authentication failed."
|
||||
case Decode = "Unable to decode the provided data."
|
||||
case Duplicate = "The item already exists."
|
||||
case InteractionNotAllowed = "Interaction with the Security Server is not allowed."
|
||||
case NoError = "No error."
|
||||
case NotAvailable = "No trust results are available."
|
||||
case NotFound = "The item cannot be found."
|
||||
case Param = "One or more parameters passed to the function were not valid."
|
||||
case RequestNotSet = "The request was not set"
|
||||
case TypeNotFound = "The type was not found"
|
||||
case UnableToClear = "Unable to clear the keychain"
|
||||
case Undefined = "An undefined error occurred"
|
||||
case Unimplemented = "Function or operation not implemented."
|
||||
|
||||
func testSaveData_Multiple() {
|
||||
var errors: [NSError?] = []
|
||||
for i in 0...10 {
|
||||
errors.append(Locksmith.saveData(["key": "value \(i)"], inService: "myService", forUserAccount: "myAccount\(i)"))
|
||||
}
|
||||
XCTAssert(errors.filter({ $0 != nil }).isEmpty, "❌: saving multiple items")
|
||||
}
|
||||
|
||||
func testSaveData_Duplicate() {
|
||||
// Should be successful
|
||||
let error1 = Locksmith.saveData(["key": "value"], inService: "myService", forUserAccount: "user")
|
||||
|
||||
// Should fail
|
||||
let error2 = Locksmith.saveData(["key": "value"], inService: "myService", forUserAccount: "user")
|
||||
|
||||
XCTAssert(error1 == nil && error2 != nil, "❌: saving duplicate data")
|
||||
}
|
||||
|
||||
// Setup the keychain for requests that use pre-existing values on the keychain (update, read, delete)
|
||||
func setupLoads() {
|
||||
Locksmith.saveData(["key": "value"], inService: "myService", forUserAccount: "user1")
|
||||
Locksmith.saveData(["anotherkey": "anothervalue"], inService: "myService", forUserAccount: "user2")
|
||||
Locksmith.saveData(["word": "definition"], inService: "myService", forUserAccount: "user3")
|
||||
}
|
||||
|
||||
// public class func loadDataInService(service: String, forUserAccount userAccount: String) -> (NSDictionary?, NSError?)
|
||||
func testLoadData_Once() {
|
||||
setupLoads()
|
||||
|
||||
let (dictionary, error) = Locksmith.loadDataInService("myService", forUserAccount: "user1")
|
||||
XCTAssert(dictionary!.valueForKey("key")! as NSString == "value" && error == nil, "❌: loading one item")
|
||||
}
|
||||
|
||||
func testLoadData_Multiple() {
|
||||
setupLoads()
|
||||
|
||||
let (dictionary, error) = Locksmith.loadDataInService("myService", forUserAccount: "user1")
|
||||
let (dictionary2, error2) = Locksmith.loadDataInService("myService", forUserAccount: "user2")
|
||||
let (dictionary3, error3) = Locksmith.loadDataInService("myService", forUserAccount: "user3")
|
||||
|
||||
XCTAssert(dictionary!.valueForKey("key")! as NSString == "value" && error == nil, "❌: loading multiple items")
|
||||
XCTAssert(dictionary2!.valueForKey("anotherkey")! as NSString == "anothervalue" && error == nil, "❌: loading multiple items")
|
||||
XCTAssert(dictionary3!.valueForKey("word")! as NSString == "definition" && error == nil, "❌: loading multiple items")
|
||||
}
|
||||
|
||||
// public class func updateData(data: Dictionary<String, String>, inService service: String, forUserAccount userAccount: String) -> NSError?
|
||||
func testUpdateData() {
|
||||
setupLoads()
|
||||
|
||||
let error = Locksmith.updateData(["key": "newvalue"], inService: "myService", forUserAccount: "user1")
|
||||
let (dictionary, err) = Locksmith.loadDataInService("myService", forUserAccount: "user1")
|
||||
XCTAssert(dictionary!.valueForKey("key")! as NSString == "newvalue" && error == nil, "❌: updating item")
|
||||
|
||||
// Updating an item that doesn't exist should create that item (i.e. performs a regular create request)
|
||||
let error2 = Locksmith.updateData(["key": "anothervalue"], inService: "myService", forUserAccount: "user1")
|
||||
XCTAssert(error2 == nil, "❌: updating item that doesn't exist")
|
||||
}
|
||||
|
||||
// public class func deleteDataInService(service: String, forUserAccount userAccount: String) -> NSError?
|
||||
func testDeleteData() {
|
||||
setupLoads()
|
||||
|
||||
let error = Locksmith.deleteDataInService("myService", forUserAccount: "user1")
|
||||
XCTAssert(error == nil, "❌: deleting existing item")
|
||||
|
||||
let error2 = Locksmith.deleteDataInService("myService", forUserAccount: "user1")
|
||||
XCTAssert(error2 != nil, "❌: deleting non existent item")
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measureBlock() {
|
||||
// Put the code you want to measure the time of here.
|
||||
init?(fromStatusCode code: Int) {
|
||||
switch code {
|
||||
case Int(errSecAllocate):
|
||||
self = Allocate
|
||||
case Int(errSecAuthFailed):
|
||||
self = AuthFailed
|
||||
case Int(errSecDecode):
|
||||
self = Decode
|
||||
case Int(errSecDuplicateItem):
|
||||
self = Duplicate
|
||||
case Int(errSecInteractionNotAllowed):
|
||||
self = InteractionNotAllowed
|
||||
case Int(errSecItemNotFound):
|
||||
self = NotFound
|
||||
case Int(errSecNotAvailable):
|
||||
self = NotAvailable
|
||||
case Int(errSecParam):
|
||||
self = Param
|
||||
case Int(errSecUnimplemented):
|
||||
self = Unimplemented
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Locksmith
|
||||
public class Locksmith: NSObject {
|
||||
// MARK: Perform request
|
||||
public class func performRequest(request: LocksmithRequest) throws -> NSDictionary {
|
||||
let type = request.type
|
||||
var result: AnyObject?
|
||||
var status: OSStatus?
|
||||
|
||||
let parsedRequest: NSMutableDictionary = parseRequest(request)
|
||||
|
||||
let requestReference = parsedRequest as CFDictionaryRef
|
||||
|
||||
switch type {
|
||||
case .Create:
|
||||
status = withUnsafeMutablePointer(&result) { SecItemAdd(requestReference, UnsafeMutablePointer($0)) }
|
||||
case .Read:
|
||||
status = withUnsafeMutablePointer(&result) { SecItemCopyMatching(requestReference, UnsafeMutablePointer($0)) }
|
||||
case .Delete:
|
||||
status = SecItemDelete(requestReference)
|
||||
case .Update:
|
||||
status = Locksmith.performUpdate(requestReference, result: &result)
|
||||
}
|
||||
|
||||
guard let unwrappedStatus = status else {
|
||||
throw LocksmithError.TypeNotFound
|
||||
}
|
||||
|
||||
let statusCode = Int(unwrappedStatus)
|
||||
if let error = LocksmithError(fromStatusCode: statusCode) {
|
||||
throw error
|
||||
}
|
||||
|
||||
var resultsDictionary: NSDictionary?
|
||||
|
||||
if result != nil && type == .Read && status == errSecSuccess {
|
||||
if let data = result as? NSData {
|
||||
// Convert the retrieved data to a dictionary
|
||||
resultsDictionary = NSKeyedUnarchiver.unarchiveObjectWithData(data) as? NSDictionary
|
||||
}
|
||||
}
|
||||
|
||||
return resultsDictionary ?? NSDictionary()
|
||||
}
|
||||
|
||||
// MARK: Private methods
|
||||
private class func performUpdate(request: CFDictionaryRef, inout result: AnyObject?) -> OSStatus {
|
||||
// We perform updates to the keychain by first deleting the matching object, then writing to it with the new value.
|
||||
SecItemDelete(request)
|
||||
|
||||
// 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.
|
||||
let status: OSStatus = withUnsafeMutablePointer(&result) { SecItemAdd(request, UnsafeMutablePointer($0)) }
|
||||
return status
|
||||
}
|
||||
|
||||
private class func parseRequest(request: LocksmithRequest) -> NSMutableDictionary {
|
||||
var parsedRequest = NSMutableDictionary()
|
||||
|
||||
var options = [String: AnyObject?]()
|
||||
options[String(kSecAttrAccount)] = request.userAccount
|
||||
options[String(kSecAttrAccessGroup)] = request.group
|
||||
options[String(kSecAttrService)] = request.service
|
||||
options[String(kSecAttrSynchronizable)] = request.synchronizable
|
||||
options[String(kSecClass)] = request.securityClass.rawValue
|
||||
|
||||
if let accessibleMode = request.accessible {
|
||||
options[String(kSecAttrAccessible)] = accessibleMode.rawValue
|
||||
}
|
||||
|
||||
for (key, option) in options {
|
||||
parsedRequest.setOptional(option, forKey: key)
|
||||
}
|
||||
|
||||
switch request.type {
|
||||
case .Create:
|
||||
parsedRequest = parseCreateRequest(request, inDictionary: parsedRequest)
|
||||
case .Delete:
|
||||
parsedRequest = parseDeleteRequest(request, inDictionary: parsedRequest)
|
||||
case .Update:
|
||||
parsedRequest = parseCreateRequest(request, inDictionary: parsedRequest)
|
||||
default: // case .Read:
|
||||
parsedRequest = parseReadRequest(request, inDictionary: parsedRequest)
|
||||
}
|
||||
|
||||
return parsedRequest
|
||||
}
|
||||
|
||||
private class func parseCreateRequest(request: LocksmithRequest, inDictionary dictionary: NSMutableDictionary) -> NSMutableDictionary {
|
||||
|
||||
if let data = request.data {
|
||||
let encodedData = NSKeyedArchiver.archivedDataWithRootObject(data)
|
||||
dictionary.setObject(encodedData, forKey: String(kSecValueData))
|
||||
}
|
||||
|
||||
return dictionary
|
||||
}
|
||||
|
||||
|
||||
private class func parseReadRequest(request: LocksmithRequest, inDictionary dictionary: NSMutableDictionary) -> NSMutableDictionary {
|
||||
dictionary.setOptional(kCFBooleanTrue, forKey: String(kSecReturnData))
|
||||
|
||||
switch request.matchLimit {
|
||||
case .One:
|
||||
dictionary.setObject(kSecMatchLimitOne, forKey: String(kSecMatchLimit))
|
||||
case .Many:
|
||||
dictionary.setObject(kSecMatchLimitAll, forKey: String(kSecMatchLimit))
|
||||
}
|
||||
|
||||
return dictionary
|
||||
}
|
||||
|
||||
private class func parseDeleteRequest(request: LocksmithRequest, inDictionary dictionary: NSMutableDictionary) -> NSMutableDictionary {
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Convenient Class Methods
|
||||
extension Locksmith {
|
||||
public class func saveData(data: Dictionary<String, String>, forUserAccount userAccount: String, inService service: String = LocksmithDefaultService) throws {
|
||||
let saveRequest = LocksmithRequest(userAccount: userAccount, requestType: .Create, data: data, service: service)
|
||||
try Locksmith.performRequest(saveRequest)
|
||||
}
|
||||
|
||||
public class func loadDataForUserAccount(userAccount: String, inService service: String = LocksmithDefaultService) -> NSDictionary? {
|
||||
let readRequest = LocksmithRequest(userAccount: userAccount, service: service)
|
||||
|
||||
do {
|
||||
let dictionary = try Locksmith.performRequest(readRequest)
|
||||
return dictionary
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public class func deleteDataForUserAccount(userAccount: String, inService service: String = LocksmithDefaultService) throws {
|
||||
let deleteRequest = LocksmithRequest(userAccount: userAccount, requestType: .Delete, service: service)
|
||||
try Locksmith.performRequest(deleteRequest)
|
||||
}
|
||||
|
||||
public class func updateData(data: Dictionary<String, String>, forUserAccount userAccount: String, inService service: String = LocksmithDefaultService) throws {
|
||||
let updateRequest = LocksmithRequest(userAccount: userAccount, requestType: .Update, data: data, service: service)
|
||||
try Locksmith.performRequest(updateRequest)
|
||||
}
|
||||
|
||||
public class func clearKeychain() throws {
|
||||
// Delete all of the keychain data of the given class
|
||||
func deleteDataForSecClass(secClass: CFTypeRef) throws {
|
||||
let request = NSMutableDictionary()
|
||||
request.setObject(secClass, forKey: String(kSecClass))
|
||||
|
||||
let status: OSStatus? = SecItemDelete(request as CFDictionaryRef)
|
||||
|
||||
if let status = status {
|
||||
let statusCode = Int(status)
|
||||
if let error = LocksmithError(fromStatusCode: statusCode) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For each of the sec class types, delete all of the saved items of that type
|
||||
let classes = [kSecClassGenericPassword, kSecClassInternetPassword, kSecClassCertificate, kSecClassKey, kSecClassIdentity]
|
||||
|
||||
for classType in classes {
|
||||
do {
|
||||
try deleteDataForSecClass(classType)
|
||||
} catch let error as LocksmithError {
|
||||
// There was an error
|
||||
// If the error indicates that there was no item with that security class, that's fine.
|
||||
// Some of the sec classes will have nothing in them in most cases.
|
||||
if error != LocksmithError.NotFound {
|
||||
throw LocksmithError.UnableToClear
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Dictionary Extension
|
||||
extension NSMutableDictionary {
|
||||
func setOptional(optional: AnyObject?, forKey key: NSCopying) {
|
||||
if let object: AnyObject = optional {
|
||||
self.setObject(object, forKey: key)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+111
-174
@@ -5,120 +5,108 @@
|
||||
// Copyright (c) 2014 Colour Coding. All rights reserved.
|
||||
//
|
||||
|
||||
import CoreFoundation
|
||||
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![String(kCFBundleIdentifierKey)] as? String ?? "com.locksmith.defaultService"
|
||||
|
||||
// MARK: Locksmith Error
|
||||
public enum LocksmithError: String, ErrorType {
|
||||
case Allocate = "Failed to allocate memory."
|
||||
case AuthFailed = "Authorization/Authentication failed."
|
||||
case Decode = "Unable to decode the provided data."
|
||||
case Duplicate = "The item already exists."
|
||||
case InteractionNotAllowed = "Interaction with the Security Server is not allowed."
|
||||
case NoError = "No error."
|
||||
case NotAvailable = "No trust results are available."
|
||||
case NotFound = "The item cannot be found."
|
||||
case Param = "One or more parameters passed to the function were not valid."
|
||||
case RequestNotSet = "The request was not set"
|
||||
case TypeNotFound = "The type was not found"
|
||||
case UnableToClear = "Unable to clear the keychain"
|
||||
case Undefined = "An undefined error occurred"
|
||||
case Unimplemented = "Function or operation not implemented."
|
||||
|
||||
init?(fromStatusCode code: Int) {
|
||||
switch code {
|
||||
case Int(errSecAllocate):
|
||||
self = Allocate
|
||||
case Int(errSecAuthFailed):
|
||||
self = AuthFailed
|
||||
case Int(errSecDecode):
|
||||
self = Decode
|
||||
case Int(errSecDuplicateItem):
|
||||
self = Duplicate
|
||||
case Int(errSecInteractionNotAllowed):
|
||||
self = InteractionNotAllowed
|
||||
case Int(errSecItemNotFound):
|
||||
self = NotFound
|
||||
case Int(errSecNotAvailable):
|
||||
self = NotAvailable
|
||||
case Int(errSecParam):
|
||||
self = Param
|
||||
case Int(errSecUnimplemented):
|
||||
self = Unimplemented
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Locksmith
|
||||
public class Locksmith: NSObject {
|
||||
// MARK: Perform request
|
||||
class func performRequest(request: LocksmithRequest) -> (NSDictionary?, NSError?) {
|
||||
public class func performRequest(request: LocksmithRequest) throws -> NSDictionary? {
|
||||
let type = request.type
|
||||
//var result: Unmanaged<AnyObject>? = nil
|
||||
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:
|
||||
status = withUnsafeMutablePointer(&result) { SecItemAdd(requestReference, UnsafeMutablePointer($0)) }
|
||||
status = SecItemAdd(requestReference, &result)
|
||||
case .Read:
|
||||
status = withUnsafeMutablePointer(&result) { SecItemCopyMatching(requestReference, UnsafeMutablePointer($0)) }
|
||||
status = SecItemCopyMatching(requestReference, &result)
|
||||
case .Delete:
|
||||
status = SecItemDelete(requestReference)
|
||||
case .Update:
|
||||
status = Locksmith.performUpdate(requestReference, result: &result)
|
||||
default:
|
||||
status = nil
|
||||
}
|
||||
|
||||
if let status = status {
|
||||
var statusCode = Int(status)
|
||||
let error = Locksmith.keychainError(forCode: statusCode)
|
||||
var resultsDictionary: NSDictionary?
|
||||
|
||||
if result != nil {
|
||||
if type == .Read && status == errSecSuccess {
|
||||
|
||||
if let data = result as? NSData {
|
||||
// Convert the retrieved data to a dictionary
|
||||
resultsDictionary = NSKeyedUnarchiver.unarchiveObjectWithData(data) as? NSDictionary
|
||||
}
|
||||
}
|
||||
guard let unwrappedStatus = status else {
|
||||
throw LocksmithError.TypeNotFound
|
||||
}
|
||||
|
||||
let statusCode = Int(unwrappedStatus)
|
||||
if let error = LocksmithError(fromStatusCode: statusCode) {
|
||||
throw error
|
||||
}
|
||||
|
||||
var resultsDictionary: NSDictionary?
|
||||
|
||||
if result != nil && type == .Read && status == errSecSuccess {
|
||||
if let data = result as? NSData {
|
||||
// Convert the retrieved data to a dictionary
|
||||
resultsDictionary = NSKeyedUnarchiver.unarchiveObjectWithData(data) as? NSDictionary
|
||||
}
|
||||
|
||||
return (resultsDictionary, error)
|
||||
} else {
|
||||
let code = LocksmithErrorCode.TypeNotFound.rawValue
|
||||
let message = internalErrorMessage(forCode: code)
|
||||
return (nil, NSError(domain: LocksmithErrorDomain, code: code, userInfo: ["message": message]))
|
||||
}
|
||||
}
|
||||
|
||||
private class func performUpdate(request: CFDictionaryRef, inout result: AnyObject?) -> OSStatus {
|
||||
// We perform updates to the keychain by first deleting the matching object, then writing to it with the new value.
|
||||
SecItemDelete(request)
|
||||
// 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)) }
|
||||
return status
|
||||
}
|
||||
|
||||
// MARK: Error Lookup
|
||||
enum ErrorMessage: String {
|
||||
case Allocate = "Failed to allocate memory."
|
||||
case AuthFailed = "Authorization/Authentication failed."
|
||||
case Decode = "Unable to decode the provided data."
|
||||
case Duplicate = "The item already exists."
|
||||
case InteractionNotAllowed = "Interaction with the Security Server is not allowed."
|
||||
case NoError = "No error."
|
||||
case NotAvailable = "No trust results are available."
|
||||
case NotFound = "The item cannot be found."
|
||||
case Param = "One or more parameters passed to the function were not valid."
|
||||
case Unimplemented = "Function or operation not implemented."
|
||||
}
|
||||
|
||||
enum LocksmithErrorCode: Int {
|
||||
case RequestNotSet = 1
|
||||
case TypeNotFound = 2
|
||||
case UnableToClear = 3
|
||||
}
|
||||
|
||||
enum LocksmithErrorMessage: String {
|
||||
case RequestNotSet = "keychainRequest was not set."
|
||||
case TypeNotFound = "The type of request given was undefined."
|
||||
case UnableToClear = "Unable to clear the keychain"
|
||||
}
|
||||
|
||||
class func keychainError(forCode statusCode: Int) -> NSError? {
|
||||
var error: NSError?
|
||||
|
||||
if statusCode != Int(errSecSuccess) {
|
||||
let message = errorMessage(statusCode)
|
||||
// println("Keychain request failed. Code: \(statusCode). Message: \(message)")
|
||||
error = NSError(domain: LocksmithErrorDomain, code: statusCode, userInfo: ["message": message])
|
||||
}
|
||||
|
||||
return error
|
||||
return resultsDictionary
|
||||
}
|
||||
|
||||
// MARK: Private methods
|
||||
|
||||
private class func internalErrorMessage(forCode statusCode: Int) -> NSString {
|
||||
switch statusCode {
|
||||
case LocksmithErrorCode.RequestNotSet.rawValue:
|
||||
return LocksmithErrorMessage.RequestNotSet.rawValue
|
||||
case LocksmithErrorCode.UnableToClear.rawValue:
|
||||
return LocksmithErrorMessage.UnableToClear.rawValue
|
||||
default:
|
||||
return "Error message for code \(statusCode) not set"
|
||||
}
|
||||
private class func performUpdate(request: CFDictionaryRef, inout result: AnyObject?) -> OSStatus {
|
||||
// We perform updates to the keychain by first deleting the matching object, then writing to it with the new value.
|
||||
SecItemDelete(request)
|
||||
|
||||
// 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.
|
||||
let status: OSStatus = withUnsafeMutablePointer(&result) { SecItemAdd(request, UnsafeMutablePointer($0)) }
|
||||
return status
|
||||
}
|
||||
|
||||
private class func parseRequest(request: LocksmithRequest) -> NSMutableDictionary {
|
||||
@@ -129,7 +117,11 @@ public class Locksmith: NSObject {
|
||||
options[String(kSecAttrAccessGroup)] = request.group
|
||||
options[String(kSecAttrService)] = request.service
|
||||
options[String(kSecAttrSynchronizable)] = request.synchronizable
|
||||
options[String(kSecClass)] = securityCode(request.securityClass)
|
||||
options[String(kSecClass)] = request.securityClass.rawValue
|
||||
|
||||
if let accessibleMode = request.accessible {
|
||||
options[String(kSecAttrAccessible)] = accessibleMode.rawValue
|
||||
}
|
||||
|
||||
for (key, option) in options {
|
||||
parsedRequest.setOptional(option, forKey: key)
|
||||
@@ -176,130 +168,75 @@ public class Locksmith: NSObject {
|
||||
private class func parseDeleteRequest(request: LocksmithRequest, inDictionary dictionary: NSMutableDictionary) -> NSMutableDictionary {
|
||||
return dictionary
|
||||
}
|
||||
|
||||
private class func errorMessage(code: Int) -> NSString {
|
||||
switch code {
|
||||
case Int(errSecAllocate):
|
||||
return ErrorMessage.Allocate.rawValue
|
||||
case Int(errSecAuthFailed):
|
||||
return ErrorMessage.AuthFailed.rawValue
|
||||
case Int(errSecDecode):
|
||||
return ErrorMessage.Decode.rawValue
|
||||
case Int(errSecDuplicateItem):
|
||||
return ErrorMessage.Duplicate.rawValue
|
||||
case Int(errSecInteractionNotAllowed):
|
||||
return ErrorMessage.InteractionNotAllowed.rawValue
|
||||
case Int(errSecItemNotFound):
|
||||
return ErrorMessage.NotFound.rawValue
|
||||
case Int(errSecNotAvailable):
|
||||
return ErrorMessage.NotAvailable.rawValue
|
||||
case Int(errSecParam):
|
||||
return ErrorMessage.Param.rawValue
|
||||
case Int(errSecSuccess):
|
||||
return ErrorMessage.NoError.rawValue
|
||||
case Int(errSecUnimplemented):
|
||||
return ErrorMessage.Unimplemented.rawValue
|
||||
default:
|
||||
return "Undocumented error with code \(code)."
|
||||
}
|
||||
}
|
||||
|
||||
private class func securityCode(securityClass: SecurityClass) -> CFStringRef {
|
||||
switch securityClass {
|
||||
case .GenericPassword:
|
||||
return kSecClassGenericPassword
|
||||
case .Certificate:
|
||||
return kSecClassCertificate
|
||||
case .Identity:
|
||||
return kSecClassIdentity
|
||||
case .InternetPassword:
|
||||
return kSecClassInternetPassword
|
||||
case .Key:
|
||||
return kSecClassKey
|
||||
default:
|
||||
return kSecClassGenericPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Convenient Class Methods
|
||||
extension Locksmith {
|
||||
public class func saveData(data: Dictionary<String, String>, forUserAccount userAccount: String, inService service: String = LocksmithDefaultService) -> NSError? {
|
||||
public class func saveData(data: Dictionary<String, String>, forUserAccount userAccount: String, inService service: String = LocksmithDefaultService) throws {
|
||||
let saveRequest = LocksmithRequest(userAccount: userAccount, requestType: .Create, data: data, service: service)
|
||||
let (dictionary, error) = Locksmith.performRequest(saveRequest)
|
||||
return error
|
||||
try Locksmith.performRequest(saveRequest)
|
||||
}
|
||||
|
||||
public class func loadDataForUserAccount(userAccount: String, inService service: String = LocksmithDefaultService) -> (NSDictionary?, NSError?) {
|
||||
public class func loadDataForUserAccount(userAccount: String, inService service: String = LocksmithDefaultService) -> NSDictionary? {
|
||||
let readRequest = LocksmithRequest(userAccount: userAccount, service: service)
|
||||
return Locksmith.performRequest(readRequest)
|
||||
|
||||
do {
|
||||
let dictionary = try Locksmith.performRequest(readRequest)
|
||||
return dictionary
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public class func deleteDataForUserAccount(userAccount: String, inService service: String = LocksmithDefaultService) -> NSError? {
|
||||
public class func deleteDataForUserAccount(userAccount: String, inService service: String = LocksmithDefaultService) throws {
|
||||
let deleteRequest = LocksmithRequest(userAccount: userAccount, requestType: .Delete, service: service)
|
||||
let (dictionary, error) = Locksmith.performRequest(deleteRequest)
|
||||
return error
|
||||
try Locksmith.performRequest(deleteRequest)
|
||||
}
|
||||
|
||||
public class func updateData(data: Dictionary<String, String>, forUserAccount userAccount: String, inService service: String = LocksmithDefaultService) -> NSError? {
|
||||
public class func updateData(data: Dictionary<String, String>, forUserAccount userAccount: String, inService service: String = LocksmithDefaultService) throws {
|
||||
let updateRequest = LocksmithRequest(userAccount: userAccount, requestType: .Update, data: data, service: service)
|
||||
let (dictionary, error) = Locksmith.performRequest(updateRequest)
|
||||
return error
|
||||
try Locksmith.performRequest(updateRequest)
|
||||
}
|
||||
|
||||
public class func clearKeychain() -> NSError? {
|
||||
public class func clearKeychain() throws {
|
||||
// Delete all of the keychain data of the given class
|
||||
func deleteDataForSecClass(secClass: CFTypeRef) -> NSError? {
|
||||
var request = NSMutableDictionary()
|
||||
func deleteDataForSecClass(secClass: CFTypeRef) throws {
|
||||
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)
|
||||
return Locksmith.keychainError(forCode: statusCode)
|
||||
let statusCode = Int(status)
|
||||
if let error = LocksmithError(fromStatusCode: statusCode) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// For each of the sec class types, delete all of the saved items of that type
|
||||
let classes = [kSecClassGenericPassword, kSecClassInternetPassword, kSecClassCertificate, kSecClassKey, kSecClassIdentity]
|
||||
|
||||
let errors: [NSError?] = classes.map({
|
||||
return deleteDataForSecClass($0)
|
||||
})
|
||||
|
||||
// Remove those that were successful, or failed with an acceptable error code
|
||||
let filtered = errors.filter({
|
||||
if let error = $0 {
|
||||
for classType in classes {
|
||||
do {
|
||||
try deleteDataForSecClass(classType)
|
||||
} catch let error as LocksmithError {
|
||||
// There was an error
|
||||
// If the error indicates that there was no item with that sec class, that's fine.
|
||||
// If the error indicates that there was no item with that security class, that's fine.
|
||||
// Some of the sec classes will have nothing in them in most cases.
|
||||
return error.code != Int(errSecItemNotFound) ? true : false
|
||||
if error != LocksmithError.NotFound {
|
||||
throw LocksmithError.UnableToClear
|
||||
}
|
||||
}
|
||||
|
||||
// There was no error
|
||||
return false
|
||||
})
|
||||
|
||||
// If the filtered array is empty, then everything went OK
|
||||
if filtered.isEmpty {
|
||||
return nil
|
||||
}
|
||||
|
||||
// At least one of the delete operations failed
|
||||
let code = LocksmithErrorCode.UnableToClear.rawValue
|
||||
let message = internalErrorMessage(forCode: code)
|
||||
return NSError(domain: LocksmithErrorDomain, code: code, userInfo: ["message": message])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Dictionary Extensions
|
||||
// MARK: Dictionary Extension
|
||||
extension NSMutableDictionary {
|
||||
func setOptional(optional: AnyObject?, forKey key: NSCopying) {
|
||||
if let object: AnyObject = optional {
|
||||
self.setObject(object, forKey: key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,35 +8,134 @@
|
||||
import UIKit
|
||||
import Security
|
||||
|
||||
public enum SecurityClass: Int {
|
||||
// With thanks to http://iosdeveloperzone.com/2014/10/22/taming-foundation-constants-into-swift-enums/
|
||||
|
||||
// MARK: Security Class
|
||||
public enum SecurityClass: RawRepresentable {
|
||||
case GenericPassword, InternetPassword, Certificate, Key, Identity
|
||||
|
||||
public init?(rawValue: String) {
|
||||
switch rawValue {
|
||||
case String(kSecClassGenericPassword):
|
||||
self = GenericPassword
|
||||
case String(kSecClassInternetPassword):
|
||||
self = InternetPassword
|
||||
case String(kSecClassCertificate):
|
||||
self = Certificate
|
||||
case String(kSecClassKey):
|
||||
self = Key
|
||||
case String(kSecClassIdentity):
|
||||
self = Identity
|
||||
default:
|
||||
print("SecurityClass: Invalid raw value provided. Defaulting to .GenericPassword")
|
||||
self = GenericPassword
|
||||
}
|
||||
}
|
||||
|
||||
public var rawValue: String {
|
||||
switch self {
|
||||
case .GenericPassword:
|
||||
return String(kSecClassGenericPassword)
|
||||
case .InternetPassword:
|
||||
return String(kSecClassInternetPassword)
|
||||
case .Certificate:
|
||||
return String(kSecClassCertificate)
|
||||
case .Key:
|
||||
return String(kSecClassKey)
|
||||
case .Identity:
|
||||
return String(kSecClassIdentity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum MatchLimit: Int {
|
||||
// MARK: Accessible
|
||||
public enum Accessible: RawRepresentable {
|
||||
case WhenUnlocked, AfterFirstUnlock, Always, WhenUnlockedThisDeviceOnly, AfterFirstUnlockThisDeviceOnly, AlwaysThisDeviceOnly
|
||||
@available (iOS 8,*)
|
||||
case WhenPasscodeSetThisDeviceOnly
|
||||
|
||||
public init?(rawValue: String) {
|
||||
switch rawValue {
|
||||
case String(kSecAttrAccessibleWhenUnlocked):
|
||||
self = WhenUnlocked
|
||||
case String(kSecAttrAccessibleAfterFirstUnlock):
|
||||
self = AfterFirstUnlock
|
||||
case String(kSecAttrAccessibleAlways):
|
||||
self = Always
|
||||
case String(kSecAttrAccessibleWhenUnlockedThisDeviceOnly):
|
||||
self = WhenUnlockedThisDeviceOnly
|
||||
case String(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly):
|
||||
self = AfterFirstUnlockThisDeviceOnly
|
||||
case String(kSecAttrAccessibleAlwaysThisDeviceOnly):
|
||||
self = AlwaysThisDeviceOnly
|
||||
default:
|
||||
if #available(iOS 8,*) {
|
||||
if rawValue == String(kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly) {
|
||||
self = WhenPasscodeSetThisDeviceOnly
|
||||
} else {
|
||||
print("Accessible: invalid rawValue provided. Defaulting to Accessible.WhenUnlocked.")
|
||||
self = WhenUnlocked
|
||||
}
|
||||
} else {
|
||||
print("Accessible: invalid rawValue provided. Defaulting to Accessible.WhenUnlocked.")
|
||||
self = WhenUnlocked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var rawValue: String {
|
||||
switch self {
|
||||
case .WhenUnlocked:
|
||||
return String(kSecAttrAccessibleWhenUnlocked)
|
||||
case .AfterFirstUnlock:
|
||||
return String(kSecAttrAccessibleAfterFirstUnlock)
|
||||
case .Always:
|
||||
return String(kSecAttrAccessibleAlways)
|
||||
case .WhenPasscodeSetThisDeviceOnly:
|
||||
if #available(iOS 8.0, *) {
|
||||
return String(kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly)
|
||||
} else {
|
||||
fatalError("Accessible.WhenPasscodeSetThisDeviceOnly has no raw representation in iOS 7.")
|
||||
}
|
||||
case .WhenUnlockedThisDeviceOnly:
|
||||
return String(kSecAttrAccessibleWhenUnlockedThisDeviceOnly)
|
||||
case .AfterFirstUnlockThisDeviceOnly:
|
||||
return String(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly)
|
||||
case .AlwaysThisDeviceOnly:
|
||||
return String(kSecAttrAccessibleAlwaysThisDeviceOnly)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Match Limit
|
||||
public enum MatchLimit {
|
||||
case One, Many
|
||||
}
|
||||
|
||||
public enum RequestType: Int {
|
||||
// MARK: Request Type
|
||||
public enum RequestType {
|
||||
case Create, Read, Update, Delete
|
||||
}
|
||||
|
||||
public class LocksmithRequest: NSObject, DebugPrintable {
|
||||
// MARK: Locksmith Request
|
||||
public class LocksmithRequest: NSObject, CustomDebugStringConvertible {
|
||||
// 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 = LocksmithDefaultService
|
||||
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 {
|
||||
return "service: \(self.service), type: \(self.type.rawValue), userAccount: \(self.userAccount)"
|
||||
return "service: \(self.service), type: \(self.type), userAccount: \(self.userAccount)"
|
||||
}
|
||||
|
||||
required public init(userAccount: String, service: String = LocksmithDefaultService) {
|
||||
@@ -44,13 +143,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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.matthewpalmer.${PRODUCT_NAME:rfc1034identifier}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.1.2</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -2,19 +2,22 @@
|
||||
|
||||
A sane way to work with the iOS Keychain in Swift.
|
||||
|
||||
[](https://travis-ci.org/matthewpalmer/Locksmith)
|
||||
<!--[](https://travis-ci.org/matthewpalmer/Locksmith)-->
|
||||
[](http://cocoadocs.org/docsets/Locksmith)
|
||||
[](https://github.com/Carthage/Carthage)
|
||||
[](http://cocoadocs.org/docsets/Locksmith)
|
||||
[](http://cocoadocs.org/docsets/Locksmith)
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
### CocoaPods
|
||||
|
||||
Locksmith is available through [CocoaPods](http://cocoapods.org). To install
|
||||
it, simply add the following line to your Podfile:
|
||||
Locksmith for Swift 2, simply add the following line to your Podfile:
|
||||
|
||||
pod 'Locksmith', :git => 'https://github.com/matthewpalmer/Locksmith.git', :branch => '2.0'
|
||||
|
||||
pod "Locksmith"
|
||||
|
||||
### Manual
|
||||
|
||||
@@ -27,48 +30,25 @@ In the following examples, you can choose not to provide a value for the `inServ
|
||||
**Save data**
|
||||
|
||||
```swift
|
||||
let error = Locksmith.saveData(["some key": "some value"], forUserAccount: "myUserAccount")
|
||||
```
|
||||
|
||||
**Save data, specifying a service**
|
||||
|
||||
```swift
|
||||
let error = Locksmith.saveData(["some key": "some value"], forUserAccount: "myUserAccount", inService: "myService")
|
||||
try Locksmith.saveData(["some key": "some value"], forUserAccount: "myUserAccount", inService: "myService")
|
||||
```
|
||||
|
||||
**Load data**
|
||||
|
||||
```swift
|
||||
let (dictionary, error) = Locksmith.loadDataForUserAccount("myUserAccount")
|
||||
```
|
||||
|
||||
**Load data, specifying a service**
|
||||
|
||||
```swift
|
||||
let (dictionary, error) = Locksmith.loadDataForUserAccount("myUserAccount", inService: "myService")
|
||||
let dictionary = Locksmith.loadDataForUserAccount("myUserAccount", inService: "myService")
|
||||
```
|
||||
|
||||
**Update data**
|
||||
|
||||
```swift
|
||||
let error = Locksmith.updateData(["some key": "another value"], forUserAccount: "myUserAccount")
|
||||
```
|
||||
|
||||
**Update data, specifying a service**
|
||||
|
||||
```swift
|
||||
let error = Locksmith.updateData(["some key": "another value"], forUserAccount: "myUserAccount", inService: "myService")
|
||||
try Locksmith.updateData(["some key": "another value"], forUserAccount: "myUserAccount", inService: "myService")
|
||||
```
|
||||
|
||||
**Delete data**
|
||||
```swift
|
||||
let error = Locksmith.deleteDataForUserAccount("myUserAccount")
|
||||
```
|
||||
|
||||
**Delete data, specifying a service**
|
||||
|
||||
```swift
|
||||
let error = Locksmith.deleteDataForUserAccount("myUserAccount", inService: "myService")
|
||||
try Locksmith.deleteDataForUserAccount("myUserAccount", inService: "myService")
|
||||
```
|
||||
|
||||
## Custom Requests
|
||||
@@ -80,19 +60,19 @@ To create custom keychain requests, you first have to instantiate a `LocksmithRe
|
||||
let saveRequest = LocksmithRequest(userAccount: userAccount, data: ["some key": "some value"], service: service)
|
||||
// Customize the request
|
||||
saveRequest.synchronizable = true
|
||||
Locksmith.performRequest(saveRequest)
|
||||
try Locksmith.performRequest(saveRequest)
|
||||
```
|
||||
|
||||
**Reading**
|
||||
```swift
|
||||
let readRequest = LocksmithRequest(userAccount: userAccount, service: service)
|
||||
let (dictionary, error) = Locksmith.performRequest(readRequest)
|
||||
let dictionary = try Locksmith.performRequest(readRequest)
|
||||
```
|
||||
|
||||
**Deleting**
|
||||
```swift
|
||||
let deleteRequest = LocksmithRequest(userAccount: userAccount, requestType: .Delete, service: service)
|
||||
Locksmith.performRequest(deleteRequest)
|
||||
try Locksmith.performRequest(deleteRequest)
|
||||
```
|
||||
|
||||
## LocksmithRequest
|
||||
@@ -116,10 +96,13 @@ var securityClass: SecurityClass // Defaults to .GenericPassword
|
||||
var synchronizable: Bool // Defaults to false
|
||||
```
|
||||
|
||||
## Testing
|
||||
I can't work out why, but opening `Example/Locksmith.xcworkspace` and trying to run the tests from there won't work. (Pull requests greatly appreciated on this!) Instead, you can run the tests by opening `Locksmith.xcodeproj` in the root directory, and doing Product -> Test.
|
||||
|
||||
## Author
|
||||
|
||||
[Matthew Palmer](http://matthewpalmer.net), matt@matthewpalmer.net
|
||||
|
||||
## 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.
|
||||
|
||||
Reference in New Issue
Block a user