base.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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._types import (
  6. _PRIVATE_KEY_TYPES,
  7. _PUBLIC_KEY_TYPES,
  8. )
  9. from cryptography.hazmat.backends import _get_backend
  10. from cryptography.hazmat.primitives.asymmetric import dh
  11. def load_pem_private_key(
  12. data: bytes, password: typing.Optional[bytes], backend=None
  13. ) -> _PRIVATE_KEY_TYPES:
  14. backend = _get_backend(backend)
  15. return backend.load_pem_private_key(data, password)
  16. def load_pem_public_key(data: bytes, backend=None) -> _PUBLIC_KEY_TYPES:
  17. backend = _get_backend(backend)
  18. return backend.load_pem_public_key(data)
  19. def load_pem_parameters(data: bytes, backend=None) -> "dh.DHParameters":
  20. backend = _get_backend(backend)
  21. return backend.load_pem_parameters(data)
  22. def load_der_private_key(
  23. data: bytes, password: typing.Optional[bytes], backend=None
  24. ) -> _PRIVATE_KEY_TYPES:
  25. backend = _get_backend(backend)
  26. return backend.load_der_private_key(data, password)
  27. def load_der_public_key(data: bytes, backend=None) -> _PUBLIC_KEY_TYPES:
  28. backend = _get_backend(backend)
  29. return backend.load_der_public_key(data)
  30. def load_der_parameters(data: bytes, backend=None) -> "dh.DHParameters":
  31. backend = _get_backend(backend)
  32. return backend.load_der_parameters(data)