test_rfc2437.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 rfc2437
  13. class RSAPrivateKeyTestCase(unittest.TestCase):
  14. pem_text = """\
  15. MIIBPAIBAAJBAMfAjvBNDDYBCl1w3yNcagZkPhqd0q5KqeOTgKSLuJWfe5+VSeR5
  16. Y1PcF3DyH8dvS3t8PIQjxJLoKS7HVRlsfhECAwEAAQJBAIr93/gxhIenXbD7MykF
  17. yvi7k8MtgkWoymICZwcX+c6RudFyuPPfQJ/sf6RmFZlRA9X9CQm5NwVG7+x1Yi6t
  18. KoECIQDmJUCWkPCiQYow6YxetpXFa0K6hTzOPmax7MNHVWNgmQIhAN4xOZ4JFT34
  19. xVhK+8EudBCYRomJUHmOJfoQAxiIXVw5AiEAyB7ecc5on/5zhqKef4Eu7LKfHIdc
  20. 304diFuDVpTmTAkCIC2ZmKOQZaWkSowGR4isCfHl7oQHhFaOD8k0RA5i3hYxAiEA
  21. n8lDw3JT6NjvMnD6aM8KBsLyhazWSVVkaUSqmJzgCF0=
  22. """
  23. def setUp(self):
  24. self.asn1Spec = rfc2437.RSAPrivateKey()
  25. def testDerCodec(self):
  26. substrate = pem.readBase64fromText(self.pem_text)
  27. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  28. self.assertFalse(rest)
  29. self.assertTrue(asn1Object.prettyPrint())
  30. self.assertEqual(substrate, der_encoder(asn1Object))
  31. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  32. if __name__ == '__main__':
  33. result = unittest.TextTestRunner(verbosity=2).run(suite)
  34. sys.exit(not result.wasSuccessful())