CryptoPassphrase  Diff

Differences From Artifact [3b6682d3d0]:

To Artifact [768edd5da6]:


147
148
149
150
151
152
153
154
155







156
157
158
159
160
161
162
163
164

165
166
167
168

169
170
171
172
173
174
175

176
177
178
179
180
181
182
183
184
185
147
148
149
150
151
152
153


154
155
156
157
158
159
160
161
162
163
164
165
166
167


168




169
170






171
172
173

174
175
176
177
178
179
180







-
-
+
+
+
+
+
+
+







-
-
+
-
-
-
-
+

-
-
-
-
-
-
+


-








            let keyFilePath =
                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)
        let passphraseLen =
            passphraseText.lengthOfBytes(using: String.Encoding.utf8.rawValue)
        let passphrase = OFSecureData(count: passphraseLen,
                                      allowsSwappableMemory: false)
        memcpy(passphrase.mutableItems, passphraseText.utf8String!,
               passphraseLen)
        generator.passphrase = passphrase

        let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let activityController = mainStoryboard.instantiateViewController(
            withIdentifier: "activityIndicator")
        navigationController?.view.addSubview(activityController.view)

        DispatchQueue.global(qos: .default).async {
            OFException.try({
                generator.derivePassword()
            generator.derivePassword()
            }, finally: {
                if let keyFile = generator.keyFile as? OFMutableData {
                    of_explicit_memset(keyFile.mutableItems, 0, keyFile.count)
                }
        }

                of_explicit_memset(passphrase, 0, strlen(passphrase))
                free(passphrase)
            })
        }

        let password = NSMutableString(bytes: generator.output,
        let password = NSMutableString(bytes: generator.output.items,
                                       length: generator.length,
                                       encoding: String.Encoding.utf8.rawValue)!
        of_explicit_memset(generator.output, 0, generator.length)

        DispatchQueue.main.sync {
            activityController.view.isHidden = true
            block(password)
        }
    }