summaryrefslogtreecommitdiff
path: root/src/util/extension_age_restriction.c
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2022-01-11 15:24:43 +0100
committerÖzgür Kesim <oec-taler@kesim.org>2022-01-21 15:41:02 +0100
commit0b56de6c994d3e525aa2d0195ff4607db3f14715 (patch)
tree9f34c40155dd5538841497c9f6a151deb2305a8d /src/util/extension_age_restriction.c
parent0b6ebc6160f1fd1f6db7c433f0912b5d2845a59c (diff)
downloadexchange-0b56de6c994d3e525aa2d0195ff4607db3f14715.tar.gz
exchange-0b56de6c994d3e525aa2d0195ff4607db3f14715.tar.bz2
exchange-0b56de6c994d3e525aa2d0195ff4607db3f14715.zip
[age restriction] progress 12/n
- taler-offline-tool now handles extensions - command "extensions" added with subcommands "show" and "sign" - parses extensions from taler config - shows and signs of extensions and their configurations - creates signed set of configurations for upload - added test for retrieval of extension config - simplified signature verification for extensions - remove per-extension signatures, also from DB schema - adjust prepared statements accordingly - adjust DB event handler for extensions - allow NULL for config for extension in DB schema - handler for /management/extensions adjusted to new datastructures - changed test for TALER_denom_blind/TALER_denom_sign_blinded with and without TALER_AgeHash - minor updates and various fixes
Diffstat (limited to 'src/util/extension_age_restriction.c')
-rw-r--r--src/util/extension_age_restriction.c75
1 files changed, 31 insertions, 44 deletions
diff --git a/src/util/extension_age_restriction.c b/src/util/extension_age_restriction.c
index b29a8ca88..0b04c7d7b 100644
--- a/src/util/extension_age_restriction.c
+++ b/src/util/extension_age_restriction.c
@@ -30,12 +30,12 @@
* @return Error if extension for age restriction was set, but age groups were
* invalid, OK otherwise.
*/
-enum TALER_Extension_ReturnValue
+enum GNUNET_GenericReturnValue
TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct TALER_AgeMask *mask)
{
char *groups;
- enum TALER_Extension_ReturnValue ret = TALER_Extension_ERROR_SYS;
+ enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
if ((GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg,
TALER_EXTENSION_SECTION_AGE_RESTRICTION,
@@ -46,7 +46,7 @@ TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
{
/* Age restriction is not enabled */
mask->mask = 0;
- return TALER_Extension_OK;
+ return GNUNET_OK;
}
/* Age restriction is enabled, extract age groups */
@@ -56,13 +56,13 @@ TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
&groups))
{
/* FIXME: log error? */
- return TALER_Extension_ERROR_SYS;
+ return GNUNET_SYSERR;
}
if (groups == NULL)
{
/* No groups defined in config, return default_age_mask */
mask->mask = TALER_EXTENSION_DEFAULT_AGE_MASK;
- return TALER_Extension_OK;
+ return GNUNET_OK;
}
ret = TALER_parse_age_group_string (groups, mask);
@@ -79,59 +79,46 @@ TALER_get_age_mask (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @param[out] mask Bit representation of the age groups.
* @return Error if string was invalid, OK otherwise.
*/
-enum TALER_Extension_ReturnValue
+enum GNUNET_GenericReturnValue
TALER_parse_age_group_string (const char *groups,
struct TALER_AgeMask *mask)
{
- enum TALER_Extension_ReturnValue ret = TALER_Extension_ERROR_SYS;
- char *pos;
+
+ const char *pos = groups;
unsigned int prev = 0;
- unsigned int val;
- char dummy;
+ unsigned int val = 0;
+ char c;
- while (1)
+ while (*pos)
{
- pos = strchr (groups, ':');
- if (NULL != pos)
+ c = *pos++;
+ if (':' == c)
{
- *pos = 0;
- }
+ if (prev >= val)
+ return GNUNET_SYSERR;
- if (1 != sscanf (groups,
- "%u%c",
- &val,
- &dummy))
- {
- /* Invalid input */
- mask->mask = 0;
- ret = TALER_Extension_ERROR_PARSING;
- break;
- }
- else if ((0 >= val) || (32 <= val) || (prev >= val))
- {
- /* Invalid value */
- mask->mask = 0;
- ret = TALER_Extension_ERROR_INVALID;
- break;
+ mask->mask |= 1 << val;
+ prev = val;
+ val = 0;
+ continue;
}
- /* Set the corresponding bit in the mask */
- mask->mask |= 1 << val;
+ if ('0'>c || '9'<c)
+ return GNUNET_SYSERR;
- if (NULL == pos)
- {
- /* We reached the end. Mark zeroth age-group and exit. */
- mask->mask |= 1;
- ret = TALER_Extension_OK;
- break;
- }
+ val = 10 * val + c - '0';
- prev = val;
- *pos = ':';
- groups = pos + 1;
+ if (0>=val || 32<=val)
+ return GNUNET_SYSERR;
}
- return ret;
+ if (0>val || 32<=val || prev>=val)
+ return GNUNET_SYSERR;
+
+ mask->mask |= (1 << val);
+ mask->mask |= 1; // mark zeroth group, too
+
+ return GNUNET_OK;
}