OLD | NEW |
(Empty) | |
| 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 |
| 26 __revision__ = "$Id$" |
| 27 |
| 28 import unittest |
| 29 from Crypto.Protocol import Chaffing |
| 30 |
| 31 text = """\ |
| 32 When in the Course of human events, it becomes necessary for one people to |
| 33 dissolve the political bands which have connected them with another, and to |
| 34 assume among the powers of the earth, the separate and equal station to which |
| 35 the Laws of Nature and of Nature's God entitle them, a decent respect to the |
| 36 opinions of mankind requires that they should declare the causes which impel |
| 37 them to the separation. |
| 38 |
| 39 We hold these truths to be self-evident, that all men are created equal, that |
| 40 they are endowed by their Creator with certain unalienable Rights, that among |
| 41 these are Life, Liberty, and the pursuit of Happiness. That to secure these |
| 42 rights, Governments are instituted among Men, deriving their just powers from |
| 43 the consent of the governed. That whenever any Form of Government becomes |
| 44 destructive of these ends, it is the Right of the People to alter or to |
| 45 abolish it, and to institute new Government, laying its foundation on such |
| 46 principles and organizing its powers in such form, as to them shall seem most |
| 47 likely to effect their Safety and Happiness. |
| 48 """ |
| 49 |
| 50 class ChaffingTest (unittest.TestCase): |
| 51 |
| 52 def runTest(self): |
| 53 "Simple tests of chaffing and winnowing" |
| 54 # Test constructors |
| 55 Chaffing.Chaff() |
| 56 Chaffing.Chaff(0.5, 1) |
| 57 self.assertRaises(ValueError, Chaffing.Chaff, factor=-1) |
| 58 self.assertRaises(ValueError, Chaffing.Chaff, blocksper=-1) |
| 59 |
| 60 data = [(1, 'data1', 'data1'), (2, 'data2', 'data2')] |
| 61 c = Chaffing.Chaff(1.0, 1) |
| 62 c.chaff(data) |
| 63 chaff = c.chaff(data) |
| 64 self.assertEqual(len(chaff), 4) |
| 65 |
| 66 c = Chaffing.Chaff(0.0, 1) |
| 67 chaff = c.chaff(data) |
| 68 self.assertEqual(len(chaff), 2) |
| 69 |
| 70 def get_tests(config={}): |
| 71 return [ChaffingTest()] |
| 72 |
| 73 if __name__ == "__main__": |
| 74 unittest.main() |
OLD | NEW |