From c9099836f080c8bb821264050f5f6d59a1ceddba Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 9 Dec 2008 00:08:01 +0000 Subject: Add tests for X509 certificates. --- src/check.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/check.c') diff --git a/src/check.c b/src/check.c index 4c71edd..cf12dd4 100644 --- a/src/check.c +++ b/src/check.c @@ -104,6 +104,39 @@ _p11t_check_bool(const char *what, CK_BBOOL value) return CONTINUE; } +static int +atoin (const char *p, int digits) +{ + int ret = 0, base = 1; + while(--digits >= 0) { + if (p[digits] < '0' || p[digits] > '9') + return -1; + ret += (p[digits] - '0') * base; + base *= 10; + } + return ret; +} + +int +_p11t_check_date(const char *what, CK_DATE* value) +{ + int year, month, day; + + year = atoin((const char*)value->year, 4); + month = atoin((const char*)value->month, 2); + day = atoin((const char*)value->day, 2); + + if(year < 0 || year > 9999 || + month < 1 || month > 12 || + day < 1 || day > 31) + { + p11t_check_fail("%s: invalid date", what); + return STOP; + } + + return CONTINUE; +} + int _p11t_check_string(const char *what, CK_UTF8CHAR_PTR value, CK_ULONG length) { -- cgit v1.2.3