exceptions.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. from __future__ import absolute_import, division, print_function
  5. from enum import Enum
  6. class _Reasons(Enum):
  7. BACKEND_MISSING_INTERFACE = 0
  8. UNSUPPORTED_HASH = 1
  9. UNSUPPORTED_CIPHER = 2
  10. UNSUPPORTED_PADDING = 3
  11. UNSUPPORTED_MGF = 4
  12. UNSUPPORTED_PUBLIC_KEY_ALGORITHM = 5
  13. UNSUPPORTED_ELLIPTIC_CURVE = 6
  14. UNSUPPORTED_SERIALIZATION = 7
  15. UNSUPPORTED_X509 = 8
  16. UNSUPPORTED_EXCHANGE_ALGORITHM = 9
  17. UNSUPPORTED_DIFFIE_HELLMAN = 10
  18. UNSUPPORTED_MAC = 11
  19. class UnsupportedAlgorithm(Exception):
  20. def __init__(self, message, reason=None):
  21. super(UnsupportedAlgorithm, self).__init__(message)
  22. self._reason = reason
  23. class AlreadyFinalized(Exception):
  24. pass
  25. class AlreadyUpdated(Exception):
  26. pass
  27. class NotYetFinalized(Exception):
  28. pass
  29. class InvalidTag(Exception):
  30. pass
  31. class InvalidSignature(Exception):
  32. pass
  33. class InternalError(Exception):
  34. def __init__(self, msg, err_code):
  35. super(InternalError, self).__init__(msg)
  36. self.err_code = err_code
  37. class InvalidKey(Exception):
  38. pass