<commit_before>//
//  PGPKeySettingTableViewController.swift
//  pass
//
//  Created by <NAME> on 21/1/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import passKit

class PGPKeySettingTableViewController: AutoCellHeightUITableViewController {

    @IBOutlet weak var pgpPublicKeyURLTextField: UITextField!
    @IBOutlet weak var pgpPrivateKeyURLTextField: UITextField!
    var pgpPassphrase: String?
    let passwordStore = PasswordStore.shared

    override func viewDidLoad() {
        super.viewDidLoad()
        pgpPublicKeyURLTextField.text = SharedDefaults[.pgpPublicKeyURL]?.absoluteString
        pgpPrivateKeyURLTextField.text = SharedDefaults[.pgpPrivateKeyURL]?.absoluteString
        pgpPassphrase = passwordStore.pgpKeyPassphrase
    }

    private func validatePGPKeyURL(input: String?) -> Bool {
        guard let path = input, let url = URL(string: path) else {
            Utils.alert(title: "CannotSavePgpKey".localize(), message: "SetPgpKeyUrlFirst.".localize(), controller: self, completion: nil)
            return false
        }
        guard let scheme = url.scheme, scheme == "https", scheme == "https"  else {
            Utils.alert(title: "CannotSavePgpKey".localize(), message: "HttpNotSupported.".localize(), controller: self, completion: nil)
            return false
        }
        return true
    }

    @IBAction func save(_ sender: Any) {
        guard validatePGPKeyURL(input: pgpPublicKeyURLTextField.text) == true,
            validatePGPKeyURL(input: pgpPrivateKeyURLTextField.text) == true else {
                return
        }
        let savePassphraseAlert = UIAlertController(title: "Passphrase".localize(), message: "WantToSavePassphrase?".localize(), preferredStyle: UIAlertController.Style.alert)
        // no
        savePassphraseAlert.addAction(UIAlertAction(title: "No".localize(), style: UIAlertAction.Style.default) { _ in
            self.pgpPassphrase = nil
            SharedDefaults[.isRememberPGPPassphraseOn] = false
            self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)<commit_msg>Remove duplicated check for HTTPS<commit_after>//
//  PGPKeySettingTableViewController.swift
//  pass
//
//  Created by <NAME> on 21/1/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import passKit

class PGPKeySettingTableViewController: AutoCellHeightUITableViewController {

    @IBOutlet weak var pgpPublicKeyURLTextField: UITextField!
    @IBOutlet weak var pgpPrivateKeyURLTextField: UITextField!
    var pgpPassphrase: String?
    let passwordStore = PasswordStore.shared

    override func viewDidLoad() {
        super.viewDidLoad()
        pgpPublicKeyURLTextField.text = SharedDefaults[.pgpPublicKeyURL]?.absoluteString
        pgpPrivateKeyURLTextField.text = SharedDefaults[.pgpPrivateKeyURL]?.absoluteString
        pgpPassphrase = passwordStore.pgpKeyPassphrase
    }

    private func validatePGPKeyURL(input: String?) -> Bool {
        guard let path = input, let url = URL(string: path) else {
            Utils.alert(title: "CannotSavePgpKey".localize(), message: "SetPgpKeyUrlFirst.".localize(), controller: self, completion: nil)
            return false
        }
        guard let scheme = url.scheme, scheme == "https"  else {
            Utils.alert(title: "CannotSavePgpKey".localize(), message: "HttpNotSupported.".localize(), controller: self, completion: nil)
            return false
        }
        return true
    }

    @IBAction func save(_ sender: Any) {
        guard validatePGPKeyURL(input: pgpPublicKeyURLTextField.text) == true,
            validatePGPKeyURL(input: pgpPrivateKeyURLTextField.text) == true else {
                return
        }
        let savePassphraseAlert = UIAlertController(title: "Passphrase".localize(), message: "WantToSavePassphrase?".localize(), preferredStyle: UIAlertController.Style.alert)
        // no
        savePassphraseAlert.addAction(UIAlertAction(title: "No".localize(), style: UIAlertAction.Style.default) { _ in
            self.pgpPassphrase = nil
            SharedDefaults[.isRememberPGPPassphraseOn] = false
            self.performSegue(withIdentifier: "savePGPKeySegue", sender: self)
{'fraction_non_alphanumeric': 0.09740414384377233, 'fraction_numerical': 0.00523934270064301, 'mean_word_length': 3.2857142857142856, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3223412', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1155, 'n_words': 259}