test_rfc5649.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 rfc5649
  14. class AESKeyWrapTestCase(unittest.TestCase):
  15. kw_alg_id_pem_text = "MAsGCWCGSAFlAwQBLQ=="
  16. def setUp(self):
  17. self.asn1Spec = rfc5649.AlgorithmIdentifier()
  18. def testDerCodec(self):
  19. substrate = pem.readBase64fromText(self.kw_alg_id_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(rfc5649.id_aes256_wrap, asn1Object[0])
  25. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  26. class AESKeyWrapWithPadTestCase(unittest.TestCase):
  27. kw_pad_alg_id_pem_text = "MAsGCWCGSAFlAwQBMA=="
  28. def setUp(self):
  29. self.asn1Spec = rfc5649.AlgorithmIdentifier()
  30. def testDerCodec(self):
  31. substrate = pem.readBase64fromText(self.kw_pad_alg_id_pem_text)
  32. asn1Object, rest = der_decoder.decode(
  33. substrate, asn1Spec=self.asn1Spec)
  34. self.assertFalse(rest)
  35. self.assertTrue(asn1Object.prettyPrint())
  36. self.assertEqual(rfc5649.id_aes256_wrap_pad, asn1Object[0])
  37. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  38. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  39. if __name__ == '__main__':
  40. result = unittest.TextTestRunner(verbosity=2).run(suite)
  41. sys.exit(not result.wasSuccessful())