anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

commit 376cf70c1a73f9597979d6d9b9fe0440a9691880
parent 4154ddb00341830eab3cb2fa120ef6a969b963a3
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 11 Jul 2026 11:09:15 +0200

apply result closure transformation for improved type safety

Diffstat:
Msrc/include/anastasis.h | 58++++++++++++++++++++++++++++++++++++++++++++--------------
Msrc/include/anastasis_service.h | 72+++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
Msrc/testing/testing_api_cmd_config.c | 8++++----
Msrc/testing/testing_api_cmd_policy_lookup.c | 8++++----
Msrc/testing/testing_api_cmd_policy_store.c | 8++++----
Msrc/testing/testing_api_cmd_truth_challenge.c | 6+++---
Msrc/testing/testing_api_cmd_truth_solve.c | 6+++---
Msrc/testing/testing_api_cmd_truth_store.c | 8++++----
Msrc/testing/testing_cmd_secret_share.c | 11++++++-----
Msrc/testing/testing_cmd_truth_upload.c | 8++++----
10 files changed, 133 insertions(+), 60 deletions(-)

diff --git a/src/include/anastasis.h b/src/include/anastasis.h @@ -469,8 +469,14 @@ struct ANASTASIS_VersionCheck; * @param secret_name name of the secret as chosen by the user, * or NULL if the user did not provide a name */ +#ifndef ANASTASIS_META_POLICY_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_MetaPolicyCallback. + */ +#define ANASTASIS_META_POLICY_RESULT_CLOSURE void +#endif typedef void -(*ANASTASIS_MetaPolicyCallback)(void *cls, +(*ANASTASIS_MetaPolicyCallback)(ANASTASIS_META_POLICY_RESULT_CLOSURE *cls, uint32_t version, struct GNUNET_TIME_Timestamp server_time, const struct GNUNET_HashCode *recdoc_id, @@ -498,7 +504,7 @@ ANASTASIS_recovery_get_versions ( const char *anastasis_provider_url, const struct ANASTASIS_CRYPTO_ProviderSaltP *provider_salt, ANASTASIS_MetaPolicyCallback mpc, - void *mpc_cls); + ANASTASIS_META_POLICY_RESULT_CLOSURE *mpc_cls); /** @@ -574,8 +580,14 @@ struct ANASTASIS_RecoveryInformation * @param cls closure for the callback * @param ri recovery information struct which contains the policies */ +#ifndef ANASTASIS_POLICY_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_PolicyCallback. + */ +#define ANASTASIS_POLICY_RESULT_CLOSURE void +#endif typedef void -(*ANASTASIS_PolicyCallback)(void *cls, +(*ANASTASIS_PolicyCallback)(ANASTASIS_POLICY_RESULT_CLOSURE *cls, const struct ANASTASIS_RecoveryInformation *ri); @@ -646,8 +658,14 @@ enum ANASTASIS_RecoveryStatus * @param secret contains the core secret which is passed to the user * @param secret_size defines the size of the core secret */ +#ifndef ANASTASIS_CORE_SECRET_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_CoreSecretCallback. + */ +#define ANASTASIS_CORE_SECRET_RESULT_CLOSURE void +#endif typedef void -(*ANASTASIS_CoreSecretCallback)(void *cls, +(*ANASTASIS_CoreSecretCallback)(ANASTASIS_CORE_SECRET_RESULT_CLOSURE *cls, enum ANASTASIS_RecoveryStatus rc, const void *secret, size_t secret_size); @@ -682,9 +700,9 @@ ANASTASIS_recovery_begin ( const char *anastasis_provider_url, const struct ANASTASIS_CRYPTO_ProviderSaltP *provider_salt, ANASTASIS_PolicyCallback pc, - void *pc_cls, + ANASTASIS_POLICY_RESULT_CLOSURE *pc_cls, ANASTASIS_CoreSecretCallback csc, - void *csc_cls); + ANASTASIS_CORE_SECRET_RESULT_CLOSURE *csc_cls); /** @@ -714,9 +732,9 @@ struct ANASTASIS_Recovery * ANASTASIS_recovery_deserialize (struct GNUNET_CURL_Context *ctx, const json_t *input, ANASTASIS_PolicyCallback pc, - void *pc_cls, + ANASTASIS_POLICY_RESULT_CLOSURE *pc_cls, ANASTASIS_CoreSecretCallback csc, - void *csc_cls); + ANASTASIS_CORE_SECRET_RESULT_CLOSURE *csc_cls); /** @@ -781,8 +799,14 @@ struct ANASTASIS_TruthUpload; * @param t truth object to create policies, NULL on failure * @param ud upload details, useful to continue in case of errors, NULL on success */ +#ifndef ANASTASIS_TRUTH_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_TruthCallback. + */ +#define ANASTASIS_TRUTH_RESULT_CLOSURE void +#endif typedef void -(*ANASTASIS_TruthCallback)(void *cls, +(*ANASTASIS_TruthCallback)(ANASTASIS_TRUTH_RESULT_CLOSURE *cls, struct ANASTASIS_Truth *t, const struct ANASTASIS_UploadDetails *ud); @@ -820,7 +844,7 @@ ANASTASIS_truth_upload ( uint32_t payment_years_requested, struct GNUNET_TIME_Relative pay_timeout, ANASTASIS_TruthCallback tc, - void *tc_cls); + ANASTASIS_TRUTH_RESULT_CLOSURE *tc_cls); /** @@ -866,7 +890,7 @@ ANASTASIS_truth_upload2 ( const struct ANASTASIS_CRYPTO_TruthKeyP *truth_key, const struct ANASTASIS_CRYPTO_KeyShareP *key_share, ANASTASIS_TruthCallback tc, - void *tc_cls); + ANASTASIS_TRUTH_RESULT_CLOSURE *tc_cls); /** @@ -893,7 +917,7 @@ ANASTASIS_truth_upload3 (struct GNUNET_CURL_Context *ctx, uint32_t payment_years_requested, struct GNUNET_TIME_Relative pay_timeout, ANASTASIS_TruthCallback tc, - void *tc_cls); + ANASTASIS_TRUTH_RESULT_CLOSURE *tc_cls); /** @@ -1084,8 +1108,14 @@ struct ANASTASIS_ShareResult * @param cls closure * @param sr share result */ +#ifndef ANASTASIS_SHARE_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_ShareResultCallback. + */ +#define ANASTASIS_SHARE_RESULT_CLOSURE void +#endif typedef void -(*ANASTASIS_ShareResultCallback)(void *cls, +(*ANASTASIS_ShareResultCallback)(ANASTASIS_SHARE_RESULT_CLOSURE *cls, const struct ANASTASIS_ShareResult *sr); @@ -1148,7 +1178,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx, uint32_t payment_years_requested, struct GNUNET_TIME_Relative pay_timeout, ANASTASIS_ShareResultCallback src, - void *src_cls, + ANASTASIS_SHARE_RESULT_CLOSURE *src_cls, const char *secret_name, const void *core_secret, size_t core_secret_size); diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h @@ -140,8 +140,14 @@ struct ANASTASIS_Config * @param cls closure * @param acfg configuration obtained, NULL if we could not parse it */ +#ifndef ANASTASIS_CONFIG_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_ConfigCallback. + */ +#define ANASTASIS_CONFIG_RESULT_CLOSURE void +#endif typedef void -(*ANASTASIS_ConfigCallback)(void *cls, +(*ANASTASIS_ConfigCallback)(ANASTASIS_CONFIG_RESULT_CLOSURE *cls, const struct ANASTASIS_Config *acfg); @@ -164,7 +170,7 @@ struct ANASTASIS_ConfigOperation * ANASTASIS_get_config (struct GNUNET_CURL_Context *ctx, const char *base_url, ANASTASIS_ConfigCallback cb, - void *cb_cls); + ANASTASIS_CONFIG_RESULT_CLOSURE *cb_cls); /** @@ -262,9 +268,15 @@ struct ANASTASIS_MetaDownloadDetails * @param cls closure * @param dd the response details */ +#ifndef ANASTASIS_POLICY_META_LOOKUP_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_PolicyMetaLookupCallback. + */ +#define ANASTASIS_POLICY_META_LOOKUP_RESULT_CLOSURE void +#endif typedef void (*ANASTASIS_PolicyMetaLookupCallback) ( - void *cls, + ANASTASIS_POLICY_META_LOOKUP_RESULT_CLOSURE *cls, const struct ANASTASIS_MetaDownloadDetails *dd); @@ -286,7 +298,7 @@ ANASTASIS_policy_meta_lookup ( const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub, uint32_t max_version, ANASTASIS_PolicyMetaLookupCallback cb, - void *cb_cls); + ANASTASIS_POLICY_META_LOOKUP_RESULT_CLOSURE *cb_cls); /** @@ -370,8 +382,14 @@ struct ANASTASIS_PolicyLookupOperation; * @param cls closure * @param dd the response details */ +#ifndef ANASTASIS_POLICY_LOOKUP_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_PolicyLookupCallback. + */ +#define ANASTASIS_POLICY_LOOKUP_RESULT_CLOSURE void +#endif typedef void -(*ANASTASIS_PolicyLookupCallback) (void *cls, +(*ANASTASIS_PolicyLookupCallback) (ANASTASIS_POLICY_LOOKUP_RESULT_CLOSURE *cls, const struct ANASTASIS_DownloadDetails *dd); @@ -391,7 +409,7 @@ ANASTASIS_policy_lookup ( const char *backend_url, const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub, ANASTASIS_PolicyLookupCallback cb, - void *cb_cls); + ANASTASIS_POLICY_LOOKUP_RESULT_CLOSURE *cb_cls); /** @@ -411,7 +429,7 @@ ANASTASIS_policy_lookup_version ( const char *backend_url, const struct ANASTASIS_CRYPTO_AccountPublicKeyP *anastasis_pub, ANASTASIS_PolicyLookupCallback cb, - void *cb_cls, + ANASTASIS_POLICY_LOOKUP_RESULT_CLOSURE *cb_cls, unsigned int version); @@ -541,8 +559,14 @@ struct ANASTASIS_UploadDetails * @param cls closure * @param up the decoded response body */ +#ifndef ANASTASIS_POLICY_STORE_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_PolicyStoreCallback. + */ +#define ANASTASIS_POLICY_STORE_RESULT_CLOSURE void +#endif typedef void -(*ANASTASIS_PolicyStoreCallback) (void *cls, +(*ANASTASIS_PolicyStoreCallback) (ANASTASIS_POLICY_STORE_RESULT_CLOSURE *cls, const struct ANASTASIS_UploadDetails *up); @@ -577,7 +601,7 @@ ANASTASIS_policy_store ( const struct ANASTASIS_PaymentSecretP *payment_secret, struct GNUNET_TIME_Relative payment_timeout, ANASTASIS_PolicyStoreCallback cb, - void *cb_cls); + ANASTASIS_POLICY_STORE_RESULT_CLOSURE *cb_cls); /** @@ -605,8 +629,14 @@ struct ANASTASIS_TruthStoreOperation; * @param cls closure * @param obj the response body */ +#ifndef ANASTASIS_TRUTH_STORE_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_TruthStoreCallback. + */ +#define ANASTASIS_TRUTH_STORE_RESULT_CLOSURE void +#endif typedef void -(*ANASTASIS_TruthStoreCallback) (void *cls, +(*ANASTASIS_TruthStoreCallback) (ANASTASIS_TRUTH_STORE_RESULT_CLOSURE *cls, const struct ANASTASIS_UploadDetails *up); @@ -641,7 +671,7 @@ ANASTASIS_truth_store ( uint32_t payment_years_requested, struct GNUNET_TIME_Relative payment_timeout, ANASTASIS_TruthStoreCallback cb, - void *cb_cls); + ANASTASIS_TRUTH_STORE_RESULT_CLOSURE *cb_cls); /** @@ -832,9 +862,15 @@ struct ANASTASIS_TruthChallengeOperation; * @param cls closure * @param tcd details about the key share */ +#ifndef ANASTASIS_TRUTH_CHALLENGE_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_TruthChallengeCallback. + */ +#define ANASTASIS_TRUTH_CHALLENGE_RESULT_CLOSURE void +#endif typedef void (*ANASTASIS_TruthChallengeCallback) ( - void *cls, + ANASTASIS_TRUTH_CHALLENGE_RESULT_CLOSURE *cls, const struct ANASTASIS_TruthChallengeDetails *tcd); @@ -858,7 +894,7 @@ ANASTASIS_truth_challenge ( const struct ANASTASIS_CRYPTO_TruthKeyP *truth_key, const struct ANASTASIS_PaymentSecretP *payment_secret, ANASTASIS_TruthChallengeCallback cb, - void *cb_cls); + ANASTASIS_TRUTH_CHALLENGE_RESULT_CLOSURE *cb_cls); /** @@ -964,9 +1000,15 @@ struct ANASTASIS_TruthSolveOperation; * @param cls closure * @param kdd details about the key share */ +#ifndef ANASTASIS_TRUTH_SOLVE_RESULT_CLOSURE +/** + * Type of the closure for #ANASTASIS_TruthSolveCallback. + */ +#define ANASTASIS_TRUTH_SOLVE_RESULT_CLOSURE void +#endif typedef void (*ANASTASIS_TruthSolveCallback) ( - void *cls, + ANASTASIS_TRUTH_SOLVE_RESULT_CLOSURE *cls, const struct ANASTASIS_TruthSolveReply *trs); @@ -995,7 +1037,7 @@ ANASTASIS_truth_solve ( struct GNUNET_TIME_Relative timeout, const struct GNUNET_HashCode *hashed_answer, ANASTASIS_TruthSolveCallback cb, - void *cb_cls); + ANASTASIS_TRUTH_SOLVE_RESULT_CLOSURE *cb_cls); /** diff --git a/src/testing/testing_api_cmd_config.c b/src/testing/testing_api_cmd_config.c @@ -20,6 +20,8 @@ * @author Dominik Meister */ #include "platform.h" +struct ConfigState; +#define ANASTASIS_CONFIG_RESULT_CLOSURE struct ConfigState #include "anastasis_testing_lib.h" #include <taler/taler_util.h> #include <taler/taler_testing_lib.h> @@ -60,15 +62,13 @@ struct ConfigState /** * Function called with the results of a #ANASTASIS_get_config(). * - * @param cls closure + * @param ss closure * @param config config from the server */ static void -config_cb (void *cls, +config_cb (struct ConfigState *ss, const struct ANASTASIS_Config *config) { - struct ConfigState *ss = cls; - ss->so = NULL; if (config->http_status != ss->http_status) { diff --git a/src/testing/testing_api_cmd_policy_lookup.c b/src/testing/testing_api_cmd_policy_lookup.c @@ -21,6 +21,8 @@ */ #include "platform.h" +struct PolicyLookupState; +#define ANASTASIS_POLICY_LOOKUP_RESULT_CLOSURE struct PolicyLookupState #include "anastasis_testing_lib.h" #include <taler/taler_util.h> #include <taler/taler_testing_lib.h> @@ -71,15 +73,13 @@ struct PolicyLookupState /** * Function called with the results of a #ANASTASIS_policy_lookup(). * - * @param cls closure + * @param pls closure * @param dd details about the lookup operation */ static void -policy_lookup_cb (void *cls, +policy_lookup_cb (struct PolicyLookupState *pls, const struct ANASTASIS_DownloadDetails *dd) { - struct PolicyLookupState *pls = cls; - pls->plo = NULL; if (dd->http_status != pls->http_status) { diff --git a/src/testing/testing_api_cmd_policy_store.c b/src/testing/testing_api_cmd_policy_store.c @@ -26,6 +26,8 @@ */ #include "platform.h" +struct PolicyStoreState; +#define ANASTASIS_POLICY_STORE_RESULT_CLOSURE struct PolicyStoreState #include "anastasis_testing_lib.h" #include <taler/taler_util.h> #include <taler/taler_testing_lib.h> @@ -127,15 +129,13 @@ struct PolicyStoreState /** * Function called with the results of an #ANASTASIS_policy_store() operation. * - * @param cls closure + * @param pss closure * @param ud details about the upload operation */ static void -policy_store_cb (void *cls, +policy_store_cb (struct PolicyStoreState *pss, const struct ANASTASIS_UploadDetails *ud) { - struct PolicyStoreState *pss = cls; - pss->pso = NULL; if (ud->http_status != pss->http_status) { diff --git a/src/testing/testing_api_cmd_truth_challenge.c b/src/testing/testing_api_cmd_truth_challenge.c @@ -22,6 +22,8 @@ */ #include "platform.h" +struct TruthChallengeState; +#define ANASTASIS_TRUTH_CHALLENGE_RESULT_CLOSURE struct TruthChallengeState #include "anastasis_testing_lib.h" #include <taler/taler_util.h> #include <taler/taler_testing_lib.h> @@ -92,11 +94,9 @@ struct TruthChallengeState static void -truth_challenge_cb (void *cls, +truth_challenge_cb (struct TruthChallengeState *ksls, const struct ANASTASIS_TruthChallengeDetails *tcd) { - struct TruthChallengeState *ksls = cls; - ksls->tco = NULL; if (tcd->http_status != ksls->expected_http_status) { diff --git a/src/testing/testing_api_cmd_truth_solve.c b/src/testing/testing_api_cmd_truth_solve.c @@ -22,6 +22,8 @@ */ #include "platform.h" +struct TruthSolveState; +#define ANASTASIS_TRUTH_SOLVE_RESULT_CLOSURE struct TruthSolveState #include "anastasis_testing_lib.h" #include <taler/taler_util.h> #include <taler/taler_testing_lib.h> @@ -119,11 +121,9 @@ struct TruthSolveState static void -truth_solve_cb (void *cls, +truth_solve_cb (struct TruthSolveState *ksls, const struct ANASTASIS_TruthSolveReply *tsr) { - struct TruthSolveState *ksls = cls; - ksls->tso = NULL; if (tsr->http_status != ksls->expected_http_status) { diff --git a/src/testing/testing_api_cmd_truth_store.c b/src/testing/testing_api_cmd_truth_store.c @@ -19,6 +19,8 @@ * @author Dennis Neufeld */ #include "platform.h" +struct TruthStoreState; +#define ANASTASIS_TRUTH_STORE_RESULT_CLOSURE struct TruthStoreState #include "anastasis_testing_lib.h" #include <taler/taler_util.h> #include <taler/taler_testing_lib.h> @@ -115,15 +117,13 @@ struct TruthStoreState * Function called with the results of an #ANASTASIS_truth_store() * operation. * - * @param cls closure + * @param tss closure * @param ud details about the upload operation */ static void -truth_store_cb (void *cls, +truth_store_cb (struct TruthStoreState *tss, const struct ANASTASIS_UploadDetails *ud) { - struct TruthStoreState *tss = cls; - tss->tso = NULL; if (ud->http_status != tss->http_status) { diff --git a/src/testing/testing_cmd_secret_share.c b/src/testing/testing_cmd_secret_share.c @@ -22,6 +22,8 @@ */ #include "platform.h" +struct SecretShareState; +#define ANASTASIS_SHARE_RESULT_CLOSURE struct SecretShareState #include "anastasis_testing_lib.h" #include <taler/taler_util.h> #include <taler/taler_testing_lib.h> @@ -123,15 +125,13 @@ struct SecretShareState /** * Function called with the results of a #ANASTASIS_secret_share(). * - * @param cls closure + * @param sss closure * @param sr result from the operation */ static void -secret_share_result_cb (void *cls, +secret_share_result_cb (struct SecretShareState *sss, const struct ANASTASIS_ShareResult *sr) { - struct SecretShareState *sss = cls; - sss->sso = NULL; if (sr->ss != sss->want_status) { @@ -148,7 +148,8 @@ secret_share_result_cb (void *cls, GNUNET_assert (0 < sr->details.payment_required.payment_requests_length); if (GNUNET_OK != TALER_MERCHANT_parse_pay_uri ( - sr->details.payment_required.payment_requests[0].payment_request_url, + sr->details.payment_required.payment_requests[0].payment_request_url + , &pd)) { GNUNET_break (0); diff --git a/src/testing/testing_cmd_truth_upload.c b/src/testing/testing_cmd_truth_upload.c @@ -22,6 +22,8 @@ */ #include "platform.h" +struct TruthUploadState; +#define ANASTASIS_TRUTH_RESULT_CLOSURE struct TruthUploadState #include "anastasis_testing_lib.h" #include <taler/taler_util.h> #include <taler/taler_testing_lib.h> @@ -119,17 +121,15 @@ struct TruthUploadState * Upload information * caller MUST free 't' using ANASTASIS_truth_free() * - * @param cls closure for callback + * @param tus closure for callback * @param t Truth object (contains provider url and truth public key) * @param ud upload details, useful to continue in case of errors, NULL on success */ static void -truth_upload_cb (void *cls, +truth_upload_cb (struct TruthUploadState *tus, struct ANASTASIS_Truth *t, const struct ANASTASIS_UploadDetails *ud) { - struct TruthUploadState *tus = cls; - tus->tuo = NULL; if (NULL == ud) {