Add a return value to hasher_t.allocate_hash()
This commit is contained in:
@@ -735,7 +735,10 @@ METHOD(crypto_tester_t, test_hasher, bool,
|
||||
|
||||
/* allocated hash */
|
||||
data = chunk_create(vector->data, vector->len);
|
||||
hasher->allocate_hash(hasher, data, &hash);
|
||||
if (!hasher->allocate_hash(hasher, data, &hash))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
if (hash.len != hasher->get_hash_size(hasher))
|
||||
{
|
||||
failed = TRUE;
|
||||
@@ -758,8 +761,8 @@ METHOD(crypto_tester_t, test_hasher, bool,
|
||||
if (data.len > 2)
|
||||
{
|
||||
memset(hash.ptr, 0, hash.len);
|
||||
hasher->allocate_hash(hasher, chunk_create(data.ptr, 1), NULL);
|
||||
if (!hasher->get_hash(hasher, chunk_create(data.ptr + 1, 1), NULL) ||
|
||||
if (!hasher->allocate_hash(hasher, chunk_create(data.ptr, 1), NULL) ||
|
||||
!hasher->get_hash(hasher, chunk_create(data.ptr + 1, 1), NULL) ||
|
||||
!hasher->get_hash(hasher, chunk_skip(data, 2), hash.ptr) ||
|
||||
!memeq(vector->hash, hash.ptr, hash.len))
|
||||
{
|
||||
|
||||
@@ -94,8 +94,10 @@ struct hasher_t {
|
||||
*
|
||||
* @param data chunk with data to hash
|
||||
* @param hash chunk which will hold allocated hash
|
||||
* @return TRUE if hash allocated successfully
|
||||
*/
|
||||
void (*allocate_hash) (hasher_t *this, chunk_t data, chunk_t *hash);
|
||||
__attribute__((warn_unused_result))
|
||||
bool (*allocate_hash) (hasher_t *this, chunk_t data, chunk_t *hash);
|
||||
|
||||
/**
|
||||
* Get the size of the resulting hash.
|
||||
|
||||
@@ -421,13 +421,13 @@ end:
|
||||
|
||||
algorithm = hasher_algorithm_from_oid(digest_alg);
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, algorithm);
|
||||
if (hasher == NULL)
|
||||
if (!hasher || !hasher->allocate_hash(hasher, this->data, &hash))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
DBG1(DBG_LIB, "hash algorithm %N not supported",
|
||||
hash_algorithm_names, algorithm);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, this->data, &hash);
|
||||
hasher->destroy(hasher);
|
||||
DBG3(DBG_LIB, "hash: %B", &hash);
|
||||
|
||||
@@ -921,13 +921,14 @@ METHOD(pkcs7_t, build_signedData, bool,
|
||||
time_t now;
|
||||
|
||||
hasher = lib->crypto->create_hasher(lib->crypto, alg);
|
||||
if (hasher == NULL)
|
||||
if (!hasher ||
|
||||
!hasher->allocate_hash(hasher, this->data, &messageDigest))
|
||||
{
|
||||
DESTROY_IF(hasher);
|
||||
DBG1(DBG_LIB, " hash algorithm %N not support",
|
||||
hash_algorithm_names, alg);
|
||||
return FALSE;
|
||||
}
|
||||
hasher->allocate_hash(hasher, this->data, &messageDigest);
|
||||
hasher->destroy(hasher);
|
||||
this->attributes->set_attribute(this->attributes,
|
||||
OID_PKCS9_MESSAGE_DIGEST,
|
||||
|
||||
Reference in New Issue
Block a user