error.rb 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module SecureMailing::PGP::Tool::Error
  3. def self.exception(code)
  4. {
  5. 'NODATA' => SecureMailing::PGP::Tool::Error::NoData,
  6. 'NO_SECKEY' => SecureMailing::PGP::Tool::Error::NoSecretKey,
  7. 'NO_PUBKEY' => SecureMailing::PGP::Tool::Error::NoPublicKey,
  8. 'KEYEXPIRED' => SecureMailing::PGP::Tool::Error::ExpiredKey,
  9. 'KEYREVOKED' => SecureMailing::PGP::Tool::Error::RevokedKey,
  10. 'EXPSIG' => SecureMailing::PGP::Tool::Error::ExpiredSignature,
  11. 'BADSIG' => SecureMailing::PGP::Tool::Error::BadSignature,
  12. 'EXPKEYSIG' => SecureMailing::PGP::Tool::Error::ExpiredKeySignature,
  13. 'REVKEYSIG' => SecureMailing::PGP::Tool::Error::RevokedKeySignature,
  14. 'INV_RECP' => SecureMailing::PGP::Tool::Error::InvalidRecipient,
  15. 'INV_SGNR' => SecureMailing::PGP::Tool::Error::InvalidSigner,
  16. 'NO_RECP' => SecureMailing::PGP::Tool::Error::NoRecipient,
  17. 'NO_SGNR' => SecureMailing::PGP::Tool::Error::NoSigner,
  18. }[code]
  19. end
  20. class SecureMailing::PGP::Tool::Error::NoData < StandardError
  21. def initialize(info)
  22. msg = __('There was no valid OpenPGP data found.')
  23. msg = "#{msg} #{info}" if info.present?
  24. super(msg)
  25. end
  26. end
  27. class SecureMailing::PGP::Tool::Error::NoSecretKey < StandardError
  28. def initialize(info)
  29. msg = __('There was no secret PGP key found.')
  30. msg = "#{msg} #{info}" if info.present?
  31. super(msg)
  32. end
  33. end
  34. class SecureMailing::PGP::Tool::Error::NoPublicKey < StandardError
  35. def initialize(info)
  36. msg = __('There was no public PGP key found.')
  37. msg = "#{msg} #{info}" if info.present?
  38. super(msg)
  39. end
  40. end
  41. class SecureMailing::PGP::Tool::Error::ExpiredKey < StandardError
  42. def initialize(info)
  43. msg = __('The PGP key has expired.')
  44. msg = "#{msg} #{info}" if info.present?
  45. super(msg)
  46. end
  47. end
  48. class SecureMailing::PGP::Tool::Error::RevokedKey < StandardError
  49. def initialize(info)
  50. msg = __('The PGP key has been revoked.')
  51. msg = "#{msg} #{info}" if info.present?
  52. super(msg)
  53. end
  54. end
  55. class SecureMailing::PGP::Tool::Error::ExpiredSignature < StandardError
  56. def initialize(info)
  57. msg = __('The PGP signature has expired.')
  58. msg = "#{msg} #{info}" if info.present?
  59. super(msg)
  60. end
  61. end
  62. class SecureMailing::PGP::Tool::Error::BadSignature < StandardError
  63. def initialize(info)
  64. msg = __('The PGP signature is invalid.')
  65. msg = "#{msg} #{info}" if info.present?
  66. super(msg)
  67. end
  68. end
  69. class SecureMailing::PGP::Tool::Error::ExpiredKeySignature < StandardError
  70. def initialize(info)
  71. msg = __('The signature PGP key has expired.')
  72. msg = "#{msg} #{info}" if info.present?
  73. super(msg)
  74. end
  75. end
  76. class SecureMailing::PGP::Tool::Error::RevokedKeySignature < StandardError
  77. def initialize(info)
  78. msg = __('The PGP signature key has been revoked.')
  79. msg = "#{msg} #{info}" if info.present?
  80. super(msg)
  81. end
  82. end
  83. class SecureMailing::PGP::Tool::Error::InvalidRecipient < StandardError
  84. def initialize(info)
  85. msg = __('The PGP email recipient is invalid.')
  86. msg = "#{msg} #{info}" if info.present?
  87. super(msg)
  88. end
  89. end
  90. class SecureMailing::PGP::Tool::Error::InvalidSigner < StandardError
  91. def initialize(info)
  92. msg = __('The PGP email signer is invalid.')
  93. msg = "#{msg} #{info}" if info.present?
  94. super(msg)
  95. end
  96. end
  97. class SecureMailing::PGP::Tool::Error::NoRecipient < StandardError
  98. def initialize(info)
  99. msg = __('There is no valid PGP email recipient.')
  100. msg = "#{msg} #{info}" if info.present?
  101. super(msg)
  102. end
  103. end
  104. class SecureMailing::PGP::Tool::Error::NoSigner < StandardError
  105. def initialize(info)
  106. msg = __('There is no valid PGP email signer.')
  107. msg = "#{msg} #{info}" if info.present?
  108. super(msg)
  109. end
  110. end
  111. class SecureMailing::PGP::Tool::Error::BadPassphrase < StandardError
  112. def initialize(info)
  113. msg = __('The PGP passphrase is invalid.')
  114. msg = "#{msg} #{info}" if info.present?
  115. super(msg)
  116. end
  117. end
  118. class SecureMailing::PGP::Tool::Error::NoPassphrase < StandardError
  119. def initialize(info)
  120. msg = __('The required PGP passphrase is missing.')
  121. msg = "#{msg} #{info}" if info.present?
  122. super(msg)
  123. end
  124. end
  125. class SecureMailing::PGP::Tool::Error::UnknownError < StandardError
  126. def initialize(info)
  127. msg = __('There was an unknown PGP error.')
  128. msg = "#{msg} #{info}" if info.present?
  129. super(msg)
  130. end
  131. end
  132. end