コード例 #1
0
 def test_nacl(self):
     master_secret = 'No, I am your father'.encode()
     keys_1 = hkdf(master_secret, 5, salt=b'and pepper')
     keys_2 = hkdf(master_secret, 5, salt=b'and vinegar')
     for k1, k2 in zip(keys_1, keys_2):
         self.assertNotEqual(k1,
                             k2,
                             msg='using different salts should result in '
                             'different keys')
コード例 #2
0
 def test_kdf(self):
     master_secret = 'No, I am your father'.encode()
     for num_keys in (1, 10, 50):
         for key_size in (2, 20):
             keys = hkdf(master_secret, num_keys, key_size=key_size)
             self.assertEqual(len(keys), num_keys)
             for key in keys:
                 self.assertEqual(len(key), key_size)
コード例 #3
0
 def test_kdf(self):
     secret = 'No, I am your father'.encode()
     for num_keys in (1, 10, 50):
         for key_size in (2, 20):
             keys = hkdf(secret, num_keys, key_size=key_size)
             self.assertEqual(len(keys), num_keys)
             set_of_keys = set()
             for key in keys:
                 self.assertEqual(len(key), key_size)
                 set_of_keys.add(key)
             # Checking that there are no duplicate keys
             self.assertEqual(num_keys, len(set_of_keys))
コード例 #4
0
 def test_wrong_hash_function(self):
     with self.assertRaises(ValueError):
         hkdf('foo'.encode('ascii'), 3, hash_algo='obviously_unsupported')