diff --git a/iOS/AboutController.h b/iOS/AboutController.h deleted file mode 100644 index 4c91705..0000000 --- a/iOS/AboutController.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2016 - 2019 Jonathan Schleifer - * - * https://heap.zone/git/scrypt-pwgen.git - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice is present in all copies. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -@import UIKit; - -@interface AboutController: UIViewController -@property (nonatomic, retain) IBOutlet UIWebView *webView; -@end diff --git a/iOS/AboutController.m b/iOS/AboutController.m deleted file mode 100644 index ef39a82..0000000 --- a/iOS/AboutController.m +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2016 - 2019 Jonathan Schleifer - * - * https://heap.zone/git/scrypt-pwgen.git - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice is present in all copies. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#import "AboutController.h" - -static NSString *aboutHTMLTemplate = - @"" - @"" - @"" - @"" - @"" - @"
" - @" scrypt-pwgen {version}" - @"
" - @"" - @"

" - @" scrypt-pwgen is free software and the source code is available at " - @" here." - @"

" - @"

" - @" It makes use of the ObjFW " - @"framework and also uses its scrypt implementation." - @"

" - @"" - @""; - -@implementation AboutController -- (void)viewDidLoad -{ - [super viewDidLoad]; - - self.automaticallyAdjustsScrollViewInsets = NO; - - NSDictionary *infoDictionary = NSBundle.mainBundle.infoDictionary; - NSString *version = infoDictionary[@"CFBundleShortVersionString"]; - NSString *aboutHTML = [aboutHTMLTemplate - stringByReplacingOccurrencesOfString: @"{version}" - withString: version]; - [self.webView loadHTMLString: aboutHTML - baseURL: nil]; -} - -- (void)dealloc -{ - [_webView release]; - - [super dealloc]; -} - -- (BOOL)webView: (UIWebView *)webView - shouldStartLoadWithRequest: (NSURLRequest *)request - navigationType: (UIWebViewNavigationType)navigationType -{ - if (navigationType == UIWebViewNavigationTypeLinkClicked) { - [UIApplication.sharedApplication openURL: request.URL - options: @{} - completionHandler: ^ (BOOL success) { - }]; - return NO; - } - - return YES; -} -@end diff --git a/iOS/AboutController.swift b/iOS/AboutController.swift new file mode 100644 index 0000000..b6b7c30 --- /dev/null +++ b/iOS/AboutController.swift @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016 - 2019 Jonathan Schleifer + * + * https://heap.zone/git/scrypt-pwgen.git + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +import UIKit + +class AboutController: UIViewController, UIWebViewDelegate { + @IBOutlet var webView: UIWebView? + + override func viewDidLoad() { + super.viewDidLoad() + + self.automaticallyAdjustsScrollViewInsets = false + + let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] + webView?.loadHTMLString( + "" + + "" + + "" + + "" + + "" + + "
" + + " scrypt-pwgen \(version ?? "")" + + "
" + + "" + + "

" + + " scrypt-pwgen is free software and the source code is available" + + " at here." + + "

" + + "

" + + " It makes use of the" + + " ObjFW framework and" + + " also uses its scrypt implementation." + + "

