test_rfc5208.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 rfc5208
  13. class PrivateKeyInfoTestCase(unittest.TestCase):
  14. pem_text = """\
  15. MIIBVgIBADANBgkqhkiG9w0BAQEFAASCAUAwggE8AgEAAkEAx8CO8E0MNgEKXXDf
  16. I1xqBmQ+Gp3Srkqp45OApIu4lZ97n5VJ5HljU9wXcPIfx29Le3w8hCPEkugpLsdV
  17. GWx+EQIDAQABAkEAiv3f+DGEh6ddsPszKQXK+LuTwy2CRajKYgJnBxf5zpG50XK4
  18. 899An+x/pGYVmVED1f0JCbk3BUbv7HViLq0qgQIhAOYlQJaQ8KJBijDpjF62lcVr
  19. QrqFPM4+ZrHsw0dVY2CZAiEA3jE5ngkVPfjFWEr7wS50EJhGiYlQeY4l+hADGIhd
  20. XDkCIQDIHt5xzmif/nOGop5/gS7ssp8ch1zfTh2IW4NWlOZMCQIgLZmYo5BlpaRK
  21. jAZHiKwJ8eXuhAeEVo4PyTREDmLeFjECIQCfyUPDclPo2O8ycPpozwoGwvKFrNZJ
  22. VWRpRKqYnOAIXQ==
  23. """
  24. def setUp(self):
  25. self.asn1Spec = rfc5208.PrivateKeyInfo()
  26. def testDerCodec(self):
  27. substrate = pem.readBase64fromText(self.pem_text)
  28. asn1Object, rest = der_decoder.decode(
  29. substrate, asn1Spec=self.asn1Spec)
  30. self.assertFalse(rest)
  31. self.assertTrue(asn1Object.prettyPrint())
  32. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  33. class EncryptedPrivateKeyInfoInfoTestCase(unittest.TestCase):
  34. pem_text = """\
  35. MIIBgTAbBgkqhkiG9w0BBQMwDgQIdtFgDWnipT8CAggABIIBYN0hkm2xqkTCt8dJ
  36. iZS8+HNiyHxy8g+rmWSXv/i+bTHFUReZA2GINtTRUkWpXqWcSHxNslgf7QdfgbVJ
  37. xQiUM+lLhwOFh85iAHR3xmPU1wfN9NvY9DiLSpM0DMhF3OvAMZD75zIhA0GSKu7w
  38. dUu7ey7H4fv7bez6RhEyLdKw9/Lf2KNStNOs4ow9CAtCoxeoMSniTt6CNhbvCkve
  39. 9vNHKiGavX1tS/YTog4wiiGzh2YxuW1RiQpTdhWiKyECgD8qQVg2tY5t3QRcXrzi
  40. OkStpkiAPAbiwS/gyHpsqiLo0al63SCxRefugbn1ucZyc5Ya59e3xNFQXCNhYl+Z
  41. Hl3hIl3cssdWZkJ455Z/bBE29ks1HtsL+bTfFi+kw/4yuMzoaB8C7rXScpGNI/8E
  42. pvTU2+wtuoOFcttJregtR94ZHu5wgdYqRydmFNG8PnvZT1mRMmQgUe/vp88FMmsZ
  43. dLsZjNQ=
  44. """
  45. def setUp(self):
  46. self.asn1Spec = rfc5208.EncryptedPrivateKeyInfo()
  47. def testDerCodec(self):
  48. substrate = pem.readBase64fromText(self.pem_text)
  49. asn1Object, rest = der_decoder.decode(
  50. substrate, asn1Spec=self.asn1Spec)
  51. self.assertFalse(rest)
  52. self.assertTrue(asn1Object.prettyPrint())
  53. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  54. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  55. if __name__ == '__main__':
  56. result = unittest.TextTestRunner(verbosity=2).run(suite)
  57. sys.exit(not result.wasSuccessful())