1# 2# This file is part of pyasn1-modules software. 3# 4# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com> 5# License: http://pyasn1.sf.net/license.html 6# 7import sys 8 9from pyasn1.codec.der import decoder as der_decoder 10from pyasn1.codec.der import encoder as der_encoder 11 12from pyasn1_modules import pem 13from pyasn1_modules import rfc2511 14 15try: 16 import unittest2 as unittest 17 18except ImportError: 19 import unittest 20 21 22class CertificateReqTestCase(unittest.TestCase): 23 pem_text = """\ 24MIIBozCCAZ8wggEFAgUAwTnj2jCByoABAqURMA8xDTALBgNVBAMTBHVzZXKmgZ8w 25DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJ6ZQ2cYbn/lFsmBOlRltbRbFQUvvE0Q 26nbopOu1kC7Bmaaz7QTx8nxeiHi4m7uxCbGGxHNoGCt7EmdG8eZUBNAcHyGlXrJdm 270z3/uNEGiBHq+xB8FnFJCA5EIJ3RWFnlbu9otSITLxWK7c5+/NHmWM+yaeHD/f/h 28rp01c/8qXZfZAgMBAAGpEDAOBgNVHQ8BAf8EBAMCBeAwLzASBgkrBgEFBQcFAQEM 29BTExMTExMBkGCSsGAQUFBwUBAgwMc2VydmVyX21hZ2ljoYGTMA0GCSqGSIb3DQEB 30BQUAA4GBAEI3KNEvTq/n1kNVhNhPkovk1AZxyJrN1u1+7Gkc4PLjWwjLOjcEVWt4 31AajUk/gkIJ6bbeO+fZlMjHfPSDKcD6AV2hN+n72QZwfzcw3icNvBG1el9EU4XfIm 32xfu5YVWi81/fw8QQ6X6YGHFQkomLd7jxakVyjxSng9BhO6GpjJNF 33""" 34 35 def setUp(self): 36 self.asn1Spec = rfc2511.CertReqMessages() 37 38 def testDerCodec(self): 39 40 substrate = pem.readBase64fromText(self.pem_text) 41 42 asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) 43 44 assert not rest 45 assert asn1Object.prettyPrint() 46 assert der_encoder.encode(asn1Object) == substrate 47 48 49suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 50 51if __name__ == '__main__': 52 unittest.TextTestRunner(verbosity=2).run(suite) 53