From 23aa2833cf12e23f61f1021adc747f5c1e652b15 Mon Sep 17 00:00:00 2001 From: levitte Date: Fri, 17 Oct 2008 19:15:28 +0000 Subject: [PATCH] Define the functions that set the character fields git-svn-id: https://yubikey-personalization.googlecode.com/svn/trunk@35 b62f149e-849f-11dd-9899-c7ba65f7c4c7 --- ykpers.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/ykpers.c b/ykpers.c index 8716c75..7a23f46 100644 --- a/ykpers.c +++ b/ykpers.c @@ -135,22 +135,30 @@ int ykp_AES_key_from_passphrase(CONFIG *cfg, const char *passphrase, return 0; } -int ykp_set_access_code(CONFIG *cfg, unsigned char *access_code) -{ - if (cfg) { - size_t max_chars = strlen(access_code); - - if (max_chars > ACC_CODE_SIZE) - max_chars = ACC_CODE_SIZE; - - memcpy(cfg->accCode, access_code, max_chars); - memset(cfg->accCode, 0, ACC_CODE_SIZE - max_chars); - - return 1; - } - return 0; +#define def_set_charfield(fnname,fieldname,size,extra) \ +int ykp_set_ ## fnname(CONFIG *cfg, unsigned char *input) \ +{ \ + if (cfg) { \ + size_t max_chars = strlen(input); \ + \ + if (max_chars > (size)) \ + max_chars = (size); \ + \ + memcpy(cfg->fieldname, (input), max_chars); \ + memset(cfg->fieldname + max_chars, 0, \ + (size) - max_chars); \ + extra; \ + \ + return 1; \ + } \ + ykp_errno = YKP_ENOCFG; \ + return 0; \ } +def_set_charfield(access_code,accCode,ACC_CODE_SIZE,) +def_set_charfield(fixed,fixed,FIXED_SIZE,cfg->fixedSize = max_chars) +def_set_charfield(uid,uid,UID_SIZE,) + #define def_set_tktflag(type) \ int ykp_set_tktflag_ ## type(CONFIG *cfg, bool state) \ { \ -- 2.39.5