test_rfc6019.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Copyright (c) 2019, Vigil Security, LLC
  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 rfc5652
  13. from pyasn1_modules import rfc6019
  14. class BinarySigningTimeTestCase(unittest.TestCase):
  15. pem_text = "MBUGCyqGSIb3DQEJEAIuMQYCBFy/hlQ="
  16. def setUp(self):
  17. self.asn1Spec = rfc5652.Attribute()
  18. def testDerCodec(self):
  19. substrate = pem.readBase64fromText(self.pem_text)
  20. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  21. self.assertFalse(rest)
  22. self.assertTrue(asn1Object.prettyPrint())
  23. self.assertEqual(substrate, der_encoder(asn1Object))
  24. self.assertEqual(rfc6019.id_aa_binarySigningTime, asn1Object['attrType'])
  25. bintime, rest = der_decoder(
  26. asn1Object['attrValues'][0], asn1Spec=rfc6019.BinaryTime())
  27. self.assertEqual(0x5cbf8654, bintime)
  28. def testOpenTypes(self):
  29. substrate = pem.readBase64fromText(self.pem_text)
  30. asn1Object, rest = der_decoder(
  31. substrate, asn1Spec=self.asn1Spec,
  32. decodeOpenTypes=True)
  33. self.assertFalse(rest)
  34. self.assertTrue(asn1Object.prettyPrint())
  35. self.assertEqual(substrate, der_encoder(asn1Object))
  36. self.assertIn(asn1Object['attrType'], rfc5652.cmsAttributesMap)
  37. self.assertEqual(0x5cbf8654, asn1Object['attrValues'][0])
  38. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  39. if __name__ == '__main__':
  40. result = unittest.TextTestRunner(verbosity=2).run(suite)
  41. sys.exit(not result.wasSuccessful())