From: levitte Date: Fri, 17 Oct 2008 19:15:28 +0000 (+0000) Subject: Define the functions that set the character fields X-Git-Tag: yubikey-personalisation_0.97-1~126 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23aa2833cf12e23f61f1021adc747f5c1e652b15;p=yubikey-personalization Define the functions that set the character fields git-svn-id: https://yubikey-personalization.googlecode.com/svn/trunk@35 b62f149e-849f-11dd-9899-c7ba65f7c4c7 --- 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) \ { \