summaryrefslogtreecommitdiff
path: root/src/check.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/check.c')
-rw-r--r--src/check.c33
1 files changed, 33 insertions, 0 deletions
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)
{