rfc5208.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #
  2. # PKCS#8 syntax
  3. #
  4. # ASN.1 source from:
  5. # http://tools.ietf.org/html/rfc5208
  6. #
  7. # Sample captures could be obtained with "openssl pkcs8 -topk8" command
  8. #
  9. from pyasn1.type import tag, namedtype, namedval, univ, constraint
  10. from pyasn1_modules.rfc2459 import *
  11. from pyasn1_modules import rfc2251
  12. class KeyEncryptionAlgorithms(AlgorithmIdentifier): pass
  13. class PrivateKeyAlgorithms(AlgorithmIdentifier): pass
  14. class EncryptedData(univ.OctetString): pass
  15. class EncryptedPrivateKeyInfo(univ.Sequence):
  16. componentType = namedtype.NamedTypes(
  17. namedtype.NamedType('encryptionAlgorithm', AlgorithmIdentifier()),
  18. namedtype.NamedType('encryptedData', EncryptedData())
  19. )
  20. class PrivateKey(univ.OctetString): pass
  21. class Attributes(univ.SetOf):
  22. componentType = rfc2251.Attribute()
  23. class Version(univ.Integer):
  24. namedValues = namedval.NamedValues(('v1', 0), ('v2', 1))
  25. class PrivateKeyInfo(univ.Sequence):
  26. componentType = namedtype.NamedTypes(
  27. namedtype.NamedType('version', Version()),
  28. namedtype.NamedType('privateKeyAlgorithm', AlgorithmIdentifier()),
  29. namedtype.NamedType('privateKey', PrivateKey()),
  30. namedtype.OptionalNamedType('attributes', Attributes().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)))
  31. )