• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#
7import sys
8
9from pyasn1.codec.der.decoder import decode as der_decode
10from pyasn1.codec.der.encoder import encode as der_encode
11
12from pyasn1_modules import pem
13from pyasn1_modules import rfc8494
14
15try:
16    import unittest2 as unittest
17except ImportError:
18    import unittest
19
20
21class CompresssedDataTestCase(unittest.TestCase):
22    pem_text = """\
23MIIBNqADAgEAMIIBLaADAgEZoIIBJASCASB4nG2P0U7CQBBF3/cr5l2K3YpSF5YA
24bYmbWArtQsJjKVuogd1mO0T8e0ti1IjJZB4md07OHZbWnMbqkp/qo+oW5jSCWDqL
25VCSpkBveg2kSbrg/FTIWcQRpJPlLmGYQzdci5MvlA+3Rx2cyREO/KVrhCOaJFLMN
26n03E6yqNIEmDheS2LHzPG0zNdqw0dn89XAnev4RsFQRRlnW+SITMWmMGf72JNAyk
27oXCj0mnPHtzwSZijYuD1YVJb8FzaB/rE2n3nUtcl2Xn7pgpkkAOqBsm1vrNWtqmM
28ZkC7LgmMxraFgx91y0F1wfv6mFd6AMUht41CfsbS8X9yNtdNqayjdGF2ld4z8LcV
29EiIPVQPtvBuLBxjW5qx3TbXXo6vHJ1OhhLY=
30
31"""
32
33    def setUp(self):
34        self.asn1Spec = rfc8494.CompressedData()
35
36    def testDerCodec(self):
37        substrate = pem.readBase64fromText(self.pem_text)
38        asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec)
39        assert not rest
40        assert asn1Object.prettyPrint()
41        assert der_encode(asn1Object) == substrate
42
43        assert asn1Object['compressionAlgorithm']['algorithmID-ShortForm'] == 0
44        cci = asn1Object['compressedContentInfo']
45        assert cci['unnamed']['contentType-ShortForm'] == 25
46        assert cci['compressedContent'].prettyPrint()[:12] == '0x789c6d8fd1'
47
48
49suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
50
51if __name__ == '__main__':
52    import sys
53
54    result = unittest.TextTestRunner(verbosity=2).run(suite)
55    sys.exit(not result.wasSuccessful())
56