<commit_before>//
//  KeyStorage - Simplifying securely saving key information
//  KeyChainInfo.swift
//
//  Created by <NAME> on 3/23/16.
//  Copyright © 2019 <EMAIL>. All rights reserved.
//

import Foundation
import Security

/**
 
 Contains information related to the Keychain
 
 */
public struct KeyChainInfo {
    
    /**
     
     Struct returned from getAccessGroupInfo with information related to the Keychain Group.
     
     */
    public struct AccessGroupInfo {
        
        /// App ID Prefix
        public var prefix: String
        
        /// Keycahin Group
        public var keyChainGroup: String
        
        /// Raw kSecAttrAccessGroup value returned from Keychain
        public var rawValue: String
    }
    
    /**
     
     Enum to used determine error details
     
     */
    public enum errorDetail: Error {
        /// No password provided or available
        case noPassword
        /// Incorrect data provided as part of the password return
        case unexpectedPasswordData
        /// Incorrect data provided for a non password Keychain item
        case unexpectedItemData
        /// Unknown error returned by keychain
        case unhandledError(status: OSStatus)
    }
    
    /**
     
     Enum to used map the accessibility of keychain items.
     
     For example, if whenUnlockedThisDeviceOnly the item data can
     only be accessed once the device has been unlocked after a restart.
     
     */
    public enum accessibleOption: RawRepresentable {
        case whenUnlocked,
        afterFirstUnlock,
        whenUnlockedThisDeviceOnly,
        afterFirstUnlockThisDeviceOnly,
        whenPasscodeSetThisDeviceOnly
        
        public init?(rawValue: String) {
            switch rawValue {
                
                /**
                 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 String(kSecAttrAccessibleWhenUnlocked):
                self = .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 String(kSecAttrAccessibleAfterFirstUnlock):
                self = .afterFirstUnlock
                /**
                 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 String(kSecAttrAccessibleWhenUnlockedThisDeviceOnly):
                self = .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 String(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly):
                self = .afterFirstUnlockThisDeviceOnly
                                <commit_msg>Fix formatting<commit_after>//
//  KeyStorage - Simplifying securely saving key information
//  KeyChainInfo.swift
//
//  Created by <NAME> on 3/23/16.
//  Copyright © 2019 <EMAIL>. All rights reserved.
//

import Foundation
import Security

/**
 
 Contains information related to the Keychain
 
 */
public struct KeyChainInfo {
    
    /**
     
     Struct returned from getAccessGroupInfo with information related to the Keychain Group.
     
     */
    public struct AccessGroupInfo {
        
        /// App ID Prefix
        public var prefix: String
        
        /// Keycahin Group
        public var keyChainGroup: String
        
        /// Raw kSecAttrAccessGroup value returned from Keychain
        public var rawValue: String
    }
    
    /**
     
     Enum to used determine error details
     
     */
    public enum errorDetail: Error {
        /// No password provided or available
        case noPassword
        /// Incorrect data provided as part of the password return
        case unexpectedPasswordData
        /// Incorrect data provided for a non password Keychain item
        case unexpectedItemData
        /// Unknown error returned by keychain
        case unhandledError(status: OSStatus)
    }
    
    /**
     
     Enum to used map the accessibility of keychain items.
     
     For example, if whenUnlockedThisDeviceOnly the item data can
     only be accessed once the device has been unlocked after a restart.
     
     */
    public enum accessibleOption: RawRepresentable {
        case whenUnlocked,
        afterFirstUnlock,
        whenUnlockedThisDeviceOnly,
        afterFirstUnlockThisDeviceOnly,
        whenPasscodeSetThisDeviceOnly
        
        public init?(rawValue: String) {
            switch rawValue {
                
                /**
                 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 String(kSecAttrAccessibleWhenUnlocked):
                self = .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 String(kSecAttrAccessibleAfterFirstUnlock):
                self = .afterFirstUnlock

                /**
                 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 String(kSecAttrAccessibleWhenUnlockedThisDeviceOnly):
                self = .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 String(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly):
                self = .afterFirstUnlockThisDeviceOnly
                                
{'fraction_non_alphanumeric': 0.03900076472087688, 'fraction_numerical': 0.0022941626306398166, 'mean_word_length': 1.5837998024366151, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4652853', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1649, 'n_words': 739}