libhasha 2.2.2
Loading...
Searching...
No Matches
io.h File Reference

Header file for I/O operations related to hashing. More...

Include dependency graph for io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HA_IO_ENDLINE_LF   "\n"
#define HA_IO_ENDLINE_CRLF   "\r\n"
#define HA_IO_ENDLINE   HA_IO_ENDLINE_LF
#define ha_hash2str_bound(len)
#define ha_str2hash_bound(len)
#define ha_strhash_bound(len)

Functions

HA_PUBFUN size_t ha_fputhash (FILE *stream, ha_cdigest_t digest, size_t digestlen, const char *end)
 Writes the hash digest to the specified file stream.
HA_PUBFUN size_t ha_puthash (ha_cdigest_t digest, size_t digestlen, const char *end)
 Outputs the hash digest to standard output.
HA_PUBFUN size_t ha_hash2str (char *dst, ha_cdigest_t src, size_t len)
 Converts a hash digest to a hexadecimal string representation.
HA_PUBFUN size_t ha_str2hash (ha_digest_t dst, const char *src, size_t len)
 Converts a hexadecimal string representation to a hash digest.
HA_PUBFUN size_t ha_strhash (char *dst, ha_cdigest_t src, size_t len)
HA_PUBFUN int ha_cmphash (ha_cdigest_t lhs, ha_cdigest_t rhs, size_t digestlen)
 Compares two hash digests byte by byte.
HA_PUBFUN int ha_cmphashstr (ha_cdigest_t lhs, const char *rhs, size_t digestlen)
 Compares a hash digest with a hexadecimal string representation.

Detailed Description

Header file for I/O operations related to hashing.

This file defines the API for handling I/O operations with hash digests, including writing digests to a file stream and outputting digests to the standard output.

Definition in file io.h.

Macro Definition Documentation

◆ ha_hash2str_bound

#define ha_hash2str_bound ( len)
Value:
((len) * 2)

Definition at line 60 of file io.h.

◆ HA_IO_ENDLINE

#define HA_IO_ENDLINE   HA_IO_ENDLINE_LF

Definition at line 24 of file io.h.

◆ HA_IO_ENDLINE_CRLF

#define HA_IO_ENDLINE_CRLF   "\r\n"

Definition at line 23 of file io.h.

◆ HA_IO_ENDLINE_LF

#define HA_IO_ENDLINE_LF   "\n"

Definition at line 22 of file io.h.

◆ ha_str2hash_bound

#define ha_str2hash_bound ( len)
Value:
((len) / 2)

Definition at line 61 of file io.h.

◆ ha_strhash_bound

#define ha_strhash_bound ( len)
Value:
#define ha_hash2str_bound(len)
Definition io.h:60

Definition at line 63 of file io.h.

Function Documentation

◆ ha_cmphash()

HA_PUBFUN int ha_cmphash ( ha_cdigest_t lhs,
ha_cdigest_t rhs,
size_t digestlen )

Compares two hash digests byte by byte.

This function compares two hash digests (byte arrays) of the same length. It returns 0 if the digests are equal, and a non-zero value if they are different.

Parameters
lhsThe first hash digest to compare.
rhsThe second hash digest to compare.
digestlenThe length of the hash digests.
Returns
0 if the digests are equal, or a non-zero value if they are different.

◆ ha_cmphashstr()

HA_PUBFUN int ha_cmphashstr ( ha_cdigest_t lhs,
const char * rhs,
size_t digestlen )

Compares a hash digest with a hexadecimal string representation.

This function compares a hash digest (byte array) with a hexadecimal string. It first converts the hash digest to its string representation and then compares the resulting string with the given hexadecimal string.

Parameters
lhsThe hash digest to compare.
rhsThe hexadecimal string to compare with.
digestlenThe length of the hash digest.
Returns
0 if the digest and string are equal, or a non-zero value if they are different.

◆ ha_fputhash()

HA_PUBFUN size_t ha_fputhash ( FILE * stream,
ha_cdigest_t digest,
size_t digestlen,
const char * end )

Writes the hash digest to the specified file stream.

This function writes the given hash digest to the provided file stream. It is useful for storing hash digests in files for later verification or comparison.

Parameters
streamThe file stream to write the digest to.
digestThe hash digest to write.
digestlenThe length of the hash digest.
endIt will be printed at the end, unless of course it is NULL
Returns
The number of bytes written, or 0 on failure.

◆ ha_hash2str()

HA_PUBFUN size_t ha_hash2str ( char * dst,
ha_cdigest_t src,
size_t len )

Converts a hash digest to a hexadecimal string representation.

This function converts the given hash digest (byte array) into a hexadecimal string and stores it in the provided dst buffer. Each byte of the digest is converted to a two-character hexadecimal representation.

Parameters
dstThe destination buffer to store the hexadecimal string.
srcThe hash digest (byte array) to convert.
lenThe length of the hash digest.
Returns
The number of characters written to dst.

◆ ha_puthash()

HA_PUBFUN size_t ha_puthash ( ha_cdigest_t digest,
size_t digestlen,
const char * end )

Outputs the hash digest to standard output.

This function outputs the given hash digest to the standard output, typically for printing or displaying the result of a hash computation to the user.

Parameters
digestThe hash digest to output.
digestlenThe length of the hash digest.
endIt will be printed at the end, unless of course it is NULL
Returns
The number of bytes written, or 0 on failure.

◆ ha_str2hash()

HA_PUBFUN size_t ha_str2hash ( ha_digest_t dst,
const char * src,
size_t len )

Converts a hexadecimal string representation to a hash digest.

This function converts the provided hexadecimal string into its corresponding binary hash digest. Each byte in the resulting digest is represented by two hexadecimal characters in the input string. The conversion stops after processing len bytes (i.e. 2 * len characters from the input string), or earlier if an invalid hexadecimal digit is encountered.

Parameters
dstThe destination buffer where the binary hash digest will be stored.
srcThe source hexadecimal string to be converted. It should contain at least 2 * len valid hexadecimal characters.
lenThe expected number of bytes in the binary hash digest.
Returns
The number of bytes successfully converted and written to dst.

◆ ha_strhash()

HA_PUBFUN size_t ha_strhash ( char * dst,
ha_cdigest_t src,
size_t len )