OLD | NEW |
(Empty) | |
| 1 # |
| 2 # Test script for Crypto.Protocol.AllOrNothing |
| 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 AllOrNothing |
| 30 from Crypto.Util.py3compat import * |
| 31 |
| 32 text = b("""\ |
| 33 When in the Course of human events, it becomes necessary for one people to |
| 34 dissolve the political bands which have connected them with another, and to |
| 35 assume among the powers of the earth, the separate and equal station to which |
| 36 the Laws of Nature and of Nature's God entitle them, a decent respect to the |
| 37 opinions of mankind requires that they should declare the causes which impel |
| 38 them to the separation. |
| 39 |
| 40 We hold these truths to be self-evident, that all men are created equal, that |
| 41 they are endowed by their Creator with certain unalienable Rights, that among |
| 42 these are Life, Liberty, and the pursuit of Happiness. That to secure these |
| 43 rights, Governments are instituted among Men, deriving their just powers from |
| 44 the consent of the governed. That whenever any Form of Government becomes |
| 45 destructive of these ends, it is the Right of the People to alter or to |
| 46 abolish it, and to institute new Government, laying its foundation on such |
| 47 principles and organizing its powers in such form, as to them shall seem most |
| 48 likely to effect their Safety and Happiness. |
| 49 """) |
| 50 |
| 51 class AllOrNothingTest (unittest.TestCase): |
| 52 |
| 53 def runTest(self): |
| 54 "Simple test of AllOrNothing" |
| 55 |
| 56 from Crypto.Cipher import AES |
| 57 import base64 |
| 58 |
| 59 # The current AllOrNothing will fail |
| 60 # every so often. Repeat the test |
| 61 # several times to force this. |
| 62 for i in range(50): |
| 63 x = AllOrNothing.AllOrNothing(AES) |
| 64 |
| 65 msgblocks = x.digest(text) |
| 66 |
| 67 # get a new undigest-only object so there's no leakage |
| 68 y = AllOrNothing.AllOrNothing(AES) |
| 69 text2 = y.undigest(msgblocks) |
| 70 self.assertEqual(text, text2) |
| 71 |
| 72 def get_tests(config={}): |
| 73 return [AllOrNothingTest()] |
| 74 |
| 75 if __name__ == "__main__": |
| 76 unittest.main() |
OLD | NEW |