exceptions.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 annotations
  5. import typing
  6. from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions
  7. if typing.TYPE_CHECKING:
  8. from cryptography.hazmat.bindings._rust import openssl as rust_openssl
  9. _Reasons = rust_exceptions._Reasons
  10. class UnsupportedAlgorithm(Exception):
  11. def __init__(self, message: str, reason: _Reasons | None = None) -> None:
  12. super().__init__(message)
  13. self._reason = reason
  14. class AlreadyFinalized(Exception):
  15. pass
  16. class AlreadyUpdated(Exception):
  17. pass
  18. class NotYetFinalized(Exception):
  19. pass
  20. class InvalidTag(Exception):
  21. pass
  22. class InvalidSignature(Exception):
  23. pass
  24. class InternalError(Exception):
  25. def __init__(
  26. self, msg: str, err_code: list[rust_openssl.OpenSSLError]
  27. ) -> None:
  28. super().__init__(msg)
  29. self.err_code = err_code
  30. class InvalidKey(Exception):
  31. pass