diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/taler_crypto_lib.h | 35 | ||||
-rw-r--r-- | src/include/taler_exchange_service.h | 154 | ||||
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 166 | ||||
-rw-r--r-- | src/include/taler_testing_lib.h | 17 | ||||
-rw-r--r-- | src/include/taler_util.h | 60 |
5 files changed, 323 insertions, 109 deletions
diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index ea53c2fcb..3ad441cb9 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -439,7 +439,9 @@ struct TALER_AgeCommitmentPublicKeyP /* - * @brief Hash to represent the commitment to n*kappa blinded keys during a age-withdrawal. + * @brief Hash to represent the commitment to n*kappa blinded keys during a + * age-withdrawal. It is the running SHA512 hash over the hashes of the blinded + * envelopes of n*kappa coins. */ struct TALER_AgeWithdrawCommitmentHashP { @@ -3726,9 +3728,10 @@ TALER_wallet_withdraw_verify ( /** * Sign age-withdraw request. * - * @param h_commitment hash all n*kappa blinded coins in the commitment for the age-withdraw + * @param h_commitment hash over all n*kappa blinded coins in the commitment for the age-withdraw * @param amount_with_fee amount to debit the reserve for - * @param max_age_group maximum age group that the withdrawn coins must be restricted to + * @param mask the mask that defines the age groups + * @param max_age maximum age from which the age group is derived, that the withdrawn coins must be restricted to. * @param reserve_priv private key to sign with * @param[out] reserve_sig resulting signature */ @@ -3736,7 +3739,8 @@ void TALER_wallet_age_withdraw_sign ( const struct TALER_AgeWithdrawCommitmentHashP *h_commitment, const struct TALER_Amount *amount_with_fee, - uint32_t max_age_group, + const struct TALER_AgeMask *mask, + uint8_t max_age, const struct TALER_ReservePrivateKeyP *reserve_priv, struct TALER_ReserveSignatureP *reserve_sig); @@ -3745,7 +3749,8 @@ TALER_wallet_age_withdraw_sign ( * * @param h_commitment hash all n*kappa blinded coins in the commitment for the age-withdraw * @param amount_with_fee amount to debit the reserve for - * @param max_age_group maximum age group that the withdrawn coins must be restricted to + * @param mask the mask that defines the age groups + * @param max_age maximum age from which the age group is derived, that the withdrawn coins must be restricted to. * @param reserve_pub public key of the reserve * @param reserve_sig resulting signature * @return #GNUNET_OK if the signature is valid @@ -3754,11 +3759,11 @@ enum GNUNET_GenericReturnValue TALER_wallet_age_withdraw_verify ( const struct TALER_AgeWithdrawCommitmentHashP *h_commitment, const struct TALER_Amount *amount_with_fee, - uint32_t max_age_group, + const struct TALER_AgeMask *mask, + uint8_t max_age, const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReserveSignatureP *reserve_sig); - /** * Verify exchange melt confirmation. * @@ -4867,6 +4872,22 @@ TALER_exchange_online_age_withdraw_confirmation_sign ( struct TALER_ExchangeSignatureP *sig); +/** + * Verfiy an exchange age-withdraw confirmation + * + * @param h_commitment Commitment over all n*kappa coin candidates from the original request to age-withdraw + * @param noreveal_index The index returned by the exchange + * @param exchange_pub The public key used for signing + * @param exchange_sig The signature from the exchange + */ +enum GNUNET_GenericReturnValue +TALER_exchange_online_age_withdraw_confirmation_verify ( + const struct TALER_AgeWithdrawCommitmentHashP *h_commitment, + uint32_t noreveal_index, + const struct TALER_ExchangePublicKeyP *exchange_pub, + const struct TALER_ExchangeSignatureP *exchange_sig); + + /* ********************* offline signing ************************** */ diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index bc6a230b6..d4efc15d5 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -18,6 +18,7 @@ * @brief C interface of libtalerexchange, a C library to use exchange's HTTP API * @author Sree Harsha Totakura <sreeharsha@totakura.in> * @author Christian Grothoff + * @author Özgür Kesim */ #ifndef _TALER_EXCHANGE_SERVICE_H #define _TALER_EXCHANGE_SERVICE_H @@ -1618,7 +1619,8 @@ typedef void /** * Get a CS R using a /csr-withdraw request. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl context to use for the requests + * @param exchange_url Base-URL to the excnange * @param pk Which denomination key is the /csr request for * @param nonce client nonce for the request * @param res_cb the callback to call when the final result for this request is available @@ -1629,7 +1631,8 @@ typedef void */ struct TALER_EXCHANGE_CsRWithdrawHandle * TALER_EXCHANGE_csr_withdraw ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *curl_ctx, + const char *exchange_url, const struct TALER_EXCHANGE_DenomPublicKey *pk, const struct TALER_CsNonce *nonce, TALER_EXCHANGE_CsRWithdrawCallback res_cb, @@ -2448,7 +2451,9 @@ typedef void * disk before calling, and be ready to repeat the request with the * same arguments in case of failures. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl context to use + * @param exchange_url The base-URL of the exchange + * @param keys The /keys material from the exchange * @param reserve_priv private key of the reserve to withdraw from * @param wci inputs that determine the planchet * @param res_cb the callback to call when the final result for this request is available @@ -2459,7 +2464,9 @@ typedef void */ struct TALER_EXCHANGE_WithdrawHandle * TALER_EXCHANGE_withdraw ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *curl_ctx, + const char *exchange_url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_EXCHANGE_WithdrawCoinInput *wci, TALER_EXCHANGE_WithdrawCallback res_cb, @@ -2575,7 +2582,9 @@ typedef void * disk before calling, and be ready to repeat the request with the * same arguments in case of failures. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl context to use + * @param exchange_url The base-URL of the exchange + * @param keys The /keys material from the exchange * @param reserve_priv private key of the reserve to withdraw from * @param wcis inputs that determine the planchets * @param wci_length number of entries in @a wcis @@ -2587,7 +2596,9 @@ typedef void */ struct TALER_EXCHANGE_BatchWithdrawHandle * TALER_EXCHANGE_batch_withdraw ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *curl_ctx, + const char *exchange_url, + const struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_EXCHANGE_WithdrawCoinInput *wcis, unsigned int wci_length, @@ -2668,7 +2679,9 @@ struct TALER_EXCHANGE_Withdraw2Handle; * disk before calling, and be ready to repeat the request with the * same arguments in case of failures. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl-context to use + * @param exchange_url The base-URL of the exchange + * @param keys The /keys material from the exchange * @param pd planchet details of the planchet to withdraw * @param reserve_priv private key of the reserve to withdraw from * @param res_cb the callback to call when the final result for this request is available @@ -2679,7 +2692,9 @@ struct TALER_EXCHANGE_Withdraw2Handle; */ struct TALER_EXCHANGE_Withdraw2Handle * TALER_EXCHANGE_withdraw2 ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *curl_ctx, + const char *exchange_url, + struct TALER_EXCHANGE_Keys *keys, const struct TALER_PlanchetDetail *pd, const struct TALER_ReservePrivateKeyP *reserve_priv, TALER_EXCHANGE_Withdraw2Callback res_cb, @@ -2765,7 +2780,9 @@ struct TALER_EXCHANGE_BatchWithdraw2Handle; * disk before calling, and be ready to repeat the request with the * same arguments in case of failures. * - * @param exchange the exchange handle; the exchange must be ready to operate + * @param curl_ctx The curl context to use + * @param exchange_url The base-URL of the exchange + * @param keys The /keys material from the exchange * @param pds array of planchet details of the planchet to withdraw * @param pds_length number of entries in the @a pds array * @param reserve_priv private key of the reserve to withdraw from @@ -2777,7 +2794,9 @@ struct TALER_EXCHANGE_BatchWithdraw2Handle; */ struct TALER_EXCHANGE_BatchWithdraw2Handle * TALER_EXCHANGE_batch_withdraw2 ( - struct TALER_EXCHANGE_Handle *exchange, + struct GNUNET_CURL_Context *curl_ctx, + const char *exchange_url, + const struct TALER_EXCHANGE_Keys *keys, const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_PlanchetDetail *pds, unsigned int pds_length, @@ -2796,6 +2815,119 @@ TALER_EXCHANGE_batch_withdraw2_cancel ( struct TALER_EXCHANGE_BatchWithdraw2Handle *wh); +/* ********************* /reserve/$RESERVE_PUB/age-withdraw *************** */ + +/** + * @brief Information needed to withdraw age restricted coins. + */ +struct TALER_EXCHANGE_AgeWithdrawCoinInput +{ + /* The master secret from which we derive all other relevant values for + * the coin: private key, nonces (if applicable) and age restriction + */ + const struct TALER_PlanchetMasterSecretP secret[TALER_CNC_KAPPA]; + + /* The denomination of the coin. Must support age restriction, i.e + * its .keys.age_mask MUST not be 0 */ + const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; +}; + +/** + * @brief A handle to a /reserves/$RESERVE_PUB/age-withdraw request + */ +struct TALER_EXCHANGE_AgeWithdrawHandle; + +/** + * @brief Details about the response for a age withdraw request. + */ +struct TALER_EXCHANGE_AgeWithdrawResponse +{ + /** + * HTTP response data. + */ + struct TALER_EXCHANGE_HttpResponse hr; + + /** + * Details about the response + */ + union + { + /** + * Details if the status is #MHD_HTTP_OK. + */ + struct + { + /** + * Index that should not be revealed during the age-withdraw reveal phase. + * The struct TALER_PlanchetMasterSecretP * from the request + * with this index are the ones to keep. + */ + uint8_t noreveal_index; + + /** + * Signature of the exchange over the origina TALER_AgeWithdrawRequestPS + */ + struct TALER_ExchangeSignatureP exchange_sig; + + /** + * Key used by the exchange for @e exchange_sig + */ + struct TALER_ExchangePublicKeyP exchange_pub; + + } ok; + /* FIXME[oec]: error cases */ + } details; +}; + +typedef void +(*TALER_EXCHANGE_AgeWithdrawCallback)( + void *cls, + const struct TALER_EXCHANGE_AgeWithdrawResponse *awr); + +/** + * Submit an age-withdraw request to the exchange and get the exchange's + * response. + * + * This API is typically used by a wallet. Note that to ensure that + * no money is lost in case of hardware failures, the provided + * argument @a rd should be committed to persistent storage + * prior to calling this function. + * + * @param curl_ctx The curl context + * @param exchange_url The base url of the exchange + * @parm keys The denomination keys from the exchange + * @param reserve_priv The pivate key to the reserve + * @param coin_inputs The input for the coins to withdraw + * @param num_coins The number of elements in @e coin_inputs + * @param max_age The maximum age we commit to. + * @param res_cb A callback for the result, maybe NULL + * @param res_cb_cls A closure for @e res_cb, maybe NULL + * @return a handle for this request; NULL if the argument was invalid. + * In this case, the callback will not be called. + */ +struct TALER_EXCHANGE_AgeWithdrawHandle * +TALER_EXCHANGE_age_withdraw ( + struct GNUNET_CURL_Context *curl_ctx, + const char *exchange_url, + struct TALER_EXCHANGE_Keys *keys, + const struct TALER_ReservePrivateKeyP *reserve_priv, + const struct TALER_EXCHANGE_AgeWithdrawCoinInput *coin_inputs, + size_t num_coins, + uint8_t max_age, + TALER_EXCHANGE_AgeWithdrawCallback res_cb, + void *res_cb_cls); + +/** + * Cancel a age-withdraw request. This function cannot be used + * on a request handle if a response is already served for it. + * + * @param awh the age-withdraw handle + */ +void +TALER_EXCHANGE_age_withdraw_cancel ( + struct TALER_EXCHANGE_AgeWithdrawHandle *awh); + + /* ********************* /refresh/melt+reveal ***************************** */ @@ -3565,7 +3697,7 @@ TALER_EXCHANGE_verify_coin_history ( */ enum GNUNET_GenericReturnValue TALER_EXCHANGE_parse_reserve_history ( - struct TALER_EXCHANGE_Keys *keys, + const struct TALER_EXCHANGE_Keys *keys, const json_t *history, const struct TALER_ReservePublicKeyP *reserve_pub, const char *currency, diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 5404f0b16..1b1a657c2 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -301,8 +301,7 @@ enum TALER_EXCHANGEDB_ReplicatedTable TALER_EXCHANGEDB_RT_AML_HISTORY, TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES, TALER_EXCHANGEDB_RT_PURSE_DELETION, - TALER_EXCHANGEDB_RT_WITHDRAW_AGE_COMMITMENTS, - TALER_EXCHANGEDB_RT_WITHDRAW_AGE_REVEALED_COINS, + TALER_EXCHANGEDB_RT_AGE_WITHDRAW, }; @@ -773,22 +772,14 @@ struct TALER_EXCHANGEDB_TableData struct TALER_AgeWithdrawCommitmentHashP h_commitment; struct TALER_Amount amount_with_fee; uint16_t max_age; + uint32_t noreveal_index; struct TALER_ReservePublicKeyP reserve_pub; struct TALER_ReserveSignatureP reserve_sig; - uint32_t noreveal_index; - struct GNUNET_TIME_Absolute timestamp; - } age_withdraw_commitments; - - struct - { - struct TALER_AgeWithdrawCommitmentHashP h_commitment; - uint32_t freshcoin_index; - uint64_t denominations_serial; - void *coin_ev; - size_t coin_ev_size; - // h_coin_ev omitted, to be recomputed! - struct TALER_BlindedDenominationSignature ev_sig; - } age_withdraw_revealed_coins; + uint64_t num_coins; + uint64_t *denominations_serials; + void *h_blind_evs; + struct TALER_BlindedDenominationSignature denom_sigs; + } age_withdraw; } details; @@ -949,6 +940,13 @@ struct TALER_EXCHANGEDB_Reserve struct TALER_EXCHANGEDB_DenominationKeyMetaData { /** + * Serial of the denomination key as in the DB. + * Can be used in calls to stored procedures in order to spare + * additional lookups. + */ + uint64_t serial; + + /** * Start time of the validity period for this key. */ struct GNUNET_TIME_Timestamp start; @@ -1182,11 +1180,11 @@ struct TALER_EXCHANGEDB_CollectableBlindcoin /** - * @brief Information we keep for an age-withdraw commitment + * @brief Information we keep for an age-withdraw request * to reproduce the /age-withdraw operation if needed, and to have proof * that a reserve was drained by this amount. */ -struct TALER_EXCHANGEDB_AgeWithdrawCommitment +struct TALER_EXCHANGEDB_AgeWithdraw { /** * Total amount (with fee) committed to withdraw @@ -1194,7 +1192,7 @@ struct TALER_EXCHANGEDB_AgeWithdrawCommitment struct TALER_Amount amount_with_fee; /** - * Maximum age that the coins are restricted to. + * Maximum age (in years) that the coins are restricted to. */ uint16_t max_age; @@ -1208,7 +1206,7 @@ struct TALER_EXCHANGEDB_AgeWithdrawCommitment * revealed during cut and choose. This value applies to all n coins in the * commitment. */ - uint32_t noreveal_index; + uint16_t noreveal_index; /** * Public key of the reserve that was drained. @@ -1217,15 +1215,40 @@ struct TALER_EXCHANGEDB_AgeWithdrawCommitment /** * Signature confirming the age withdrawal commitment, matching @e - * reserve_pub, @e maximum_age_group and @e h_commitment and @e - * total_amount_with_fee. + * reserve_pub, @e max_age and @e h_commitment and @e amount_with_fee. */ struct TALER_ReserveSignatureP reserve_sig; /** - * The exchange's signature of the response. + * Number of coins to be withdrawn. */ - struct TALER_ExchangeSignatureP sig; + size_t num_coins; + + /** + * Array of @a num_coins blinded coins. These are the chosen coins + * (according to @a noreveal_index) from the request, which contained + * kappa*num_coins blinded coins. + */ + struct TALER_BlindedCoinHashP *h_coin_evs; + + /** + * Array of @a num_coins denomination signatures of the blinded coins @a + * h_coin_evs. + */ + struct TALER_BlindedDenominationSignature *denom_sigs; + + /** + * Array of @a num_coins serial id's of the denominations, corresponding to + * the coins in @a h_coin_evs. + */ + uint64_t *denom_serials; + + /** + * [out]-Array of @a num_coins hashes of the public keys of the denominations + * identified by @e denom_serials. This field is set when calling + * get_age_withdraw + */ + struct TALER_DenominationHashP *denom_pub_hashes; }; @@ -2751,28 +2774,6 @@ struct TALER_EXCHANGEDB_CsRevealFreshCoinData uint32_t coin_off; }; -/** - * Information about a coin that was revealed to the exchange - * during reveal. - */ -struct TALER_EXCHANGEDB_AgeWithdrawRevealedCoin -{ - /** - * Hash of the public denomination key of the coin. - */ - struct TALER_DenominationHashP h_denom_pub; - - /** - * Signature generated by the exchange over the coin (in blinded format). - */ - struct TALER_BlindedDenominationSignature coin_sig; - - /** - * Blinded hash of the new coin - */ - struct TALER_BlindedCoinHashP h_coin_ev; -}; - /** * Generic KYC status for some operation. @@ -3761,6 +3762,15 @@ struct TALER_EXCHANGEDB_Plugin /** + * FIXME: merge do_batch_withdraw and do_batch_withdraw_insert into one API, + * which takes as input (among others) + * - denom_serial[] + * - blinded_coin_evs[] + * - denom_sigs[] + * The implementation should persist the data as _arrays_ in the DB. + */ + + /** * Perform reserve update as part of a batch withdraw operation, checking * for sufficient balance. Persisting the withdrawal details is done * separately! @@ -3769,8 +3779,11 @@ struct TALER_EXCHANGEDB_Plugin * @param now current time (rounded) * @param reserve_pub public key of the reserve to debit * @param amount total amount to withdraw + * @param do_age_check if set, the batch-withdrawal can only succeed when the reserve has no age restriction (birthday) set. * @param[out] found set to true if the reserve was found * @param[out] balance_ok set to true if the balance was sufficient + * @param[out] age_ok set to true if no age requirements were defined on the reserve or @e do_age_check was false + * @param[out] allowed_maximum_age when @e age_ok is false, set to the allowed maximum age for withdrawal from the reserve. The client MUST then use the age-withdraw endpoint * @param[out] ruuid set to the reserve's UUID (reserves table row) * @return query execution status */ @@ -3780,8 +3793,11 @@ struct TALER_EXCHANGEDB_Plugin struct GNUNET_TIME_Timestamp now, const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_Amount *amount, + bool do_age_check, bool *found, bool *balance_ok, + bool *age_ok, + uint16_t *allowed_maximum_age, uint64_t *ruuid); @@ -3811,72 +3827,46 @@ struct TALER_EXCHANGEDB_Plugin bool *nonce_reuse); /** - * Locate the response for a age-withdraw request under a hash that uniquely - * identifies the age-withdraw operation. Used to ensure idempotency of the - * request. + * Locate the response for a age-withdraw request under a hash of the + * commitment and reserve_pub that uniquely identifies the age-withdraw + * operation. Used to ensure idempotency of the request. * * @param cls the @e cls of this struct with the plugin-specific state * @param reserve_pub public key of the reserve for which the age-withdraw request is made * @param ach hash that uniquely identifies the age-withdraw operation - * @param[out] awc corresponding details of the previous age-withdraw request if an entry was found + * @param[out] aw corresponding details of the previous age-withdraw request if an entry was found * @return statement execution status */ enum GNUNET_DB_QueryStatus - (*get_age_withdraw_info)( + (*get_age_withdraw)( void *cls, const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_AgeWithdrawCommitmentHashP *ach, - struct TALER_EXCHANGEDB_AgeWithdrawCommitment *awc); + struct TALER_EXCHANGEDB_AgeWithdraw *aw); /** - * Perform an age-withdraw operation, checking for sufficient balance - * and possibly persisting the withdrawal details. + * Perform an age-withdraw operation, checking for sufficient balance and + * fulfillment of age requirements and possibly persisting the withdrawal + * details. * * @param cls the `struct PostgresClosure` with the plugin-specific state * @param commitment corresponding commitment for the age-withdraw * @param[out] found set to true if the reserve was found * @param[out] balance_ok set to true if the balance was sufficient - * @param[out] ruuid set to the reserve's UUID (reserves table row) + * @param[out] age_ok set to true if age requirements were met + * @param[out] allowed_maximum_age if @e age_ok is FALSE, this is set to the allowed maximum age * @return query execution status */ enum GNUNET_DB_QueryStatus (*do_age_withdraw)( void *cls, - const struct TALER_EXCHANGEDB_AgeWithdrawCommitment *commitment, + const struct TALER_EXCHANGEDB_AgeWithdraw *commitment, + struct GNUNET_TIME_Timestamp now, bool *found, bool *balance_ok, - uint64_t *ruuid); - - /** - * Store in the database which coin(s) the wallet wanted to withdraw with - * age restriction enabled in a given age-withdraw operation and the relevant - * information we learned or created in the reveal steop - * - * @param cls The `struct PostgresClosure` with the plugin-specific state - * @param h_commitment The hash of the original age-withdraw commitment, which is a key into the age_withdraw_commitments table - * @param num_awrcs Number of coins to generate, size of the @a coin_evs array - * @param awrcs Array of @a num_awrcs information about coins to be created - * @return query execution status - */ - enum GNUNET_DB_QueryStatus - (*insert_age_withdraw_reveal)( - void *cls, - const struct TALER_AgeWithdrawCommitmentHashP *h_commitment, - uint32_t num_awrcs, - const struct TALER_EXCHANGEDB_AgeWithdrawRevealedCoin *awrcs); - - /** - * Lookup in the database for the fresh coins with age-restriction that - * we created in the given age-withdraw operation. - * - * TODO: oec - */ - enum GNUNET_DB_QueryStatus - (*get_age_withdraw_reveal)( - void *cls, - uint64_t h_commitment - /* TODO: oec */ - ); + bool *age_ok, + uint16_t *allowed_maximum_age, + bool *conflict); /** * Retrieve the details to a policy given by its hash_code diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 2ef7ef602..8950e71ba 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -2243,14 +2243,25 @@ TALER_TESTING_cmd_proof_kyc_oauth2 ( /** * Starts a fake OAuth 2.0 service on @a port for testing - * KYC processes. + * KYC processes which also provides a @a birthdate in a response * * @param label command label * @param port the TCP port to listen on */ struct TALER_TESTING_Command -TALER_TESTING_cmd_oauth (const char *label, - uint16_t port); +TALER_TESTING_cmd_oauth_with_birthdate (const char *label, + const char *birthdate, + uint16_t port); + +/** + * Starts a fake OAuth 2.0 service on @a port for testing + * KYC processes. + * + * @param label command label + * @param port the TCP port to listen on + */ +#define TALER_TESTING_cmd_oauth(label, port) \ + TALER_TESTING_cmd_oauth_with_birthdate ((label), NULL, (port)) /* ****************** P2P payment commands ****************** */ diff --git a/src/include/taler_util.h b/src/include/taler_util.h index 1de264c12..e0473bff7 100644 --- a/src/include/taler_util.h +++ b/src/include/taler_util.h @@ -21,6 +21,7 @@ #ifndef TALER_UTIL_H #define TALER_UTIL_H +#include <gnunet/gnunet_common.h> #define __TALER_UTIL_LIB_H_INSIDE__ #include <gnunet/gnunet_util_lib.h> @@ -511,6 +512,33 @@ char *strchrnul (const char *s, int c); #endif /** + * @brief Parses a date information into days after 1970-01-01 (or 0) + * + * The input MUST be of the form + * + * 1) YYYY-MM-DD, representing a valid date + * 2) YYYY-MM-00, representing a valid month in a particular year + * 3) YYYY-00-00, representing a valid year. + * + * In the cases 2) and 3) the out parameter is set to the beginning of the + * time, f.e. 1950-00-00 == 1950-01-01 and 1888-03-00 == 1888-03-01 + * + * The output will set to the number of days after 1970-01-01 or 0, if the input + * represents a date belonging to the largest allowed age group. + * + * @param in Input string representation of the date + * @param mask Age mask + * @param[out] out Where to write the result + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +enum GNUNET_GenericReturnValue +TALER_parse_coarse_date ( + const char *in, + const struct TALER_AgeMask *mask, + uint32_t *out); + + +/** * @brief Parses a string as a list of age groups. * * The string must consist of a colon-separated list of increasing integers @@ -558,6 +586,18 @@ char * TALER_age_mask_to_string ( const struct TALER_AgeMask *mask); +/* + * @brief returns the age group of a given age for a given age mask + * + * @param mask Age mask + * @param age The given age + * @return age group + */ +uint8_t +TALER_get_age_group ( + const struct TALER_AgeMask *mask, + uint8_t age); + /** * @brief Parses a JSON object { "age_groups": "a:b:...y:z" }. * @@ -570,6 +610,26 @@ TALER_JSON_parse_age_groups (const json_t *root, struct TALER_AgeMask *mask); +/* @brief Return the lowest age in the corresponding group for a given age + * according the given age mask. + * + * @param[IN] mask age mask + * @param[IN] age age to check + * @return lowest age in corresponding age group + */ +uint8_t +TALER_get_lowest_age ( + const struct TALER_AgeMask *mask, + uint8_t age); + +/* @brief Get the lowest age for the largest age group + * + * @param mask the age mask + * @return lowest age for the largest age group + */ +#define TALER_adult_age(mask) \ + sizeof((mask)->bits) * 8 - __builtin_clz ((mask)->bits) - 1 + /** * Handle to an external process that will assist * with some JSON-to-JSON conversion. |