test_rfc5915.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 rfc5915
  14. from pyasn1_modules import rfc5480
  15. class MUDCertTestCase(unittest.TestCase):
  16. private_key_pem_text = """\
  17. MIGkAgEBBDDLjzGbbLrR3T13lrrVum7WC/4Ua4Femc1RhhNVe1Q5XsArQ33kn9kx
  18. 3lOUfOcG+qagBwYFK4EEACKhZANiAAT4zZ8HL+xEDpXWkoWp5xFMTz4u4Ae1nF6z
  19. XCYlmsEGD5vPu5hl9hDEjd1UHRgJIPoy3fJcWWeZ8FHCirICtuMgFisNscG/aTwK
  20. yDYOFDuqz/C2jyEwqgWCRyxyohuJXtk=
  21. """
  22. def setUp(self):
  23. self.asn1Spec = rfc5915.ECPrivateKey()
  24. def testDerCodec(self):
  25. substrate = pem.readBase64fromText(self.private_key_pem_text)
  26. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  27. self.assertFalse(rest)
  28. self.assertTrue(asn1Object.prettyPrint())
  29. self.assertEqual(substrate, der_encoder(asn1Object))
  30. self.assertEqual(
  31. rfc5480.secp384r1, asn1Object['parameters']['namedCurve'])
  32. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  33. if __name__ == '__main__':
  34. result = unittest.TextTestRunner(verbosity=2).run(suite)
  35. sys.exit(not result.wasSuccessful())