Compare commits

..

2 Commits

Author SHA1 Message Date
9c3ddcbc18
added TALER_adult_age(struct TALER_AgeMask *mask) 2023-06-27 18:57:05 +02:00
537206e49f
-update author 2023-06-27 18:56:27 +02:00
4 changed files with 45 additions and 3 deletions

View File

@ -622,6 +622,14 @@ 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.

View File

@ -23,6 +23,7 @@
#include "taler_signatures.h"
#include <gnunet/gnunet_json_lib.h>
#include <gcrypt.h>
#include <stdint.h>
struct
#ifndef AGE_RESTRICTION_WITH_ECDSA
@ -746,7 +747,7 @@ TALER_parse_coarse_date (
/* calculate the limit date for the largest age group */
localtime_r (&(time_t){time (NULL)}, &limit);
limit.tm_year -= TALER_get_lowest_age (mask, 255);
limit.tm_year -= TALER_adult_age (mask);
GNUNET_assert (-1 != mktime (&limit));
if ((limit.tm_year < date.tm_year)

View File

@ -233,7 +233,7 @@ test_lowest (void)
{.age = 22, .expected = 21 },
};
for (uint8_t n = 0; n < 21; n++)
for (uint8_t n = 0; n < sizeof(test) / sizeof(test[0]); n++)
{
uint8_t l = TALER_get_lowest_age (&mask, test[n].age);
printf ("lowest[%d] for age %d, expected lowest: %d, got: %d\n",
@ -246,6 +246,36 @@ test_lowest (void)
}
enum GNUNET_GenericReturnValue
test_adult (void)
{
struct { struct TALER_AgeMask mask; uint8_t expected; }
test[] = {
{ .mask = {.bits = 1 | 1 << 2},
.expected = 2 },
{ .mask = {.bits = 1 | 1 << 2 | 1 << 3},
.expected = 3 },
{ .mask = {.bits = 1 | 1 << 3},
.expected = 3 },
{ .mask = {.bits = 1 | 1 << 22},
.expected = 22 },
{ .mask = {.bits = 1 | 1 << 10 | 1 << 16 | 1 << 22},
.expected = 22 },
};
for (uint8_t n = 0; n < sizeof(test) / sizeof(test[0]); n++)
{
uint8_t l = TALER_adult_age (&test[n].mask);
printf ("adult[%d] for mask %s, expected: %d, got: %d\n",
n, TALER_age_mask_to_string (&test[n].mask), test[n].expected, l);
if (test[n].expected != l)
return GNUNET_SYSERR;
}
printf ("done with adult\n");
return GNUNET_OK;
}
static struct TALER_AgeMask age_mask = {
.bits = 1 | 1 << 8 | 1 << 10 | 1 << 12 | 1 << 14 | 1 << 16 | 1 << 18 | 1 << 21
};
@ -381,6 +411,8 @@ main (int argc,
}
if (GNUNET_OK != test_dates ())
return 4;
if (GNUNET_OK != test_adult ())
return 5;
return 0;
}

View File

@ -1,6 +1,6 @@
/*
This file is part of TALER
Copyright (C) 2021, 2022 Taler Systems SA
Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@ -17,6 +17,7 @@
* @file wallet_signatures.c
* @brief Utility functions for Taler wallet signatures
* @author Christian Grothoff
* @author Özgür Kesim
*/
#include "platform.h"
#include "taler_util.h"