From 89d6b85f1d63b2e59affb27021f8159a7f5a0181 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Mon, 13 Feb 2017 19:37:10 -0600 Subject: [PATCH] wscutil: Add wsc_is_pin_valid --- src/wscutil.c | 16 ++++++++++++++++ src/wscutil.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/wscutil.c b/src/wscutil.c index 3f2133bf..aa55f7e3 100644 --- a/src/wscutil.c +++ b/src/wscutil.c @@ -2515,3 +2515,19 @@ bool wsc_kdf(const void *key, void *output, size_t size) return true; } + +bool wsc_pin_is_valid(const char *pin) +{ + unsigned int i; + + for (i = 0; pin[i] >= '0' && pin[i] <= '9'; i++) + ; + + if (pin[i]) + return false; + + if (i != 8 && i != 4) + return false; + + return true; +} diff --git a/src/wscutil.h b/src/wscutil.h index 4958ad29..1d86c0b0 100644 --- a/src/wscutil.h +++ b/src/wscutil.h @@ -637,3 +637,5 @@ struct wsc_session_key { } __attribute__ ((packed)); bool wsc_kdf(const void *kdk, void *output, size_t size); + +bool wsc_pin_is_valid(const char *pin);