x509.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 datetime
  5. import warnings
  6. from cryptography import utils, x509
  7. # This exists for pyOpenSSL compatibility and SHOULD NOT BE USED
  8. # WE WILL REMOVE THIS VERY SOON.
  9. def _Certificate(backend, x509) -> x509.Certificate: # noqa: N802
  10. warnings.warn(
  11. "This version of cryptography contains a temporary pyOpenSSL "
  12. "fallback path. Upgrade pyOpenSSL now.",
  13. utils.DeprecatedIn35,
  14. )
  15. return backend._ossl2cert(x509)
  16. # This exists for pyOpenSSL compatibility and SHOULD NOT BE USED
  17. # WE WILL REMOVE THIS VERY SOON.
  18. def _CertificateSigningRequest( # noqa: N802
  19. backend, x509_req
  20. ) -> x509.CertificateSigningRequest:
  21. warnings.warn(
  22. "This version of cryptography contains a temporary pyOpenSSL "
  23. "fallback path. Upgrade pyOpenSSL now.",
  24. utils.DeprecatedIn35,
  25. )
  26. return backend._ossl2csr(x509_req)
  27. # This exists for pyOpenSSL compatibility and SHOULD NOT BE USED
  28. # WE WILL REMOVE THIS VERY SOON.
  29. def _CertificateRevocationList( # noqa: N802
  30. backend, x509_crl
  31. ) -> x509.CertificateRevocationList:
  32. warnings.warn(
  33. "This version of cryptography contains a temporary pyOpenSSL "
  34. "fallback path. Upgrade pyOpenSSL now.",
  35. utils.DeprecatedIn35,
  36. )
  37. return backend._ossl2crl(x509_crl)
  38. class _RawRevokedCertificate(x509.RevokedCertificate):
  39. def __init__(
  40. self,
  41. serial_number: int,
  42. revocation_date: datetime.datetime,
  43. extensions: x509.Extensions,
  44. ):
  45. self._serial_number = serial_number
  46. self._revocation_date = revocation_date
  47. self._extensions = extensions
  48. @property
  49. def serial_number(self) -> int:
  50. return self._serial_number
  51. @property
  52. def revocation_date(self) -> datetime.datetime:
  53. return self._revocation_date
  54. @property
  55. def extensions(self) -> x509.Extensions:
  56. return self._extensions