test_rfc4210.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 import decoder as der_decoder
  10. from pyasn1.codec.der import encoder as der_encoder
  11. from pyasn1_modules import pem
  12. from pyasn1_modules import rfc4210
  13. class PKIMessageTestCase(unittest.TestCase):
  14. pem_text = """\
  15. MIITuTCCARECAQKkWTBXMQswCQYDVQQGEwJUUjEQMA4GA1UEChMHRS1HdXZlbjEUMBIGA1UECxML
  16. VHJ1c3RDZW50ZXIxIDAeBgNVBAMTF1JTQSBTZWN1cml0eSBDTVAgU2VydmVypC0wKzELMAkGA1UE
  17. BhMCVFIxHDAaBgNVBAMME1ZhbGltby1WZXR0b3ItMTdEZWOgERgPMjAxMjA1MDMxMTE2MTdaoQ8w
  18. DQYJKoZIhvcNAQEFBQCiIgQgZWVhMjg5MGU2ZGY5N2IyNzk5NWY2MWE0MzE2MzI1OWGkEgQQQ01Q
  19. VjJUMTIyMzM0NjI3MKUSBBCAAAABgAAAAYAAAAGAAAABphIEEDEzNjY0NDMwMjlSYW5kb22jghIZ
  20. MIISFaGCC84wggvKMIIFwDCCBKigAwIBAgIQfOVE05R616R6Nqgu3drXHzANBgkqhkiG9w0BAQUF
  21. ADBxMQswCQYDVQQGEwJUUjEoMCYGA1UEChMfRWxla3Ryb25payBCaWxnaSBHdXZlbmxpZ2kgQS5T
  22. LjE4MDYGA1UEAxMvZS1HdXZlbiBFbGVrdHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2FnbGF5aWNp
  23. c2kwHhcNMDgxMTI0MTAwMzI0WhcNMTYxMjE0MTExNzI0WjBdMQswCQYDVQQGEwJUU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tQw==
  104. """
  105. def setUp(self):
  106. self.asn1Spec = rfc4210.PKIMessage()
  107. def testDerCodec(self):
  108. substrate = pem.readBase64fromText(self.pem_text)
  109. asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
  110. self.assertFalse(rest)
  111. self.assertTrue(asn1Object.prettyPrint())
  112. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  113. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  114. if __name__ == '__main__':
  115. result = unittest.TextTestRunner(verbosity=2).run(suite)
  116. sys.exit(not result.wasSuccessful())