def test_get_invalid_hashalgo_from_descrition(self): """ test to get the hash algo from different descriptions """ # first test the beaking case, where description was None hash_algo = get_hashalgo_from_description(None) self.assertTrue(hash_algo == sha1) # invalid hash function name but valid fallback hash_algo = get_hashalgo_from_description('blub') self.assertTrue(hash_algo == sha1) # invalid hash function name and invalid fallback with self.assertRaises(Exception) as exx: hash_algo = get_hashalgo_from_description('blub', fallback='blah') message = 'unsupported hash function' exx_message = "%r" % exx.exception self.assertTrue(message in exx_message, exx) return
def test_get_valid_hashalgo_from_descrition(self): """ test to get the hash algo from different descriptions """ for description, hash_function in Hashlib_map.items(): hash_algo = get_hashalgo_from_description(description) self.assertTrue(hash_algo == hash_function) return
def _getCrypto(self, description): ''' Convert the name of a hash algorithm as described in the OATH specifications, to a python object handling the digest algorithm interface ''' hash_type = description.lower() if hash_type in ['sha1', 'sha256', 'sha512']: return get_hashalgo_from_description(hash_type) # any other case is an error raise ValueError('Unknown hash algorithm %r' % hash_type)
def getHashlib(self, hLibStr): return get_hashalgo_from_description(description=hLibStr, fallback='sha1')