tests/test_crypto_algorithms.py
changeset 4550 80dd9e83dad9
parent 4252 fe660f227cac
equal deleted inserted replaced
4549:7926f4988eb1 4550:80dd9e83dad9
    33     not going to vary with Python versions"""
    33     not going to vary with Python versions"""
    34 
    34 
    35     def check0wnerHash40Bit(self):
    35     def check0wnerHash40Bit(self):
    36         "owner key calculation"
    36         "owner key calculation"
    37         ownerHash = computeO('userpass','ownerpass', revision=2)
    37         ownerHash = computeO('userpass','ownerpass', revision=2)
    38         assert hexText(ownerHash) == '<F86213EB0CED81F097947F3B343E34CAC8CA92CE8F6FEE2556FA31EC1FE968AF>'
    38         self.assertEqual(hexText(ownerHash),'<F86213EB0CED81F097947F3B343E34CAC8CA92CE8F6FEE2556FA31EC1FE968AF>')
    39         
    39         
    40     def checkEncryptionKey40Bit(self):
    40     def checkEncryptionKey40Bit(self):
    41         userPass = 'userpass'
    41         userPass = 'userpass'
    42         ownerHash = unHexText('<F86213EB0CED81F097947F3B343E34CAC8CA92CE8F6FEE2556FA31EC1FE968AF>')
    42         ownerHash = unHexText('<F86213EB0CED81F097947F3B343E34CAC8CA92CE8F6FEE2556FA31EC1FE968AF>')
    43         documentID = 'xxxxxxxxxxxxxxxx'        
    43         documentID = 'xxxxxxxxxxxxxxxx'        
    44         permissions = -4
    44         permissions = -4
    45         encKey = encryptionkey(userPass, ownerHash, permissions, documentID, revision=2)
    45         encKey = encryptionkey(userPass, ownerHash, permissions, documentID, revision=2)
    46         assert hexText(encKey) == '<7EBBD07A88>'
    46         self.assertEqual(hexText(encKey),'<7EBBD07A88>')
    47 
    47 
    48     def checkUserHash40Bit(self):
    48     def checkUserHash40Bit(self):
    49         encKey = unHexText('<7EBBD07A88>')
    49         encKey = unHexText('<7EBBD07A88>')
    50         userHash = computeU(encKey, revision=2, documentId='xxxxxxxxxxxxxxxx')
    50         userHash = computeU(encKey, revision=2, documentId='xxxxxxxxxxxxxxxx')
    51         assert hexText(userHash) == '<AA154131D8FA105317F7104D2001A345D78A3DEEFA3D85D032FC9B4B35DA72A0>'
    51         self.assertEqual(hexText(userHash),'<AA154131D8FA105317F7104D2001A345D78A3DEEFA3D85D032FC9B4B35DA72A0>')
    52 
    52 
    53     def checkEncryptString40Bit(self):
    53     def checkEncryptString40Bit(self):
    54         assert hexText(encodePDF(unHexText('<3DC3EBDA71>'), 9, 0, 'anonymous')) == '<57AC33DDEB5775982A>'
    54         self.assertEqual(hexText(encodePDF(unHexText('<3DC3EBDA71>'), 9, 0, 'anonymous')), '<57AC33DDEB5775982A>')
    55 
    55 
    56         
    56         
    57     def check0wnerHash128Bit(self):
    57     def check0wnerHash128Bit(self):
    58         "owner key calculation"
    58         "owner key calculation"
    59         ownerHash = computeO('userpass','ownerpass', revision=3)
    59         ownerHash = computeO('userpass','ownerpass', revision=3)
    60         assert hexText(ownerHash) == '<68E5704AC779A5F0CD89704406587A52F25BF61CADC56A0F8DB6C4DB0052534D>'
    60         self.assertEqual(hexText(ownerHash), '<68E5704AC779A5F0CD89704406587A52F25BF61CADC56A0F8DB6C4DB0052534D>')
    61         
    61         
    62     def checkEncryptionKey128Bit(self):
    62     def checkEncryptionKey128Bit(self):
    63         userPass = 'userpass'
    63         userPass = 'userpass'
    64         ownerHash = unHexText('<68E5704AC779A5F0CD89704406587A52F25BF61CADC56A0F8DB6C4DB0052534D>')
    64         ownerHash = unHexText('<68E5704AC779A5F0CD89704406587A52F25BF61CADC56A0F8DB6C4DB0052534D>')
    65         documentID = 'xxxxxxxxxxxxxxxx'        
    65         documentID = 'xxxxxxxxxxxxxxxx'        
    66         permissions = -4
    66         permissions = -4
    67         encKey = encryptionkey(userPass, ownerHash, permissions, documentID, revision=3)
    67         encKey = encryptionkey(userPass, ownerHash, permissions, documentID, revision=3)
    68         assert hexText(encKey) == '<13DDE7585D9BE366C976DDD56AF541D1>'
    68         self.assertEqual(hexText(encKey), '<13DDE7585D9BE366C976DDD56AF541D1>')
    69         
    69         
    70     def checkUserHash128Bit(self):
    70     def checkUserHash128Bit(self):
    71         encKey = unHexText('<13DDE7585D9BE366C976DDD56AF541D1>')
    71         encKey = unHexText('<13DDE7585D9BE366C976DDD56AF541D1>')
    72         userHash = computeU(encKey, revision=3, documentId='xxxxxxxxxxxxxxxx')
    72         userHash = computeU(encKey, revision=3, documentId='xxxxxxxxxxxxxxxx')
    73         assert hexText(userHash) == '<A9AE45CDE827FE0B7D6536267948836A00000000000000000000000000000000>'
    73         self.assertEqual(hexText(userHash), '<A9AE45CDE827FE0B7D6536267948836A00000000000000000000000000000000>')
    74 
    74 
    75     def checkEncryptString128Bit(self):
    75     def checkEncryptString128Bit(self):
    76         assert hexText(encodePDF(unHexText('<3C0C5EBE0122D8EB2BDDF8A09FA8E29E>'),
    76         self.assertEqual(hexText(encodePDF(unHexText('<3C0C5EBE0122D8EB2BDDF8A09FA8E29E>'),
    77                                  9,
    77                                  9,
    78                                  0,
    78                                  0,
    79                                  'anonymous')
    79                                  'anonymous')
    80                        ) == '<27FB3E943FCF61878B>'
    80                        ),'<27FB3E943FCF61878B>')
    81 
    81 
    82 class EyeballTestCase(unittest.TestCase):
    82 class EyeballTestCase(unittest.TestCase):
    83     "This makes a gaxillion self-explanatory files"
    83     "This makes a gaxillion self-explanatory files"
    84     def check40BitOptions(self):
    84     def check40BitOptions(self):
    85         userPass = 'userpass'
    85         userPass = 'userpass'