CryptoPassphrase  Diff

Differences From Artifact [028af44e3c]:

To Artifact [3b6682d3d0]:


28
29
30
31
32
33
34
35
36


37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
56

57
58
59
60
61
62
63
28
29
30
31
32
33
34


35
36
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55

56
57
58
59
60
61
62
63







-
-
+
+

-
+














-
+


-
+







    @IBOutlet var nameField: UITextField?
    @IBOutlet var lengthField: UITextField?
    @IBOutlet var legacySwitch: UISwitch?
    @IBOutlet var keyFileField: UITextField?
    @IBOutlet var passphraseField: UITextField?
    public var mainViewController: MainViewController?

    private var name: OFString = "".ofObject
    private var length: size_t = 0
    private var name: String = ""
    private var length: UInt = 0
    private var isLegacy: Bool = false
    private var keyFile: OFString? = nil
    private var keyFile: String? = nil

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        guard let mainViewController = self.mainViewController else { return }
        guard let tableView = mainViewController.tableView else { return }
        let siteStorage = mainViewController.siteStorage
        guard let indexPath = tableView.indexPathForSelectedRow else { return }

        name = mainViewController.sites[indexPath.row]
        length = siteStorage.length(forSite: name)
        isLegacy = siteStorage.isLegacy(site: name)
        keyFile = siteStorage.keyFile(forSite: name)

        nameField?.text = name.nsObject
        nameField?.text = name
        lengthField?.text = "\(length)"
        legacySwitch?.isOn = isLegacy
        keyFileField?.text = keyFile?.nsObject
        keyFileField?.text = keyFile

        tableView.deselectRow(at: indexPath, animated: true)
    }

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return false
130
131
132
133
134
135
136
137
138


139
140
141
142
143
144
145
146
147

148

149
150
151
152
153
154
155
130
131
132
133
134
135
136


137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156







-
-
+
+









+
-
+







            }
        }
    }

    private func generateWithCallback(_ block: (_: NSMutableString) -> ()) {
        let generator: PasswordGenerator = isLegacy ?
            LegacyPasswordGenerator() : NewPasswordGenerator()
        generator.site = name
        generator.length = length
        generator.site = name.ofObject
        generator.length = size_t(length)

        if let keyFile = keyFile {
            guard let documentDirectory = NSSearchPathForDirectoriesInDomains(
                .documentDirectory, .userDomainMask, true).first
            else {
                print("Could not get key files: No documents directory")
                return
            }

            let keyFilePath =
            let keyFilePath = documentDirectory.ofObject.appending(keyFile)
                documentDirectory.ofObject.appending(keyFile.ofObject)
            generator.keyFile = OFMutableData(contentsOfFile: keyFilePath)
        }

        let passphraseText = (passphraseField?.text ?? "") as NSString
        let passphrase = of_strdup(passphraseText.utf8String!)!
        generator.passphrase = UnsafePointer<CChar>(passphrase)