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 9import sys 10 11from pyasn1.codec.der.decoder import decode as der_decode 12from pyasn1.codec.der.encoder import encode as der_encode 13 14from pyasn1_modules import pem 15from pyasn1_modules import rfc3161 16 17try: 18 import unittest2 as unittest 19except ImportError: 20 import unittest 21 22 23class TSPQueryTestCase(unittest.TestCase): 24 tsp_query_pem_text = """\ 25MFYCAQEwUTANBglghkgBZQMEAgMFAARAGu1DauxDZZv8F7l4EKIbS00U40mUKfBW5C0giEz0 26t1zOHCvK4A8i8zxwUXFHv4pAJZE+uFhZ+v53HTg9rLjO5Q== 27""" 28 29 def setUp(self): 30 self.asn1Spec = rfc3161.TimeStampReq() 31 32 def testDerCodec(self): 33 substrate = pem.readBase64fromText(self.tsp_query_pem_text) 34 asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) 35 assert not rest 36 assert asn1Object.prettyPrint() 37 assert der_encode(asn1Object) == substrate 38 39 40class TSPResponseTestCase(unittest.TestCase): 41 tsp_response_pem_text = """\ 42MIIFMTADAgEAMIIFKAYJKoZIhvcNAQcCoIIFGTCCBRUCAQMxCzAJBgUrDgMCGgUAMIIBowYL 43KoZIhvcNAQkQAQSgggGSBIIBjjCCAYoCAQEGBCoDBAEwUTANBglghkgBZQMEAgMFAARAGu1D 44auxDZZv8F7l4EKIbS00U40mUKfBW5C0giEz0t1zOHCvK4A8i8zxwUXFHv4pAJZE+uFhZ+v53 45HTg9rLjO5QIDDwJEGA8yMDE5MDUxMDE4MzQxOFoBAf+gggERpIIBDTCCAQkxETAPBgNVBAoT 46CEZyZWUgVFNBMQwwCgYDVQQLEwNUU0ExdjB0BgNVBA0TbVRoaXMgY2VydGlmaWNhdGUgZGln 47aXRhbGx5IHNpZ25zIGRvY3VtZW50cyBhbmQgdGltZSBzdGFtcCByZXF1ZXN0cyBtYWRlIHVz 48aW5nIHRoZ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UboZtOUmNj10IJPUNyKQ5JPwCe6HEhbeXLRdh/8 63bjdqy56hBHyG1NRBqiTXTvj9LOzsJGIF5GjwyCT0B2hpvzdTdzNtfQ27HUUYgnYg0fGEpNpi 64vyaW5qCh9S704IKB0m/fXlqiIfNVdqDr/aAHNww8CouZP2oFO61WXCspbFNPLubeqxd5P4o4 65dJzD4PKsurILdX7SL8pRI+O2UtJLwNB1t3LBLKfTZuOWoSBFvQwbqBsDEchrZIDZXSXMbXd6 66uuvuO3ZsRWuej+gso+nWi3CRnRc9Wb0++cq4s8YSLaYSj2pHMA== 67""" 68 69 def setUp(self): 70 self.asn1Spec = rfc3161.TimeStampResp() 71 72 def testDerCodec(self): 73 substrate = pem.readBase64fromText(self.tsp_response_pem_text) 74 asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) 75 assert not rest 76 assert asn1Object.prettyPrint() 77 assert der_encode(asn1Object) == substrate 78 79 80suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 81 82if __name__ == '__main__': 83 import sys 84 85 result = unittest.TextTestRunner(verbosity=2).run(suite) 86 sys.exit(not result.wasSuccessful()) 87