test_rfc2631.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Created by Russ Housley
  5. # Copyright (c) 2019, Vigil Security, LLC
  6. # License: http://snmplabs.com/pyasn1/license.html
  7. #
  8. import sys
  9. import unittest
  10. from pyasn1.codec.der.decoder import decode as der_decoder
  11. from pyasn1.codec.der.encoder import encode as der_encoder
  12. from pyasn1.type import univ
  13. from pyasn1_modules import pem
  14. from pyasn1_modules import rfc2631
  15. class OtherInfoTestCase(unittest.TestCase):
  16. pem_text = "MB0wEwYLKoZIhvcNAQkQAwYEBAAAAAGiBgQEAAAAwA=="
  17. def setUp(self):
  18. self.asn1Spec = rfc2631.OtherInfo()
  19. def testDerCodec(self):
  20. substrate = pem.readBase64fromText(self.pem_text)
  21. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  22. self.assertFalse(rest)
  23. self.assertTrue(asn1Object.prettyPrint())
  24. self.assertEqual(substrate, der_encoder(asn1Object))
  25. hex1 = univ.OctetString(hexValue='00000001')
  26. self.assertEqual(hex1, asn1Object['keyInfo']['counter'])
  27. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  28. if __name__ == '__main__':
  29. result = unittest.TextTestRunner(verbosity=2).run(suite)
  30. sys.exit(not result.wasSuccessful())