test_chaffing.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #
  2. # Test script for Crypto.Protocol.Chaffing
  3. #
  4. # Part of the Python Cryptography Toolkit
  5. #
  6. # Written by Andrew Kuchling and others
  7. #
  8. # ===================================================================
  9. # The contents of this file are dedicated to the public domain. To
  10. # the extent that dedication to the public domain is not available,
  11. # everyone is granted a worldwide, perpetual, royalty-free,
  12. # non-exclusive license to exercise all rights associated with the
  13. # contents of this file for any purpose whatsoever.
  14. # No rights are reserved.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. # SOFTWARE.
  24. # ===================================================================
  25. __revision__ = "$Id$"
  26. import unittest
  27. from Crypto.Protocol import Chaffing
  28. text = """\
  29. When in the Course of human events, it becomes necessary for one people to
  30. dissolve the political bands which have connected them with another, and to
  31. assume among the powers of the earth, the separate and equal station to which
  32. the Laws of Nature and of Nature's God entitle them, a decent respect to the
  33. opinions of mankind requires that they should declare the causes which impel
  34. them to the separation.
  35. We hold these truths to be self-evident, that all men are created equal, that
  36. they are endowed by their Creator with certain unalienable Rights, that among
  37. these are Life, Liberty, and the pursuit of Happiness. That to secure these
  38. rights, Governments are instituted among Men, deriving their just powers from
  39. the consent of the governed. That whenever any Form of Government becomes
  40. destructive of these ends, it is the Right of the People to alter or to
  41. abolish it, and to institute new Government, laying its foundation on such
  42. principles and organizing its powers in such form, as to them shall seem most
  43. likely to effect their Safety and Happiness.
  44. """
  45. class ChaffingTest (unittest.TestCase):
  46. def runTest(self):
  47. "Simple tests of chaffing and winnowing"
  48. # Test constructors
  49. Chaffing.Chaff()
  50. Chaffing.Chaff(0.5, 1)
  51. self.assertRaises(ValueError, Chaffing.Chaff, factor=-1)
  52. self.assertRaises(ValueError, Chaffing.Chaff, blocksper=-1)
  53. data = [(1, 'data1', 'data1'), (2, 'data2', 'data2')]
  54. c = Chaffing.Chaff(1.0, 1)
  55. c.chaff(data)
  56. chaff = c.chaff(data)
  57. self.assertEqual(len(chaff), 4)
  58. c = Chaffing.Chaff(0.0, 1)
  59. chaff = c.chaff(data)
  60. self.assertEqual(len(chaff), 2)
  61. def get_tests(config={}):
  62. return [ChaffingTest()]
  63. if __name__ == "__main__":
  64. unittest.main()