1# 2# This file is part of pyasn1-modules software. 3# 4# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> 5# License: http://snmplabs.com/pyasn1/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 rfc2437 14 15try: 16 import unittest2 as unittest 17 18except ImportError: 19 import unittest 20 21 22class RSAPrivateKeyTestCase(unittest.TestCase): 23 pem_text = """\ 24MIIBPAIBAAJBAMfAjvBNDDYBCl1w3yNcagZkPhqd0q5KqeOTgKSLuJWfe5+VSeR5 25Y1PcF3DyH8dvS3t8PIQjxJLoKS7HVRlsfhECAwEAAQJBAIr93/gxhIenXbD7MykF 26yvi7k8MtgkWoymICZwcX+c6RudFyuPPfQJ/sf6RmFZlRA9X9CQm5NwVG7+x1Yi6t 27KoECIQDmJUCWkPCiQYow6YxetpXFa0K6hTzOPmax7MNHVWNgmQIhAN4xOZ4JFT34 28xVhK+8EudBCYRomJUHmOJfoQAxiIXVw5AiEAyB7ecc5on/5zhqKef4Eu7LKfHIdc 29304diFuDVpTmTAkCIC2ZmKOQZaWkSowGR4isCfHl7oQHhFaOD8k0RA5i3hYxAiEA 30n8lDw3JT6NjvMnD6aM8KBsLyhazWSVVkaUSqmJzgCF0= 31""" 32 33 def setUp(self): 34 self.asn1Spec = rfc2437.RSAPrivateKey() 35 36 def testDerCodec(self): 37 38 substrate = pem.readBase64fromText(self.pem_text) 39 40 asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) 41 42 assert not rest 43 assert asn1Object.prettyPrint() 44 assert der_encoder.encode(asn1Object) == substrate 45 46 47suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 48 49if __name__ == '__main__': 50 import sys 51 52 result = unittest.TextTestRunner(verbosity=2).run(suite) 53 sys.exit(not result.wasSuccessful()) 54