test_rfc3560.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 rfc3560
  15. class OAEPDefautTestCase(unittest.TestCase):
  16. oaep_default_pem_text = "MAsGCSqGSIb3DQEBBw=="
  17. def setUp(self):
  18. self.asn1Spec = rfc5280.AlgorithmIdentifier()
  19. def testDerCodec(self):
  20. substrate = pem.readBase64fromText(self.oaep_default_pem_text)
  21. asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
  22. self.assertFalse(rest)
  23. self.assertTrue(asn1Object.prettyPrint())
  24. self.assertEqual(rfc3560.id_RSAES_OAEP, asn1Object[0])
  25. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  26. class OAEPSHA256TestCase(unittest.TestCase):
  27. oaep_sha256_pem_text = "MDwGCSqGSIb3DQEBBzAvoA8wDQYJYIZIAWUDBAIBBQChHDAaBgkqhkiG9w0BAQgwDQYJYIZIAWUDBAIBBQA="
  28. def setUp(self):
  29. self.asn1Spec = rfc5280.AlgorithmIdentifier()
  30. def testDerCodec(self):
  31. substrate = pem.readBase64fromText(self.oaep_sha256_pem_text)
  32. asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
  33. self.assertFalse(rest)
  34. self.assertTrue(asn1Object.prettyPrint())
  35. self.assertEqual(rfc3560.id_RSAES_OAEP, asn1Object[0])
  36. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  37. class OAEPFullTestCase(unittest.TestCase):
  38. oaep_full_pem_text = "MFMGCSqGSIb3DQEBBzBGoA8wDQYJYIZIAWUDBAICBQChHDAaBgkqhkiG9w0BAQgwDQYJYIZIAWUDBAICBQCiFTATBgkqhkiG9w0BAQkEBmZvb2Jhcg=="
  39. def setUp(self):
  40. self.asn1Spec = rfc5280.AlgorithmIdentifier()
  41. def testDerCodec(self):
  42. substrate = pem.readBase64fromText(self.oaep_full_pem_text)
  43. asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
  44. self.assertFalse(rest)
  45. self.assertTrue(asn1Object.prettyPrint())
  46. self.assertEqual(rfc3560.id_RSAES_OAEP, asn1Object[0])
  47. self.assertEqual(substrate, der_encoder.encode(asn1Object))
  48. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  49. if __name__ == '__main__':
  50. result = unittest.TextTestRunner(verbosity=2).run(suite)
  51. sys.exit(not result.wasSuccessful())