test_rfc8619.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 import decoder as der_decoder
  10. from pyasn1.codec.der import encoder as der_encoder
  11. from pyasn1_modules import pem
  12. from pyasn1_modules import rfc5280
  13. from pyasn1_modules import rfc8619
  14. class HKDFSHA256TestCase(unittest.TestCase):
  15. alg_id_1_pem_text = "MA0GCyqGSIb3DQEJEAMc"
  16. def setUp(self):
  17. self.asn1Spec = rfc5280.AlgorithmIdentifier()
  18. def testDerCodec(self):
  19. substrate = pem.readBase64fromText(self.alg_id_1_pem_text)
  20. asn1Object, rest = der_decoder.decode(
  21. substrate, asn1Spec=self.asn1Spec)
  22. self.assertFalse(rest)
  23. self.assertTrue(asn1Object.prettyPrint())
  24. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  25. self.assertEqual(
  26. rfc8619.id_alg_hkdf_with_sha256, asn1Object['algorithm'])
  27. class HKDFSHA384TestCase(unittest.TestCase):
  28. alg_id_1_pem_text = "MA0GCyqGSIb3DQEJEAMd"
  29. def setUp(self):
  30. self.asn1Spec = rfc5280.AlgorithmIdentifier()
  31. def testDerCodec(self):
  32. substrate = pem.readBase64fromText(self.alg_id_1_pem_text)
  33. asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
  34. self.assertFalse(rest)
  35. self.assertTrue(asn1Object.prettyPrint())
  36. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  37. self.assertEqual(
  38. rfc8619.id_alg_hkdf_with_sha384, asn1Object['algorithm'])
  39. class HKDFSHA512TestCase(unittest.TestCase):
  40. alg_id_1_pem_text = "MA0GCyqGSIb3DQEJEAMe"
  41. def setUp(self):
  42. self.asn1Spec = rfc5280.AlgorithmIdentifier()
  43. def testDerCodec(self):
  44. substrate = pem.readBase64fromText(self.alg_id_1_pem_text)
  45. asn1Object, rest = der_decoder.decode(
  46. substrate, asn1Spec=self.asn1Spec)
  47. self.assertFalse(rest)
  48. self.assertTrue(asn1Object.prettyPrint())
  49. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  50. self.assertEqual(
  51. rfc8619.id_alg_hkdf_with_sha512, asn1Object['algorithm'])
  52. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  53. if __name__ == '__main__':
  54. result = unittest.TextTestRunner(verbosity=2).run(suite)
  55. sys.exit(not result.wasSuccessful())