@@ -5,31 +5,31 @@ let groupName = "group.net.defined.mobileNebula"
55class KeyChain {
66 class func save( key: String , data: Data , managed: Bool ) -> Bool {
77 var query : [ String : Any ] = [
8- kSecClass as String : kSecClassGenericPassword as String ,
9- kSecAttrAccount as String : key,
10- kSecValueData as String : data,
8+ kSecClass as String : kSecClassGenericPassword as String ,
9+ kSecAttrAccount as String : key,
10+ kSecValueData as String : data,
1111 kSecAttrAccessGroup as String : groupName,
1212 ]
13-
14- if ( managed) {
13+
14+ if managed {
1515 query [ kSecAttrAccessible as String ] = kSecAttrAccessibleAfterFirstUnlock
1616 }
1717
1818 // Attempt to delete an existing key to allow for an overwrite
19- _ = self . delete ( key: key)
19+ _ = delete ( key: key)
2020 return SecItemAdd ( query as CFDictionary , nil ) == 0
2121 }
2222
2323 class func load( key: String ) -> Data ? {
2424 let query : [ String : Any ] = [
25- kSecClass as String : kSecClassGenericPassword,
26- kSecAttrAccount as String : key,
27- kSecReturnData as String : kCFBooleanTrue!,
28- kSecMatchLimit as String : kSecMatchLimitOne,
25+ kSecClass as String : kSecClassGenericPassword,
26+ kSecAttrAccount as String : key,
27+ kSecReturnData as String : kCFBooleanTrue!,
28+ kSecMatchLimit as String : kSecMatchLimitOne,
2929 kSecAttrAccessGroup as String : groupName,
3030 ]
3131
32- var dataTypeRef : AnyObject ? = nil
32+ var dataTypeRef : AnyObject ?
3333
3434 let status : OSStatus = SecItemCopyMatching ( query as CFDictionary , & dataTypeRef)
3535
@@ -39,31 +39,29 @@ class KeyChain {
3939 return nil
4040 }
4141 }
42-
42+
4343 class func delete( key: String ) -> Bool {
44- let query : [ String : Any ] = [
45- kSecClass as String : kSecClassGenericPassword as String ,
46- kSecAttrAccount as String : key,
47- kSecAttrAccessGroup as String : groupName,
48- ]
44+ let query : [ String : Any ] = [
45+ kSecClass as String : kSecClassGenericPassword as String ,
46+ kSecAttrAccount as String : key,
47+ kSecAttrAccessGroup as String : groupName,
48+ ]
4949
5050 return SecItemDelete ( query as CFDictionary ) == 0
5151 }
5252}
5353
5454extension Data {
55-
5655 init < T> ( from value: T ) {
5756 var value = value
5857 var data = Data ( )
59- withUnsafePointer ( to: & value, { ( ptr: UnsafePointer < T > ) -> Void in
58+ withUnsafePointer ( to: & value) { ( ptr: UnsafePointer < T > ) in
6059 data = Data ( buffer: UnsafeBufferPointer ( start: ptr, count: 1 ) )
61- } )
60+ }
6261 self . init ( data)
6362 }
6463
65- func to< T> ( type: T . Type ) -> T {
66- return self . withUnsafeBytes { $0. load ( as: T . self) }
64+ func to< T> ( type _ : T . Type ) -> T {
65+ return withUnsafeBytes { $0. load ( as: T . self) }
6766 }
6867}
69-
0 commit comments