From 62cc3a9c5af2fd7cc8847a577b6b911c79e110e7 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 3 Jul 2016 20:06:33 +0200 Subject: tools: improve error reporting and detection --- src/tools/config.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/tools/config.c') diff --git a/src/tools/config.c b/src/tools/config.c index 0cec30e..9066178 100644 --- a/src/tools/config.c +++ b/src/tools/config.c @@ -93,12 +93,8 @@ static inline uint16_t parse_port(const char *value) static inline bool parse_key(uint8_t key[WG_KEY_LEN], const char *value) { uint8_t tmp[WG_KEY_LEN + 1]; - if (strlen(value) != b64_len(WG_KEY_LEN) - 1) { - fprintf(stderr, "Key is not the correct length: `%s`\n", value); - return false; - } - if (b64_pton(value, tmp, WG_KEY_LEN + 1) < 0) { - fprintf(stderr, "Could not parse base64 key: `%s`\n", value); + if (strlen(value) != b64_len(WG_KEY_LEN) - 1 || b64_pton(value, tmp, WG_KEY_LEN + 1) != WG_KEY_LEN) { + fprintf(stderr, "Key is not the correct length or format: `%s`\n", value); return false; } memcpy(key, tmp, WG_KEY_LEN); -- cgit v1.2.3-59-g8ed1b