test_rfc2511.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
  5. # License: http://snmplabs.com/pyasn1/license.html
  6. #
  7. import sys
  8. import unittest
  9. from pyasn1.codec.der.decoder import decode as der_decoder
  10. from pyasn1.codec.der.encoder import encode as der_encoder
  11. from pyasn1_modules import pem
  12. from pyasn1_modules import rfc2511
  13. class CertificateReqTestCase(unittest.TestCase):
  14. pem_text = """\
  15. MIIBozCCAZ8wggEFAgUAwTnj2jCByoABAqURMA8xDTALBgNVBAMTBHVzZXKmgZ8w
  16. DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJ6ZQ2cYbn/lFsmBOlRltbRbFQUvvE0Q
  17. nbopOu1kC7Bmaaz7QTx8nxeiHi4m7uxCbGGxHNoGCt7EmdG8eZUBNAcHyGlXrJdm
  18. 0z3/uNEGiBHq+xB8FnFJCA5EIJ3RWFnlbu9otSITLxWK7c5+/NHmWM+yaeHD/f/h
  19. rp01c/8qXZfZAgMBAAGpEDAOBgNVHQ8BAf8EBAMCBeAwLzASBgkrBgEFBQcFAQEM
  20. BTExMTExMBkGCSsGAQUFBwUBAgwMc2VydmVyX21hZ2ljoYGTMA0GCSqGSIb3DQEB
  21. BQUAA4GBAEI3KNEvTq/n1kNVhNhPkovk1AZxyJrN1u1+7Gkc4PLjWwjLOjcEVWt4
  22. AajUk/gkIJ6bbeO+fZlMjHfPSDKcD6AV2hN+n72QZwfzcw3icNvBG1el9EU4XfIm
  23. xfu5YVWi81/fw8QQ6X6YGHFQkomLd7jxakVyjxSng9BhO6GpjJNF
  24. """
  25. def setUp(self):
  26. self.asn1Spec = rfc2511.CertReqMessages()
  27. def testDerCodec(self):
  28. substrate = pem.readBase64fromText(self.pem_text)
  29. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  30. self.assertFalse(rest)
  31. self.assertTrue(asn1Object.prettyPrint())
  32. self.assertEqual(substrate, der_encoder(asn1Object))
  33. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  34. if __name__ == '__main__':
  35. result = unittest.TextTestRunner(verbosity=2).run(suite)
  36. sys.exit(not result.wasSuccessful())