ViewController.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // ViewController.swift
  3. // OpenSSL-for-iOS
  4. //
  5. // Created by Felix Schulze on 04.12.2010.
  6. // Updated by Felix Schulze on 17.11.2015.
  7. // Copyright © 2015 Felix Schulze. All rights reserved.
  8. // Web: http://www.felixschulze.de
  9. //
  10. import UIKit
  11. class ViewController: UIViewController {
  12. @IBOutlet var textField: UITextField!
  13. @IBOutlet var md5Label: UILabel!
  14. @IBOutlet var sh256Label: UILabel!
  15. @IBAction
  16. func showInfo() {
  17. let message = "OpenSSL-Version: \(OPENSSL_VERSION_TEXT)\nLicense: See include/LICENSE\n\nCopyright 2010-2015 by Felix Schulze\n http://www.felixschulze.de"
  18. let alertController = UIAlertController(title: "OpenSSL-for-iOS", message: message, preferredStyle: .Alert)
  19. alertController.addAction(UIAlertAction(title: "Ok", style: .Cancel, handler: nil))
  20. self.presentViewController(alertController, animated: true, completion: nil)
  21. }
  22. override func viewDidLoad() {
  23. super.viewDidLoad()
  24. self.title = "OpenSSL-for-iOS"
  25. let infoButton = UIButton(type: .InfoLight)
  26. infoButton.addTarget(self, action: "showInfo", forControlEvents: .TouchDown)
  27. self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: infoButton)
  28. self.textField.addTarget(self, action: "textFieldDidChange", forControlEvents: .EditingChanged)
  29. self.calculateHash()
  30. }
  31. func textFieldDidChange() {
  32. self.calculateHash()
  33. }
  34. func calculateHash() {
  35. if textField.text!.characters.count > 0 {
  36. md5Label.text = FSOpenSSL.md5FromString(textField.text)
  37. sh256Label.text = FSOpenSSL.sha256FromString(textField.text)
  38. }
  39. else {
  40. md5Label.text = nil
  41. sh256Label.text = nil
  42. }
  43. }
  44. }