Skip to content

Commit

Permalink
Update: Add different files for all Keychain classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jerilyngigigo committed Mar 9, 2020
1 parent 8615d28 commit bdfe239
Show file tree
Hide file tree
Showing 8 changed files with 581 additions and 435 deletions.
78 changes: 78 additions & 0 deletions GIGLibrary.xcodeproj/xcshareddata/xcschemes/GIGLibraryApp.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FA680F191B009B6B006FC484"
BuildableName = "GIGLibraryApp.app"
BlueprintName = "GIGLibraryApp"
ReferencedContainer = "container:GIGLibrary.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FA680F191B009B6B006FC484"
BuildableName = "GIGLibraryApp.app"
BlueprintName = "GIGLibraryApp"
ReferencedContainer = "container:GIGLibrary.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FA680F191B009B6B006FC484"
BuildableName = "GIGLibraryApp.app"
BlueprintName = "GIGLibraryApp"
ReferencedContainer = "container:GIGLibrary.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
20 changes: 20 additions & 0 deletions GiGLibrary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
8F8C8EFB20F4842500F5CE2C /* ReachabilityWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F8C8EFA20F4842500F5CE2C /* ReachabilityWrapper.swift */; };
96D003672411525F000F1873 /* KeychainStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D003662411525F000F1873 /* KeychainStore.swift */; };
96D0036924115DBE000F1873 /* Status.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D0036824115DBE000F1873 /* Status.swift */; };
96D00378241281B4000F1873 /* KeychainAccessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D00377241281B4000F1873 /* KeychainAccessibility.swift */; };
96D0037A2412834F000F1873 /* KeychainConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D003792412834F000F1873 /* KeychainConstants.swift */; };
96D0037C24128389000F1873 /* KeychainAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D0037B24128389000F1873 /* KeychainAttributes.swift */; };
96D0037E24128EB5000F1873 /* KeychainAuthenticationPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D0037D24128EB5000F1873 /* KeychainAuthenticationPolicy.swift */; };
96D0038024128F07000F1873 /* KeychainOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D0037F24128F07000F1873 /* KeychainOptions.swift */; };
A51F6D751D50BBB30052D95A /* StyledString.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51F6D741D50BBB30052D95A /* StyledString.swift */; };
A51F6D771D50C0410052D95A /* StyledStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51F6D761D50C0410052D95A /* StyledStringTests.swift */; };
A55EE0771DACFDFF002E4EDF /* ImageExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A55EE0761DACFDFF002E4EDF /* ImageExtension.swift */; };
Expand Down Expand Up @@ -427,6 +432,11 @@
8F8C8EFA20F4842500F5CE2C /* ReachabilityWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ReachabilityWrapper.swift; path = SwiftNetwork/ReachabilityWrapper.swift; sourceTree = "<group>"; };
96D003662411525F000F1873 /* KeychainStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainStore.swift; sourceTree = "<group>"; };
96D0036824115DBE000F1873 /* Status.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Status.swift; sourceTree = "<group>"; };
96D00377241281B4000F1873 /* KeychainAccessibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainAccessibility.swift; sourceTree = "<group>"; };
96D003792412834F000F1873 /* KeychainConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainConstants.swift; sourceTree = "<group>"; };
96D0037B24128389000F1873 /* KeychainAttributes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainAttributes.swift; sourceTree = "<group>"; };
96D0037D24128EB5000F1873 /* KeychainAuthenticationPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainAuthenticationPolicy.swift; sourceTree = "<group>"; };
96D0037F24128F07000F1873 /* KeychainOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainOptions.swift; sourceTree = "<group>"; };
A5057DA51D536857006E1F6A /* StyledString.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = StyledString.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
A51F6D741D50BBB30052D95A /* StyledString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyledString.swift; sourceTree = "<group>"; };
A51F6D761D50C0410052D95A /* StyledStringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyledStringTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -972,6 +982,11 @@
isa = PBXGroup;
children = (
96D003662411525F000F1873 /* KeychainStore.swift */,
96D003792412834F000F1873 /* KeychainConstants.swift */,
96D00377241281B4000F1873 /* KeychainAccessibility.swift */,
96D0037B24128389000F1873 /* KeychainAttributes.swift */,
96D0037D24128EB5000F1873 /* KeychainAuthenticationPolicy.swift */,
96D0037F24128F07000F1873 /* KeychainOptions.swift */,
96D0036824115DBE000F1873 /* Status.swift */,
);
path = KeychainStore;
Expand Down Expand Up @@ -2351,6 +2366,7 @@
D9FD35FC1B415CAE000D356F /* GIGNumericValidator.m in Sources */,
02F2F7F71E82C8760098E4AF /* ProgressPageControl.swift in Sources */,
D99AD2451B1DA3A3005BB4E5 /* GIGURLFile.m in Sources */,
96D0038024128F07000F1873 /* KeychainOptions.swift in Sources */,
D9FE61FD1BD65CC900E2B23C /* GIGFormController.m in Sources */,
644D9B6521AEB6C6002817A7 /* TextViewStyle.swift in Sources */,
D99AD2A71B1DA3A3005BB4E5 /* NSInvocation+GIGExtension.m in Sources */,
Expand All @@ -2368,6 +2384,7 @@
64D89EBD21ADA1AB0090F9D3 /* TextFieldStyle.swift in Sources */,
D99AD2EF1B1DA3A3005BB4E5 /* UIView+GIGBorderShadowExtension.m in Sources */,
D99AD2131B1DA3A3005BB4E5 /* GIGURLConfigAddDomainViewController.m in Sources */,
96D0037E24128EB5000F1873 /* KeychainAuthenticationPolicy.swift in Sources */,
FAAE2A4F1D227D5C00C5F808 /* Selfie.swift in Sources */,
A94D4A611CDDF67300CC4CAF /* GIGScannerViewController.swift in Sources */,
64D89EBE21ADA1AB0090F9D3 /* ViewStyle.swift in Sources */,
Expand Down Expand Up @@ -2395,6 +2412,7 @@
230A6AA020908FB700BC886D /* ScreenRecordVC.swift in Sources */,
0273BC7321393A2E005A1105 /* Reachability.swift in Sources */,
FAEDF67A1BE20EA400F05AE2 /* GIGStringValidator.m in Sources */,
96D0037C24128389000F1873 /* KeychainAttributes.swift in Sources */,
FAA3F8871C60EDD80061AADD /* Log.swift in Sources */,
D99AD2D71B1DA3A3005BB4E5 /* UIScrollView+GIGScrollTo.m in Sources */,
D99AD2F71B1DA3A3005BB4E5 /* UIView+GIGFrameExtension.m in Sources */,
Expand All @@ -2418,6 +2436,7 @@
8F8C8EFB20F4842500F5CE2C /* ReachabilityWrapper.swift in Sources */,
61F2ACEE1E9B9D53003E20C4 /* InfiniteCollectionVC.swift in Sources */,
D99AD2B11B1DA3A3005BB4E5 /* NSData+GIGJSON.m in Sources */,
96D0037A2412834F000F1873 /* KeychainConstants.swift in Sources */,
D9FD36221B416CCB000D356F /* GIGPhoneValidator.m in Sources */,
618616AC208DF099001B4603 /* HyperlinkTextView.swift in Sources */,
D9FE62201BD6878600E2B23C /* GIGMessageFormField.m in Sources */,
Expand Down Expand Up @@ -2456,6 +2475,7 @@
FA36E9701C637CD100214598 /* Dispatch.swift in Sources */,
64D89ECE21AE7ED50090F9D3 /* LabelStyle.swift in Sources */,
D99AD25D1B1DA3A3005BB4E5 /* GIGURLStorage.m in Sources */,
96D00378241281B4000F1873 /* KeychainAccessibility.swift in Sources */,
64D89EC121ADA1AB0090F9D3 /* UIView+Borders.swift in Sources */,
D99AD2CB1B1DA3A3005BB4E5 /* NSRegularExpression+GIGRegexp.m in Sources */,
96D0036924115DBE000F1873 /* Status.swift in Sources */,
Expand Down
121 changes: 121 additions & 0 deletions Source/KeychainStore/KeychainAccessibility.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// KeychainAccessibility.swift
// GIGLibrary
//
// Created by Jerilyn Gonçalves on 06/03/2020.
// Copyright © 2020 Gigigo SL. All rights reserved.
//

