_serialization.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 abc
  5. from cryptography import utils
  6. # This exists to break an import cycle. These classes are normally accessible
  7. # from the serialization module.
  8. class Encoding(utils.Enum):
  9. PEM = "PEM"
  10. DER = "DER"
  11. OpenSSH = "OpenSSH"
  12. Raw = "Raw"
  13. X962 = "ANSI X9.62"
  14. SMIME = "S/MIME"
  15. class PrivateFormat(utils.Enum):
  16. PKCS8 = "PKCS8"
  17. TraditionalOpenSSL = "TraditionalOpenSSL"
  18. Raw = "Raw"
  19. OpenSSH = "OpenSSH"
  20. class PublicFormat(utils.Enum):
  21. SubjectPublicKeyInfo = "X.509 subjectPublicKeyInfo with PKCS#1"
  22. PKCS1 = "Raw PKCS#1"
  23. OpenSSH = "OpenSSH"
  24. Raw = "Raw"
  25. CompressedPoint = "X9.62 Compressed Point"
  26. UncompressedPoint = "X9.62 Uncompressed Point"
  27. class ParameterFormat(utils.Enum):
  28. PKCS3 = "PKCS3"
  29. class KeySerializationEncryption(metaclass=abc.ABCMeta):
  30. pass
  31. class BestAvailableEncryption(KeySerializationEncryption):
  32. def __init__(self, password: bytes):
  33. if not isinstance(password, bytes) or len(password) == 0:
  34. raise ValueError("Password must be 1 or more bytes.")
  35. self.password = password
  36. class NoEncryption(KeySerializationEncryption):
  37. pass