test_rfc5914.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 rfc5914
  14. from pyasn1_modules import rfc5652
  15. class TrustAnchorListTestCase(unittest.TestCase):
  16. trust_anchor_list_pem_text = """\
  17. MIIGGQYLKoZIhvcNAQkQASKgggYIMIIGBKGCAvYwggLyoAMCAQICAgDJMA0GCSqG
  18. SIb3DQEBCwUAMBYxFDASBgNVBAMTC3JpcGUtbmNjLXRhMCAXDTE3MTEyODE0Mzk1
  19. NVoYDzIxMTcxMTI4MTQzOTU1WjAWMRQwEgYDVQQDEwtyaXBlLW5jYy10YTCCASIw
  20. DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANFEWEhqlM9psgbDs3ltY0OjbMTb
  21. 5SzMoVpJ755fDYgQrP0/0tl7jSkDWfsAWcSIDz1dqRQRXkAL6B/1ivNx8ANuldrI
  22. sJvzGNpymfjpcPsJac5WdadyKY9njXCq5orfAcAQvMSJs7ghmldI5EQdBmdIaB+j
  23. JdN7pi6a0bJ+r9MTj9PpekHNWRzBVRW9/OSEOxUEE3FSMa3XjLKMiavXjJBOg6HJ
  24. R4RfzZUpZV7mwEkPSlFqidPjrd0Al6+C1xAjH5KZFUdk2U/r+b+ufGx1bOmcUQ9W
  25. +lJNbkCgMh1G5/7V7z/Ja4wImxs1bFw09i9MeBHcfkHYsT4Do4t4ATMi9lcCAwEA
  26. AaOCAV4wggFaMB0GA1UdDgQWBBToVSsf1tGk9+QExtjlaA0evBY/wzAPBgNVHRMB
  27. Af8EBTADAQH/MA4GA1UdDwEB/w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
  43. bZsnLVvmAjEAt/ypozbUhQw4dSPpWzrn5BQ0kKbDM3DQJcBABEUBoIOol1/jYQPm
  44. xajQuxcheFlkooIBADCB/TB2MBAGByqGSM49AgEGBSuBBAAiA2IABOIIQup32CTe
  45. oCxkpBPOQJwjcqkCCg43PyE2uI1TFPbVkZVL85YCjXEexNjLp59e76Dmf1qSEZZT
  46. b+vAyz+u/Vs/RyTnmgculr6oL7tXGK9xpL14Oh7oWzxrZBErzDQrjAQUo53mH/na
  47. OU/AbuiRy5Wl2jHiCp8MFURpZ2lDZXJ0IFRydXN0IEFuY2hvcjBSMEwxCzAJBgNV
  48. BAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxJjAkBgNVBAMTHURpZ2lDZXJ0
  49. IEVDQyBTZWN1cmUgU2VydmVyIENBggIFIIICZW4=
  50. """
  51. def setUp(self):
  52. self.asn1Spec = rfc5652.ContentInfo()
  53. def testDerCodec(self):
  54. substrate = pem.readBase64fromText(self.trust_anchor_list_pem_text)
  55. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  56. self.assertFalse(rest)
  57. self.assertTrue(asn1Object.prettyPrint())
  58. self.assertEqual(substrate, der_encoder(asn1Object))
  59. self.assertEqual(rfc5914.id_ct_trustAnchorList, asn1Object['contentType'])
  60. tal, rest = der_decoder(asn1Object['content'], rfc5914.TrustAnchorList())
  61. self.assertFalse(rest)
  62. self.assertTrue(tal.prettyPrint())
  63. self.assertEqual(asn1Object['content'], der_encoder(tal))
  64. self.assertEqual(3, sum(1 for _ in tal))
  65. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  66. if __name__ == '__main__':
  67. unittest.TextTestRunner(verbosity=2).run(suite)