import Foundation

public enum KeychainAccessibility {
/**
Item data can only be accessed
while the device is unlocked. This is recommended for items that only
need be accesible while the application is in the foreground. Items
with this attribute will migrate to a new device when using encrypted
backups.
*/
case whenUnlocked

/**
Item data can only be
accessed once the device has been unlocked after a restart. This is
recommended for items that need to be accesible by background
applications. Items with this attribute will migrate to a new device
when using encrypted backups.
*/
case afterFirstUnlock

/**
Item data can always be accessed
regardless of the lock state of the device. This is not recommended
for anything except system use. Items with this attribute will migrate
to a new device when using encrypted backups.
*/
case always

/**
Item data can only
be accessed while the device is unlocked. This is recommended for items
that only need be accesible while the application is in the foreground.
Items with this attribute will never migrate to a new device, so after
a backup is restored to a new device, these items will be missing.
*/
case whenUnlockedThisDeviceOnly

/**
Item data can
only be accessed once the device has been unlocked after a restart.
This is recommended for items that need to be accessible by background
applications. Items with this attribute will never migrate to a new
device, so after a backup is restored to a new device these items will
be missing.
*/
case afterFirstUnlockThisDeviceOnly

/**
Item data can always
be accessed regardless of the lock state of the device. This option
is not recommended for anything except system use. Items with this
attribute will never migrate to a new device, so after a backup is
restored to a new device, these items will be missing.
*/
case alwaysThisDeviceOnly
}

