Skip to content

Commit

Permalink
wip: Apply script on lcx_hash.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Chapron committed Jan 15, 2024
1 parent 3dd0bcf commit 80d5665
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib_cxng/include/lcx_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#ifdef HAVE_HASH

#include "ledger_assert.h"
#include "cx_errors.h"
#include "lcx_wrappers.h"
#include "lcx_common.h"
Expand Down Expand Up @@ -150,6 +151,21 @@ WARN_UNUSED_RESULT cx_err_t cx_hash_no_throw(cx_hash_t *hash,
uint8_t *out,
size_t out_len);

/**
* @brief cx_hash_no_throw version which doesn't return in case of failure.
*
* See #cx_hash_no_throw
*/
static inline void cx_hash_assert(cx_hash_t *hash,
uint32_t mode,
const uint8_t *in,
size_t len,
uint8_t *out,
size_t out_len)
{
LEDGER_ASSERT(cx_hash_no_throw(hash, mode, in, len, out, out_len) == CX_OK, "cx_hash_no_throw");
}

/**
* @deprecated
* See #cx_hash_no_throw
Expand Down Expand Up @@ -179,6 +195,16 @@ DEPRECATED static inline size_t cx_hash(cx_hash_t *hash,
*/
WARN_UNUSED_RESULT cx_err_t cx_hash_init(cx_hash_t *hash, cx_md_t hash_id);

/**
* @brief cx_hash_init version which doesn't return in case of failure.
*
* See #cx_hash_init
*/
static inline void cx_hash_init_assert(cx_hash_t *hash, cx_md_t hash_id)
{
LEDGER_ASSERT(cx_hash_init(hash, hash_id) == CX_OK, "cx_hash_init");
}

/**
* @brief Initializes a hash context.
*
Expand All @@ -201,6 +227,16 @@ WARN_UNUSED_RESULT cx_err_t cx_hash_init(cx_hash_t *hash, cx_md_t hash_id);
*/
WARN_UNUSED_RESULT cx_err_t cx_hash_init_ex(cx_hash_t *hash, cx_md_t hash_id, size_t output_size);

/**
* @brief cx_hash_init_ex version which doesn't return in case of failure.
*
* See #cx_hash_init_ex
*/
static inline void cx_hash_init_ex_assert(cx_hash_t *hash, cx_md_t hash_id, size_t output_size)
{
LEDGER_ASSERT(cx_hash_init_ex(hash, hash_id, output_size) == CX_OK, "cx_hash_init_ex");
}

/**
* @brief Adds more data to hash.
*
Expand All @@ -220,6 +256,16 @@ WARN_UNUSED_RESULT cx_err_t cx_hash_init_ex(cx_hash_t *hash, cx_md_t hash_id, si
*/
WARN_UNUSED_RESULT cx_err_t cx_hash_update(cx_hash_t *hash, const uint8_t *in, size_t in_len);

/**
* @brief cx_hash_update version which doesn't return in case of failure.
*
* See #cx_hash_update
*/
static inline void cx_hash_update_assert(cx_hash_t *hash, const uint8_t *in, size_t in_len)
{
LEDGER_ASSERT(cx_hash_update(hash, in, in_len) == CX_OK, "cx_hash_update");
}

/**
* @brief Finalizes the hash.
*
Expand All @@ -235,6 +281,16 @@ WARN_UNUSED_RESULT cx_err_t cx_hash_update(cx_hash_t *hash, const uint8_t *in, s
*/
WARN_UNUSED_RESULT cx_err_t cx_hash_final(cx_hash_t *hash, uint8_t *digest);

/**
* @brief cx_hash_final version which doesn't return in case of failure.
*
* See #cx_hash_final
*/
static inline void cx_hash_final_assert(cx_hash_t *hash, uint8_t *digest)
{
LEDGER_ASSERT(cx_hash_final(hash, digest) == CX_OK, "cx_hash_final");
}

#endif // HAVE_HASH

#endif // LCX_HASH_H

0 comments on commit 80d5665

Please sign in to comment.