test_rfc8494.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 rfc8494
  13. class CompresssedDataTestCase(unittest.TestCase):
  14. pem_text = """\
  15. MIIBNqADAgEAMIIBLaADAgEZoIIBJASCASB4nG2P0U7CQBBF3/cr5l2K3YpSF5YA
  16. bYmbWArtQsJjKVuogd1mO0T8e0ti1IjJZB4md07OHZbWnMbqkp/qo+oW5jSCWDqL
  17. VCSpkBveg2kSbrg/FTIWcQRpJPlLmGYQzdci5MvlA+3Rx2cyREO/KVrhCOaJFLMN
  18. n03E6yqNIEmDheS2LHzPG0zNdqw0dn89XAnev4RsFQRRlnW+SITMWmMGf72JNAyk
  19. oXCj0mnPHtzwSZijYuD1YVJb8FzaB/rE2n3nUtcl2Xn7pgpkkAOqBsm1vrNWtqmM
  20. ZkC7LgmMxraFgx91y0F1wfv6mFd6AMUht41CfsbS8X9yNtdNqayjdGF2ld4z8LcV
  21. EiIPVQPtvBuLBxjW5qx3TbXXo6vHJ1OhhLY=
  22. """
  23. def setUp(self):
  24. self.asn1Spec = rfc8494.CompressedData()
  25. def testDerCodec(self):
  26. substrate = pem.readBase64fromText(self.pem_text)
  27. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  28. self.assertFalse(rest)
  29. self.assertTrue(asn1Object.prettyPrint())
  30. self.assertEqual(substrate, der_encoder(asn1Object))
  31. self.assertEqual(
  32. 0, asn1Object['compressionAlgorithm']['algorithmID-ShortForm'])
  33. cci = asn1Object['compressedContentInfo']
  34. self.assertEqual(
  35. 25, cci['unnamed']['contentType-ShortForm'])
  36. self.assertEqual(
  37. '0x789c6d8fd1', cci['compressedContent'].prettyPrint()[:12])
  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())