extension KeychainAccessibility: RawRepresentable, CustomStringConvertible {

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:
return nil
}
}

public var rawValue: String {
switch self {
case .whenUnlocked:
return String(kSecAttrAccessibleWhenUnlocked)
case .afterFirstUnlock:
return String(kSecAttrAccessibleAfterFirstUnlock)
case .always:
return String(kSecAttrAccessibleAlways)
case .whenUnlockedThisDeviceOnly:
return String(kSecAttrAccessibleWhenUnlockedThisDeviceOnly)
case .afterFirstUnlockThisDeviceOnly:
return String(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly)
case .alwaysThisDeviceOnly:
return String(kSecAttrAccessibleAlwaysThisDeviceOnly)
}
}

public var description: String {
switch self {
case .whenUnlocked:
return "WhenUnlocked"
case .afterFirstUnlock:
return "AfterFirstUnlock"
case .always:
return "Always"
case .whenUnlockedThisDeviceOnly:
return "WhenUnlockedThisDeviceOnly"
case .afterFirstUnlockThisDeviceOnly:
return "AfterFirstUnlockThisDeviceOnly"
case .alwaysThisDeviceOnly:
return "AlwaysThisDeviceOnly"
}
}
}
93 changes: 93 additions & 0 deletions Source/KeychainStore/KeychainAttributes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// KeychainAttributes.swift
// GIGLibrary
//
// Created by Jerilyn Gonçalves on 06/03/2020.
// Copyright © 2020 Gigigo SL. All rights reserved.
//

import Foundation

public struct Attributes {

public var `class`: String? {
return self.attributes[KeychainConstants.Class] as? String
}
public var data: Data? {
return self.attributes[KeychainConstants.ValueData] as? Data
}
public var ref: Data? {
return self.attributes[KeychainConstants.ValueRef] as? Data
}
public var persistentRef: Data? {
return self.attributes[KeychainConstants.ValuePersistentRef] as? Data
}
public var accessible: String? {
return self.attributes[KeychainConstants.AttributeAccessible] as? String
}
public var accessGroup: String? {
return self.attributes[KeychainConstants.AttributeAccessGroup] as? String
}
public var synchronizable: Bool? {
return self.attributes[KeychainConstants.AttributeSynchronizable] as? Bool
}
public var creationDate: Date? {
return self.attributes[KeychainConstants.AttributeCreationDate] as? Date
}
public var modificationDate: Date? {
return self.attributes[KeychainConstants.AttributeModificationDate] as? Date
}
public var attributeDescription: String? {
return self.attributes[KeychainConstants.AttributeDescription] as? String
}
public var comment: String? {
return self.attributes[KeychainConstants.AttributeComment] as? String
}
public var creator: String? {
return self.attributes[KeychainConstants.AttributeCreator] as? String
}
public var type: String? {
return self.attributes[KeychainConstants.AttributeType] as? String
}
public var label: String? {
return self.attributes[KeychainConstants.AttributeLabel] as? String
}
public var isInvisible: Bool? {
return self.attributes[KeychainConstants.AttributeIsInvisible] as? Bool
}
public var isNegative: Bool? {
return self.attributes[KeychainConstants.AttributeIsNegative] as? Bool
}
public var account: String? {
return self.attributes[KeychainConstants.AttributeAccount] as? String
}
public var service: String? {
return self.attributes[KeychainConstants.AttributeService] as? String
}
public var generic: Data? {
return self.attributes[KeychainConstants.AttributeGeneric] as? Data
}

fileprivate let attributes: [String: Any]

init(attributes: [String: Any]) {
self.attributes = attributes
}

public subscript(key: String) -> Any? {
get {
return self.attributes[key]
}
}
}

extension Attributes: CustomStringConvertible, CustomDebugStringConvertible {

public var description: String {
return "\(self.attributes)"
}

public var debugDescription: String {
return self.description
}
}
Loading

0 comments on commit bdfe239

Please sign in to comment.