base.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.hazmat.primitives.asymmetric import dh
  6. from cryptography.hazmat.primitives.asymmetric.types import (
  7. PRIVATE_KEY_TYPES,
  8. PUBLIC_KEY_TYPES,
  9. )
  10. def load_pem_private_key(
  11. data: bytes,
  12. password: typing.Optional[bytes],
  13. backend: typing.Any = None,
  14. ) -> PRIVATE_KEY_TYPES:
  15. from cryptography.hazmat.backends.openssl.backend import backend as ossl
  16. return ossl.load_pem_private_key(data, password)
  17. def load_pem_public_key(
  18. data: bytes, backend: typing.Any = None
  19. ) -> PUBLIC_KEY_TYPES:
  20. from cryptography.hazmat.backends.openssl.backend import backend as ossl
  21. return ossl.load_pem_public_key(data)
  22. def load_pem_parameters(
  23. data: bytes, backend: typing.Any = None
  24. ) -> "dh.DHParameters":
  25. from cryptography.hazmat.backends.openssl.backend import backend as ossl
  26. return ossl.load_pem_parameters(data)
  27. def load_der_private_key(
  28. data: bytes,
  29. password: typing.Optional[bytes],
  30. backend: typing.Any = None,
  31. ) -> PRIVATE_KEY_TYPES:
  32. from cryptography.hazmat.backends.openssl.backend import backend as ossl
  33. return ossl.load_der_private_key(data, password)
  34. def load_der_public_key(
  35. data: bytes, backend: typing.Any = None
  36. ) -> PUBLIC_KEY_TYPES:
  37. from cryptography.hazmat.backends.openssl.backend import backend as ossl
  38. return ossl.load_der_public_key(data)
  39. def load_der_parameters(
  40. data: bytes, backend: typing.Any = None
  41. ) -> "dh.DHParameters":
  42. from cryptography.hazmat.backends.openssl.backend import backend as ossl
  43. return ossl.load_der_parameters(data)