11#ifndef LIBACQUIRE_ACQUIRE_CHECKSUMS_H
22#define LIBACQUIRE_ACQUIRE_CHECKSUMS_H
33
4- /**
5- * @file acquire_checksums.h
6- * @brief Collection of checksum function declarations and interface.
7- *
8- * This header declares typedefs and functions for computing and verifying
9- * various checksum algorithms like crc32c, md5, sha1, etc.
10- * Also provides functionality to get checksum function by name.
11- *
12- * NOTE: Always `#include` this when adding new checksum implementations,
13- * to ensure the implementation matches the prototype.
14- */
15-
164#ifdef __cplusplus
175extern "C" {
186#endif /* __cplusplus */
197
8+ #include "acquire_handle.h"
209#include "libacquire_export.h"
21- #if defined(HAS_STDBOOL ) && !defined(bool )
22- #include <stdbool.h>
23- #else
24- #include "acquire_stdbool.h"
25- #endif
26- #include "acquire_config.h"
27- #include "acquire_string_extras.h"
2810
2911/**
30- * @brief Boolean result type alias for checksum validation functions .
12+ * @brief Enumeration of supported checksum algorithms .
3113 */
14+ enum Checksum {
15+ LIBACQUIRE_CRC32C ,
16+ LIBACQUIRE_SHA256 ,
17+ LIBACQUIRE_SHA512 ,
18+ LIBACQUIRE_UNSUPPORTED_CHECKSUM
19+ };
3220
3321/**
34- * @brief Verify file using CRC32C checksum.
35- *
36- * @param filename Path to file.
37- * @param hash Expected CRC32C checksum string.
38- *
39- * @return true if valid.
22+ * @brief Converts a string name (e.g., "sha256") to a Checksum enum.
23+ * @return The corresponding enum, or LIBACQUIRE_UNSUPPORTED_CHECKSUM.
4024 */
41- extern LIBACQUIRE_EXPORT bool crc32c (const char * filename , const char * hash );
25+ extern LIBACQUIRE_EXPORT enum Checksum string2checksum (const char * );
26+
27+ /* --- Asynchronous Verification API --- */
4228
4329/**
44- * @brief Verify file using SHA256 checksum.
45- *
46- * @param filename Path to file.
47- * @param hash Expected checksum string .
48- *
49- * @return true if valid .
30+ * @brief Begins an asynchronous checksum verification (non-blocking) .
31+ * @param handle An initialized acquire handle.
32+ * @param filepath The path to the file to verify .
33+ * @param algorithm The checksum algorithm to use .
34+ * @param expected_hash The expected hexadecimal checksum string.
35+ * @return 0 on success, non-zero on failure .
5036 */
51- extern LIBACQUIRE_EXPORT bool sha256 (const char * filename , const char * hash );
37+ extern LIBACQUIRE_EXPORT int
38+ acquire_verify_async_start (struct acquire_handle * handle , const char * filepath ,
39+ enum Checksum algorithm , const char * expected_hash );
5240
5341/**
54- * @brief Verify file using SHA256 checksum.
55- *
56- * @param filename Path to file.
57- * @param hash Expected checksum string.
58- *
59- * @return true if valid.
42+ * @brief Polls the status of an asynchronous verification, processing a chunk.
43+ * @param handle The handle for the in-progress operation.
44+ * @return The current status of the operation.
6045 */
61- extern LIBACQUIRE_EXPORT bool sha512 (const char * filename , const char * hash );
46+ extern LIBACQUIRE_EXPORT enum acquire_status
47+ acquire_verify_async_poll (struct acquire_handle * handle );
6248
63- enum Checksum {
64- LIBACQUIRE_CRC32C ,
65- LIBACQUIRE_SHA256 ,
66- LIBACQUIRE_SHA512 ,
67- LIBACQUIRE_UNSUPPORTED_CHECKSUM
68- } ;
49+ /**
50+ * @brief Requests cancellation of an asynchronous verification.
51+ * @param handle The handle for the operation to be cancelled.
52+ */
53+ extern LIBACQUIRE_EXPORT void
54+ acquire_verify_async_cancel ( struct acquire_handle * handle ) ;
6955
70- extern LIBACQUIRE_EXPORT enum Checksum string2checksum ( const char * );
56+ /* --- Synchronous Verification API --- */
7157
7258/**
73- * @brief Obtain a pointer to a checksum function by name.
74- *
75- * Returns a pointer to a function matching the
76- * signature of checksum_func_t, or NULL if not found.
77- *
78- * @param checksum Discriminant from `enum Checksum` representing checksum
79- * algorithm
80- *
81- * @return Function pointer on success; NULL on failure.
59+ * @brief Verifies a file's checksum synchronously (blocking).
60+ * @return 0 if the checksum matches, -1 on failure or mismatch.
8261 */
83- extern LIBACQUIRE_EXPORT bool ( * get_checksum_function ( enum Checksum checksum ))(
84- const char * , const char * );
85-
86- #if defined( LIBACQUIRE_IMPLEMENTATION ) && defined( CHECKSUM_IMPL )
62+ extern LIBACQUIRE_EXPORT int acquire_verify_sync ( struct acquire_handle * handle ,
63+ const char * filepath ,
64+ enum Checksum algorithm ,
65+ const char * expected_hash );
8766
67+ #if defined(LIBACQUIRE_IMPLEMENTATION ) && defined(LIBACQUIRE_CHECKSUMS_IMPL )
8868enum Checksum string2checksum (const char * const s ) {
8969 if (s == NULL )
9070 return LIBACQUIRE_UNSUPPORTED_CHECKSUM ;
@@ -97,26 +77,10 @@ enum Checksum string2checksum(const char *const s) {
9777 else
9878 return LIBACQUIRE_UNSUPPORTED_CHECKSUM ;
9979}
100-
101- bool (* get_checksum_function (enum Checksum checksum ))(const char * ,
102- const char * ) {
103- switch (checksum ) {
104- case LIBACQUIRE_CRC32C :
105- return crc32c ;
106- case LIBACQUIRE_SHA256 :
107- return sha256 ;
108- case LIBACQUIRE_SHA512 :
109- return sha512 ;
110- case LIBACQUIRE_UNSUPPORTED_CHECKSUM :
111- default :
112- return NULL ;
113- }
114- }
115-
116- #endif /* defined(LIBACQUIRE_IMPLEMENTATION) && defined(CHECKSUM_IMPL) */
80+ #endif /* defined(LIBACQUIRE_IMPLEMENTATION) && \
81+ defined(LIBACQUIRE_CHECKSUMS_IMPL) */
11782
11883#ifdef __cplusplus
11984}
12085#endif /* __cplusplus */
121-
122- #endif /* ! LIBACQUIRE_ACQUIRE_CHECKSUMS_H */
86+ #endif /* !LIBACQUIRE_ACQUIRE_CHECKSUMS_H */
0 commit comments