<commit_before>//  Created by <NAME> on 6/22/17.

import Foundation
import Security

public struct KeychainPreferences: Preferences {
  private let accessGroup: String?

  public init(accessGroup: String? = nil) {
    self.accessGroup = accessGroup
  }

  public func get<Key>(_ key: Key) -> Key.PreferenceValueType? where Key: PreferenceKey {
    var query = self.query(forKey: key.rawKey)
    query[kSecReturnData] = kCFBooleanTrue
    query[kSecMatchLimit] = kSecMatchLimitOne

    var result: AnyObject?
    let resultCode: OSStatus = withUnsafeMutablePointer(to: &result) {
      SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
    }
    print(resultCode)

    guard resultCode == noErr,
      let data = result as? Data else {
        return nil
    }

    return Key.PreferenceValueType.decode(data)
  }

  public func set<Key, Value>(_ value: Value?, for key: Key) where Key: PreferenceKey, Value == Key.PreferenceValueType {
    deleteItem(forKey: key.rawKey)

    guard let value = value,
      let encodedData = value.encode() else {
        return
    }

    var query = self.query(forKey: key.rawKey)
    query[kSecValueData] = encodedData

    let status: OSStatus = SecItemAdd(query as CFDictionary, nil)    
    print(status)
  }

  private func deleteItem(forKey key: String) {
    var query: [CFString: Any] = [
      kSecClass: kSecClassGenericPassword,
      kSecAttrAccount : key
    ]

    addAccessGroup(to: &query)

    let status = SecItemDelete(query as CFDictionary)
    print(status)
  }

  private func query(forKey key: String) -> [CFString: Any] {
    var query: [CFString: Any] = [
      kSecClass: kSecClassGenericPassword,
      kSecAttrAccount: key,
      ]
    addAccessGroup(to: &query)
    return query
  }

  private func addAccessGroup(to query: inout [CFString: Any]) {
    if let accessGroup = accessGroup {
      query[kSecAttrAccessGroup] = accessGroup
    }
  }
}
<commit_msg>Remove not needed logs<commit_after>//  Created by <NAME> on 6/22/17.

import Foundation
import Security

public struct KeychainPreferences: Preferences {
  private let accessGroup: String?

  public init(accessGroup: String? = nil) {
    self.accessGroup = accessGroup
  }

  public func get<Key>(_ key: Key) -> Key.PreferenceValueType? where Key: PreferenceKey {
    var query = self.query(forKey: key.rawKey)
    query[kSecReturnData] = kCFBooleanTrue
    query[kSecMatchLimit] = kSecMatchLimitOne

    var result: AnyObject?
    let resultCode: OSStatus = withUnsafeMutablePointer(to: &result) {
      SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
    }

    guard resultCode == noErr,
      let data = result as? Data else {
        return nil
    }

    return Key.PreferenceValueType.decode(data)
  }

  public func set<Key, Value>(_ value: Value?, for key: Key) where Key: PreferenceKey, Value == Key.PreferenceValueType {
    deleteItem(forKey: key.rawKey)

    guard let value = value,
      let encodedData = value.encode() else {
        return
    }

    var query = self.query(forKey: key.rawKey)
    query[kSecValueData] = encodedData

    let _: OSStatus = SecItemAdd(query as CFDictionary, nil)
  }

  private func deleteItem(forKey key: String) {
    var query: [CFString: Any] = [
      kSecClass: kSecClassGenericPassword,
      kSecAttrAccount : key
    ]

    addAccessGroup(to: &query)

    let _: OSStatus = SecItemDelete(query as CFDictionary)
  }

  private func query(forKey key: String) -> [CFString: Any] {
    var query: [CFString: Any] = [
      kSecClass: kSecClassGenericPassword,
      kSecAttrAccount: key,
      ]
    addAccessGroup(to: &query)
    return query
  }

  private func addAccessGroup(to query: inout [CFString: Any]) {
    if let accessGroup = accessGroup {
      query[kSecAttrAccessGroup] = accessGroup
    }
  }
}

{'fraction_non_alphanumeric': 0.0947533281127643, 'fraction_numerical': 0.0031323414252153485, 'mean_word_length': 3.286353467561521, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '7536409', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1184, 'n_words': 317}