test_rfc3161.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_modules import pem
  13. from pyasn1_modules import rfc3161
  14. class TSPQueryTestCase(unittest.TestCase):
  15. tsp_query_pem_text = """\
  16. MFYCAQEwUTANBglghkgBZQMEAgMFAARAGu1DauxDZZv8F7l4EKIbS00U40mUKfBW5C0giEz0
  17. t1zOHCvK4A8i8zxwUXFHv4pAJZE+uFhZ+v53HTg9rLjO5Q==
  18. """
  19. def setUp(self):
  20. self.asn1Spec = rfc3161.TimeStampReq()
  21. def testDerCodec(self):
  22. substrate = pem.readBase64fromText(self.tsp_query_pem_text)
  23. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  24. self.assertFalse(rest)
  25. self.assertTrue(asn1Object.prettyPrint())
  26. self.assertEqual(substrate, der_encoder(asn1Object))
  27. class TSPResponseTestCase(unittest.TestCase):
  28. tsp_response_pem_text = """\
  29. MIIFMTADAgEAMIIFKAYJKoZIhvcNAQcCoIIFGTCCBRUCAQMxCzAJBgUrDgMCGgUAMIIBowYL
  30. KoZIhvcNAQkQAQSgggGSBIIBjjCCAYoCAQEGBCoDBAEwUTANBglghkgBZQMEAgMFAARAGu1D
  31. auxDZZv8F7l4EKIbS00U40mUKfBW5C0giEz0t1zOHCvK4A8i8zxwUXFHv4pAJZE+uFhZ+v53
  32. HTg9rLjO5QIDDwJEGA8yMDE5MDUxMDE4MzQxOFoBAf+gggERpIIBDTCCAQkxETAPBgNVBAoT
  33. CEZyZWUgVFNBMQwwCgYDVQQLEwNUU0ExdjB0BgNVBA0TbVRoaXMgY2V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eDBQMhTUeZoA59/OxgnQR1Zpca4
  48. ZuWuqnZImxziRQA1tX/6pjAo5eP1V+SLWYHeIO7ia/urGIK9AXd3jY3Ljq4h7R1E+RRKIseO
  49. 74mmtbJtCaiGL9H+6k164qC7U5fHBzKl3UboZtOUmNj10IJPUNyKQ5JPwCe6HEhbeXLRdh/8
  50. bjdqy56hBHyG1NRBqiTXTvj9LOzsJGIF5GjwyCT0B2hpvzdTdzNtfQ27HUUYgnYg0fGEpNpi
  51. vyaW5qCh9S704IKB0m/fXlqiIfNVdqDr/aAHNww8CouZP2oFO61WXCspbFNPLubeqxd5P4o4
  52. dJzD4PKsurILdX7SL8pRI+O2UtJLwNB1t3LBLKfTZuOWoSBFvQwbqBsDEchrZIDZXSXMbXd6
  53. uuvuO3ZsRWuej+gso+nWi3CRnRc9Wb0++cq4s8YSLaYSj2pHMA==
  54. """
  55. def setUp(self):
  56. self.asn1Spec = rfc3161.TimeStampResp()
  57. def testDerCodec(self):
  58. substrate = pem.readBase64fromText(self.tsp_response_pem_text)
  59. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  60. self.assertFalse(rest)
  61. self.assertTrue(asn1Object.prettyPrint())
  62. self.assertEqual(substrate, der_encoder(asn1Object))
  63. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  64. if __name__ == '__main__':
  65. result = unittest.TextTestRunner(verbosity=2).run(suite)
  66. sys.exit(not result.wasSuccessful())