test_rfc8692.py 1.6 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 rfc5751
  13. from pyasn1_modules import rfc8692
  14. class AlgorithmIdentifierTestCase(unittest.TestCase):
  15. pem_text = """\
  16. MEowCwYJYIZIAWUDBAILMAsGCWCGSAFlAwQCDDAKBggrBgEFBQcGHjAKBggrBgEF
  17. BQcGHzAKBggrBgEFBQcGIDAKBggrBgEFBQcGIQ==
  18. """
  19. def setUp(self):
  20. self.asn1Spec = rfc5751.SMIMECapabilities()
  21. def testDerCodec(self):
  22. substrate = pem.readBase64fromText(self.pem_text)
  23. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  24. self.assertFalse(rest)
  25. self.assertTrue(asn1Object.prettyPrint())
  26. self.assertEqual(substrate, der_encoder(asn1Object))
  27. oid_list = (
  28. rfc8692.id_shake128,
  29. rfc8692.id_shake256,
  30. rfc8692.id_RSASSA_PSS_SHAKE128,
  31. rfc8692.id_RSASSA_PSS_SHAKE256,
  32. rfc8692.id_ecdsa_with_shake128,
  33. rfc8692.id_ecdsa_with_shake256,
  34. )
  35. count = 0
  36. for algid in asn1Object:
  37. self.assertTrue(algid['capabilityID'] in oid_list)
  38. count += 1
  39. self.assertTrue(len(oid_list), count)
  40. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  41. if __name__ == '__main__':
  42. result = unittest.TextTestRunner(verbosity=2).run(suite)
  43. sys.exit(not result.wasSuccessful())