" + + "" + + "", baseURL: nil) + } + + func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, + navigationType: UIWebView.NavigationType) -> Bool { + if #available(iOS 10.0, *), + navigationType == UIWebView.NavigationType.linkClicked, + let url = request.url { + UIApplication.shared.open(url) + return false + } + + return true + } +} diff --git a/iOS/AddSiteController.h b/iOS/AddSiteController.h deleted file mode 100644 index 9d72076..0000000 --- a/iOS/AddSiteController.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016 - 2019 Jonathan Schleifer - * - * https://heap.zone/git/scrypt-pwgen.git - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice is present in all copies. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -@import UIKit; - -#import "MainViewController.h" - -@interface AddSiteController: UITableViewController -@property (nonatomic, retain) IBOutlet UITextField *nameField; -@property (nonatomic, retain) IBOutlet UITextField *lengthField; -@property (nonatomic, retain) IBOutlet UISwitch *legacySwitch; -@property (nonatomic, copy) NSString *keyFile; -@property (nonatomic, retain) IBOutlet UILabel *keyFileLabel; -@property (retain) MainViewController *mainViewController; - -- (IBAction)done: (id)sender; -- (IBAction)cancel: (id)sender; -@end diff --git a/iOS/AddSiteController.m b/iOS/AddSiteController.m deleted file mode 100644 index 8a47992..0000000 --- a/iOS/AddSiteController.m +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2016 - 2019 Jonathan Schleifer - * - * https://heap.zone/git/scrypt-pwgen.git - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice is present in all copies. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -@import ObjFW_Bridge; - -#import "AddSiteController.h" -#import "SelectKeyFileController.h" - -static void -showAlert(UIViewController *controller, NSString *title, NSString *message) -{ - UIAlertController *alert = [UIAlertController - alertControllerWithTitle: title - message: message - preferredStyle: UIAlertControllerStyleAlert]; - [alert addAction: - [UIAlertAction actionWithTitle: @"OK" - style: UIAlertActionStyleDefault - handler: nil]]; - - [controller presentViewController: alert - animated: YES - completion: nil]; -} - -@implementation AddSiteController -- (void)dealloc -{ - [_nameField release]; - [_lengthField release]; - [_legacySwitch release]; - [_keyFile release]; - [_keyFileLabel release]; - [_mainViewController release]; - - [super dealloc]; -} - -- (void)tableView: (UITableView *)tableView - didSelectRowAtIndexPath: (NSIndexPath *)indexPath -{ - [tableView deselectRowAtIndexPath: indexPath - animated: YES]; - - if (indexPath.section == 1 && indexPath.row == 1) - [self performSegueWithIdentifier: @"selectKeyFile" - sender: self]; -} - -- (NSIndexPath *)tableView: (UITableView *)tableView - willSelectRowAtIndexPath: (NSIndexPath *)indexPath -{ - if (indexPath.section == 1 && indexPath.row == 1) - return indexPath; - - return nil; -} - -- (IBAction)done: (id)sender -{ - OFString *name = self.nameField.text.OFObject; - OFString *lengthString = self.lengthField.text.OFObject; - bool lengthValid = true; - size_t length; - - if (name.length == 0) { - showAlert(self, @"Name missing", @"Please enter a name."); - return; - } - - @try { - length = (size_t)lengthString.decimalValue; - - if (length < 3 || length > 64) - lengthValid = false; - } @catch (OFInvalidFormatException *e) { - lengthValid = false; - } - - if (!lengthValid) { - showAlert(self, @"Invalid length", - @"Please enter a number between 3 and 64."); - return; - } - - if ([self.mainViewController.siteStorage hasSite: name]) { - showAlert(self, @"Site Already Exists", - @"Please pick a name that does not exist yet."); - return; - } - - [self.mainViewController.siteStorage setSite: name - length: length - legacy: self.legacySwitch.on - keyFile: self.keyFile.OFObject]; - [self.mainViewController reset]; - - [self.navigationController popViewControllerAnimated: YES]; -} - -- (IBAction)cancel: (id)sender -{ - [self.navigationController popViewControllerAnimated: YES]; -} - -- (void)prepareForSegue: (UIStoryboardSegue *)segue - sender: (id)sender -{ - if ([segue.identifier isEqual: @"selectKeyFile"]) - [segue.destinationViewController setAddSiteController: self]; -} -@end diff --git a/iOS/AddSiteController.swift b/iOS/AddSiteController.swift new file mode 100644 index 0000000..73b369e --- /dev/null +++ b/iOS/AddSiteController.swift @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2016 - 2019 Jonathan Schleifer + * + * https://heap.zone/git/scrypt-pwgen.git + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +import UIKit +import ObjFW +import ObjFW_Bridge + +class AddSiteController: UITableViewController { + @IBOutlet var nameField: UITextField? + @IBOutlet var lengthField: UITextField? + @IBOutlet var legacySwitch: UISwitch? + public var keyFile: String? + @IBOutlet var keyFileLabel: UILabel? + public var mainViewController: MainViewController? + + override func tableView(_ tableView: UITableView, + didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: true) + + if indexPath.section == 1 && indexPath.row == 1 { + self.performSegue(withIdentifier: "selectKeyFile", sender: self) + } + } + + override func tableView( + _ tableView: UITableView, + willSelectRowAt indexPath: IndexPath + ) -> IndexPath? { + if indexPath.section == 1 && indexPath.row == 1 { + return indexPath + } + + return nil + } + + private func showAlert(controller: UIViewController, title: String, + message: String) { + let alert = UIAlertController(title: title, message: message, + preferredStyle: .alert) + alert.addAction( + UIAlertAction(title: "OK", style: .default, handler: nil)) + controller.present(alert, animated: true, completion: nil) + } + + @IBAction func done(_ sender: Any) { + guard let name = nameField?.text?.ofObject else { return } + guard let lengthString = lengthField?.text?.ofObject else { return } + + guard name.length > 0 else { + showAlert(controller: self, title: "Name missing", + message: "Please enter a name.") + return + } + + var lengthValid = true + var length: size_t = 0 + OFException.try({ + length = lengthString.decimalValue + + if length < 3 || length > 64 { + lengthValid = false + } + }, catch: { (OFException) in + lengthValid = false + }) + + guard lengthValid else { + showAlert(controller: self, title: "Invalid length", + message: "Please enter a number between 3 and 64.") + return + } + + guard let siteStorage = mainViewController?.siteStorage else { return } + + guard !siteStorage.hasSite(name) else { + showAlert(controller: self, title: "Site Already Exists", + message: "Please pick a name that does not exist yet.") + return + } + + let keyFile = self.keyFile?.ofObject + siteStorage.setSite(name, length: length, + legacy: legacySwitch?.isOn ?? false, + keyFile: keyFile) + mainViewController?.reset() + navigationController?.popViewController(animated: true) + } + + @IBAction func cancel(_ sender: Any) { + navigationController?.popViewController(animated: true) + } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if segue.identifier == "selectKeyFile" { + let controller = segue.destination as? SelectKeyFileController + controller?.addSiteController = self + } + } +} diff --git a/iOS/AppDelegate.h b/iOS/AppDelegate.h deleted file mode 100644 index 1956098..0000000 --- a/iOS/AppDelegate.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2016 - 2019 Jonathan Schleifer - * - * https://heap.zone/git/scrypt-pwgen.git - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice is present in all copies. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -@import UIKit; - -@interface AppDelegate: UIResponder -@property (nonatomic, strong) UIWindow *window; -@end diff --git a/iOS/AppDelegate.m b/iOS/AppDelegate.swift similarity index 90% rename from iOS/AppDelegate.m rename to iOS/AppDelegate.swift index 08dff5d..2706ffb 100644 --- a/iOS/AppDelegate.m +++ b/iOS/AppDelegate.swift @@ -20,13 +20,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#import "AppDelegate.h" +import UIKit -@implementation AppDelegate -- (void)dealloc -{ - [_window release]; - - [super dealloc]; +@objc class AppDelegate: UIResponder, UIApplicationDelegate { + public var window: UIWindow? } -@end diff --git a/iOS/Base.lproj/Main.storyboard b/iOS/Base.lproj/Main.storyboard index 8a70541..10887f0 100644 --- a/iOS/Base.lproj/Main.storyboard +++ b/iOS/Base.lproj/Main.storyboard @@ -1,12 +1,11 @@ - + - - + @@ -32,7 +31,7 @@ - + @@ -93,7 +92,7 @@ - + @@ -130,7 +129,7 @@ - + @@ -242,7 +241,7 @@