test_rfc8410.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 rfc5208
  14. from pyasn1_modules import rfc8410
  15. class PrivateKeyTestCase(unittest.TestCase):
  16. no_pub_key_pem_text = ("MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwo"
  17. "y/HU++CXqI9EdVhC")
  18. def setUp(self):
  19. self.asn1Spec = rfc5208.PrivateKeyInfo()
  20. def testDerCodec(self):
  21. substrate = pem.readBase64fromText(self.no_pub_key_pem_text)
  22. asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
  23. self.assertFalse(rest)
  24. self.assertTrue(asn1Object.prettyPrint())
  25. self.assertEqual(
  26. rfc8410.id_Ed25519, asn1Object['privateKeyAlgorithm']['algorithm'])
  27. self.assertTrue(asn1Object['privateKey'].isValue)
  28. self.assertEqual(
  29. "0x0420d4ee", asn1Object['privateKey'].prettyPrint()[0:10])
  30. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  31. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  32. if __name__ == '__main__':
  33. result = unittest.TextTestRunner(verbosity=2).run(suite)
  34. sys.exit(not result.wasSuccessful())