| 1 | # |
| 2 | # Test script for Crypto.Util.RFC1751. |
| 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 binascii |
| 29 | import unittest |
| 30 | from Crypto.Util import RFC1751 |
| 31 | from Crypto.Util.py3compat import * |
| 32 | |
| 33 | test_data = [('EB33F77EE73D4053', 'TIDE ITCH SLOW REIN RULE MOT'), |
| 34 | ('CCAC2AED591056BE4F90FD441C534766', |
| 35 | 'RASH BUSH MILK LOOK BAD BRIM AVID GAFF BAIT ROT POD LOVE'), |
| 36 | ('EFF81F9BFBC65350920CDD7416DE8009', |
| 37 | 'TROD MUTE TAIL WARM CHAR KONG HAAG CITY BORE O TEAL AWL') |
| 38 | ] |
| 39 | |
| 40 | class RFC1751Test_k2e (unittest.TestCase): |
| 41 | |
| 42 | def runTest (self): |
| 43 | "Check converting keys to English" |
| 44 | for key, words in test_data: |
| 45 | key=binascii.a2b_hex(b(key)) |
| 46 | self.assertEqual(RFC1751.key_to_english(key), words) |
| 47 | |
| 48 | class RFC1751Test_e2k (unittest.TestCase): |
| 49 | |
| 50 | def runTest (self): |
| 51 | "Check converting English strings to keys" |
| 52 | for key, words in test_data: |
| 53 | key=binascii.a2b_hex(b(key)) |
| 54 | self.assertEqual(RFC1751.english_to_key(words), key) |
| 55 | |
| 56 | # class RFC1751Test |
| 57 | |
| 58 | def get_tests(config={}): |
| 59 | return [RFC1751Test_k2e(), RFC1751Test_e2k()] |
| 60 | |
| 61 | if __name__ == "__main__": |
| 62 | unittest.main() |