exceptions.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. import typing
  5. from cryptography import utils
  6. if typing.TYPE_CHECKING:
  7. from cryptography.hazmat.bindings.openssl.binding import (
  8. _OpenSSLErrorWithText,
  9. )
  10. class _Reasons(utils.Enum):
  11. BACKEND_MISSING_INTERFACE = 0
  12. UNSUPPORTED_HASH = 1
  13. UNSUPPORTED_CIPHER = 2
  14. UNSUPPORTED_PADDING = 3
  15. UNSUPPORTED_MGF = 4
  16. UNSUPPORTED_PUBLIC_KEY_ALGORITHM = 5
  17. UNSUPPORTED_ELLIPTIC_CURVE = 6
  18. UNSUPPORTED_SERIALIZATION = 7
  19. UNSUPPORTED_X509 = 8
  20. UNSUPPORTED_EXCHANGE_ALGORITHM = 9
  21. UNSUPPORTED_DIFFIE_HELLMAN = 10
  22. UNSUPPORTED_MAC = 11
  23. class UnsupportedAlgorithm(Exception):
  24. def __init__(
  25. self, message: str, reason: typing.Optional[_Reasons] = None
  26. ) -> None:
  27. super(UnsupportedAlgorithm, self).__init__(message)
  28. self._reason = reason
  29. class AlreadyFinalized(Exception):
  30. pass
  31. class AlreadyUpdated(Exception):
  32. pass
  33. class NotYetFinalized(Exception):
  34. pass
  35. class InvalidTag(Exception):
  36. pass
  37. class InvalidSignature(Exception):
  38. pass
  39. class InternalError(Exception):
  40. def __init__(
  41. self, msg: str, err_code: typing.List["_OpenSSLErrorWithText"]
  42. ) -> None:
  43. super(InternalError, self).__init__(msg)
  44. self.err_code = err_code
  45. class InvalidKey(Exception):
  46. pass