test_rfc8418.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 import decoder as der_decoder
  11. from pyasn1.codec.der import encoder as der_encoder
  12. from pyasn1_modules import pem
  13. from pyasn1_modules import rfc5280
  14. from pyasn1_modules import rfc8418
  15. class KeyAgreeAlgTestCase(unittest.TestCase):
  16. key_agree_alg_id_pem_text = "MBoGCyqGSIb3DQEJEAMUMAsGCWCGSAFlAwQBLQ=="
  17. def setUp(self):
  18. self.asn1Spec = rfc5280.AlgorithmIdentifier()
  19. def testDerCodec(self):
  20. substrate = pem.readBase64fromText(self.key_agree_alg_id_pem_text)
  21. asn1Object, rest = der_decoder.decode(
  22. substrate, asn1Spec=self.asn1Spec)
  23. self.assertFalse(rest)
  24. self.assertTrue(asn1Object.prettyPrint())
  25. self.assertEqual(
  26. rfc8418.dhSinglePass_stdDH_hkdf_sha384_scheme,
  27. asn1Object['algorithm'])
  28. self.assertTrue(asn1Object['parameters'].isValue)
  29. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  30. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  31. if __name__ == '__main__':
  32. result = unittest.TextTestRunner(verbosity=2).run(suite)
  33. sys.exit(not result.wasSuccessful())