CDSignatureCertificateStateViewController.swift 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // CDSignatureCertificateStateViewController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/10/20.
  6. //
  7. import Cocoa
  8. class CDSignatureCertificateStateViewController: NSViewController {
  9. @IBOutlet weak var titleLabel: NSTextField!
  10. @IBOutlet weak var imageView: NSImageView!
  11. @IBOutlet weak var subTitleLabel: NSTextField!
  12. @IBOutlet weak var subDes1Label: NSTextField!
  13. @IBOutlet weak var subDes2Label: NSTextField!
  14. @IBOutlet weak var propertiesBtn: NSButton!
  15. @IBOutlet weak var closeBtn: NSButton!
  16. var signature: CPDFSignature!
  17. var pdfListView: CPDFDigtalView!
  18. var actionBlock: ((_ stateVC: CDSignatureCertificateStateViewController, _ actionType: DSignatureActionType)->Void)?
  19. override func viewDidAppear() {
  20. super.viewDidAppear()
  21. self.reloadData()
  22. }
  23. override func viewDidLoad() {
  24. super.viewDidLoad()
  25. // Do view setup here.
  26. self.titleLabel.stringValue = NSLocalizedString("Signature Validation Status", comment: "")
  27. self.reloadData()
  28. }
  29. func reloadData () {
  30. let signer = self.signature.signers.first
  31. let isSignVerified = signer?.isSignVerified
  32. let isCertTrusted = signer?.isCertTrusted
  33. if isSignVerified == true && isCertTrusted == true {
  34. self.imageView.image = NSImage(named: "ImageNameSigntureLargeVerifySuccess")
  35. let cer = signer?.certificates.first
  36. let CNStr = cer?.subjectDict["CN"] as! String
  37. self.subTitleLabel.stringValue = String(format: NSLocalizedString("Signature is VALID, signed by %@.", comment: ""), CNStr)
  38. self.subDes1Label.stringValue = String(format: "- %@",NSLocalizedString("The document has not been modified since this signature was applied.", comment: ""))
  39. self.subDes2Label.stringValue = String(format: "- %@",NSLocalizedString("The signer's identity is valid.", comment: ""))
  40. } else if isSignVerified == true && isCertTrusted == false {
  41. self.imageView.image = NSImage(named: "ImageNameSigntureLargeTrustedFailure")
  42. self.subTitleLabel.stringValue = NSLocalizedString("Signature is invalid", comment: "")
  43. self.subDes1Label.stringValue = String(format: "- %@",NSLocalizedString("The document has not been modified since this signature was applied.", comment: ""))
  44. self.subDes2Label.stringValue = String(format: "- %@",NSLocalizedString("The signer's identity is unknown because it has not been included in your list of trusted certificates and none of its parent certificates are trusted certificates.", comment: ""))
  45. } else if isSignVerified == false && isCertTrusted == false {
  46. self.imageView.image = NSImage(named: "ImageNameSigntureLargeVerifyFailure")
  47. self.subTitleLabel.stringValue = NSLocalizedString("Signature is invalid", comment: "")
  48. self.subDes1Label.stringValue = String(format: "- %@",NSLocalizedString("The document has not been modified since this signature was applied.", comment: ""))
  49. self.subDes2Label.stringValue = String(format: "- %@",NSLocalizedString("The signer's identity is invalid.", comment: ""))
  50. } else {
  51. self.imageView.image = NSImage(named: "ImageNameSigntureLargeVerifyFailure")
  52. self.subTitleLabel.stringValue = NSLocalizedString("Signature is invalid", comment: "")
  53. self.subDes1Label.stringValue = String(format: "- %@",NSLocalizedString("The revision of the document that was covered by this signature has not been altered; however, there have been subsequent changes to the document.", comment: ""))
  54. self.subDes2Label.stringValue = String(format: "- %@",NSLocalizedString("Click Signature Properties, then it will show what is covered by this signature.", comment: ""))
  55. }
  56. self.propertiesBtn.title = NSLocalizedString("Signature Properties...", comment: "")
  57. self.closeBtn.title = NSLocalizedString("Close", comment: "")
  58. self.subTitleLabel.textColor = NSColor.labelColor
  59. self.titleLabel.textColor = NSColor.labelColor
  60. self.subDes1Label.textColor = NSColor.labelColor
  61. self.subDes2Label.textColor = NSColor.labelColor
  62. }
  63. //MARK: IBAction
  64. @IBAction func buttonItemClick_Properties(_ sender: NSButton) {
  65. guard let callBack = self.actionBlock else {
  66. return
  67. }
  68. callBack(self, .confirm)
  69. }
  70. @IBAction func buttonItemClick_Close(_ sender: Any) {
  71. guard let callBack = self.actionBlock else {
  72. return
  73. }
  74. callBack(self, .cancel)
  75. }
  76. }