Index: iOS/Base.lproj/Main.storyboard ================================================================== --- iOS/Base.lproj/Main.storyboard +++ iOS/Base.lproj/Main.storyboard @@ -460,7 +460,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: iOS/ShowDetailsController.m ================================================================== --- iOS/ShowDetailsController.m +++ iOS/ShowDetailsController.m @@ -29,11 +29,11 @@ #import "PasswordGenerator.h" #import "NewPasswordGenerator.h" #import "LegacyPasswordGenerator.h" @interface ShowDetailsController () -- (NSMutableString*)_generate; +- (void)_generateWithCallback: (void(^)(NSMutableString*))block; - (void)_generateAndCopy; - (void)_generateAndShow; @end static void @@ -111,86 +111,98 @@ } } - (void)_generateAndCopy { - NSMutableString *password = [self _generate]; - - UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard]; - pasteBoard.string = password; - - clearNSMutableString(password); - - UIAlertController *alert = [UIAlertController - alertControllerWithTitle: @"Password Generated" - message: @"The password has been copied into the " - @"clipboard." - preferredStyle: UIAlertControllerStyleAlert]; - [alert addAction: - [UIAlertAction actionWithTitle: @"OK" - style: UIAlertActionStyleDefault - handler: ^ (UIAlertAction *action) { - [self.navigationController popViewControllerAnimated: YES]; - }]]; - - [self presentViewController: alert - animated: YES - completion: nil]; + [self _generateWithCallback: ^ (NSMutableString *password) { + UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard]; + pasteBoard.string = password; + + clearNSMutableString(password); + + UIAlertController *alert = [UIAlertController + alertControllerWithTitle: @"Password Generated" + message: @"The password has been copied " + @"into the clipboard." + preferredStyle: UIAlertControllerStyleAlert]; + [alert addAction: + [UIAlertAction actionWithTitle: @"OK" + style: UIAlertActionStyleDefault + handler: ^ (UIAlertAction *action) { + [self.navigationController popViewControllerAnimated: YES]; + }]]; + + [self presentViewController: alert + animated: YES + completion: nil]; + }]; } - (void)_generateAndShow { - NSMutableString *password = [self _generate]; - - UIAlertController *alert = [UIAlertController - alertControllerWithTitle: @"Generated Passphrase" - message: password - preferredStyle: UIAlertControllerStyleAlert]; - [alert addAction: - [UIAlertAction actionWithTitle: @"OK" - style: UIAlertActionStyleDefault - handler: ^ (UIAlertAction *action) { - [self.navigationController popViewControllerAnimated: YES]; - }]]; - - [self presentViewController: alert - animated: YES - completion: ^ { - clearNSMutableString(password); + [self _generateWithCallback: ^ (NSMutableString *password) { + UIAlertController *alert = [UIAlertController + alertControllerWithTitle: @"Generated Passphrase" + message: password + preferredStyle: UIAlertControllerStyleAlert]; + [alert addAction: + [UIAlertAction actionWithTitle: @"OK" + style: UIAlertActionStyleDefault + handler: ^ (UIAlertAction *action) { + [self.navigationController + popViewControllerAnimated: YES]; + }]]; + + [self presentViewController: alert + animated: YES + completion: ^ { + clearNSMutableString(password); + }]; }]; } -- (NSMutableString*)_generate -{ - id generator; - char *passphrase; - - if (_legacy) - generator = [LegacyPasswordGenerator generator]; - else - generator = [NewPasswordGenerator generator]; - - generator.site = _name; - generator.length = _length; - - passphrase = of_strdup([self.passphraseField.text UTF8String]); - @try { - self.passphraseField.text = @""; - generator.passphrase = passphrase; - - [generator derivePassword]; - } @finally { - of_explicit_memset(passphrase, 0, strlen(passphrase)); - free(passphrase); - } - - NSMutableString *password = [NSMutableString - stringWithUTF8String: (char*)generator.output]; - of_explicit_memset(generator.output, 0, - strlen((char*)generator.output)); - - return password; +- (void)_generateWithCallback: (void(^)(NSMutableString*))block +{ + UIStoryboard *mainStoryboard = + [UIStoryboard storyboardWithName: @"Main" + bundle: nil]; + UIViewController *activityController = [mainStoryboard + instantiateViewControllerWithIdentifier: @"activityIndicator"]; + [self.navigationController.view addSubview: activityController.view]; + + dispatch_async(dispatch_get_global_queue( + DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { + id generator; + char *passphrase; + + if (_legacy) + generator = [LegacyPasswordGenerator generator]; + else + generator = [NewPasswordGenerator generator]; + + generator.site = _name; + generator.length = _length; + + passphrase = of_strdup([self.passphraseField.text UTF8String]); + @try { + self.passphraseField.text = @""; + generator.passphrase = passphrase; + + [generator derivePassword]; + } @finally { + of_explicit_memset(passphrase, 0, strlen(passphrase)); + free(passphrase); + } + + NSMutableString *password = [NSMutableString + stringWithUTF8String: (char*)generator.output]; + of_explicit_memset(generator.output, 0, + strlen((char*)generator.output)); + + activityController.view.hidden = YES; + block(password); + }); } - (IBAction)remove: (id)sender { UIAlertController *alert = [UIAlertController