• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# This file is part of pyasn1-modules software.
3#
4# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
5# License: http://pyasn1.sf.net/license.html
6#
7import sys
8
9from pyasn1.codec.der import decoder as der_decoder
10from pyasn1.codec.der import encoder as der_encoder
11
12from pyasn1_modules import pem
13from pyasn1_modules import rfc2560
14
15try:
16    import unittest2 as unittest
17
18except ImportError:
19    import unittest
20
21
22class OCSPRequestTestCase(unittest.TestCase):
23    pem_text = """\
24MGowaDBBMD8wPTAJBgUrDgMCGgUABBS3ZrMV9C5Dko03aH13cEZeppg3wgQUkqR1LKSevoFE63n8
25isWVpesQdXMCBDXe9M+iIzAhMB8GCSsGAQUFBzABAgQSBBBjdJOiIW9EKJGELNNf/rdA
26"""
27
28    def setUp(self):
29        self.asn1Spec = rfc2560.OCSPRequest()
30
31    def testDerCodec(self):
32
33        substrate = pem.readBase64fromText(self.pem_text)
34
35        asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
36
37        assert not rest
38        assert asn1Object.prettyPrint()
39        assert der_encoder.encode(asn1Object) == substrate
40
41
42class OCSPResponseTestCase(unittest.TestCase):
43    pem_text = """\
44MIIEvQoBAKCCBLYwggSyBgkrBgEFBQcwAQEEggSjMIIEnzCCAQ+hgYAwfjELMAkGA1UEBhMCQVUx
45EzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEV
46MBMGA1UEAxMMc25tcGxhYnMuY29tMSAwHgYJKoZIhvcNAQkBFhFpbmZvQHNubXBsYWJzLmNvbRgP
47MjAxMjA0MTExNDA5MjJaMFQwUjA9MAkGBSsOAwIaBQAEFLdmsxX0LkOSjTdofXdwRl6mmDfCBBSS
48pHUspJ6+gUTrefyKxZWl6xB1cwIENd70z4IAGA8yMDEyMDQxMTE0MDkyMlqhIzAhMB8GCSsGAQUF
49BzABAgQSBBBjd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qnEcYwDQYJKoZIhvcNAQEF
63BQADgYEAWR0uFJVlQId6hVpUbgXFTpywtNitNXFiYYkRRv77McSJqLCa/c1wnuLmqcFcuRUK0oN6
648ZJDP2HDDKe8MCZ8+sx+CF54eM8VCgN9uQ9XyE7x9XrXDd3Uw9RJVaWSIezkNKNeBE0lDM2jUjC4
65HAESdf7nebz1wtqAOXE1jWF/y8g=
66"""
67
68    def setUp(self):
69        self.asn1Spec = rfc2560.OCSPResponse()
70
71    def testDerCodec(self):
72        substrate = pem.readBase64fromText(self.pem_text)
73
74        asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
75
76        assert not rest
77        assert asn1Object.prettyPrint()
78        assert der_encoder.encode(asn1Object) == substrate
79
80
81suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
82
83if __name__ == '__main__':
84    unittest.TextTestRunner(verbosity=2).run(suite)
85