diff options
author | Mattias Andrée <maandree@kth.se> | 2022-02-12 21:56:50 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-02-12 21:56:50 +0100 |
commit | 33c953317cad9ea06d8a26fe2cc2ed0ed9e29692 (patch) | |
tree | 9e34e8fd215966299d11cf93d5471c76b3a933a7 /libar2_encode_params.c | |
parent | libar2_encode_base64: data may be NULL if buf is NULL (diff) | |
download | libar2-33c953317cad9ea06d8a26fe2cc2ed0ed9e29692.tar.gz libar2-33c953317cad9ea06d8a26fe2cc2ed0ed9e29692.tar.bz2 libar2-33c953317cad9ea06d8a26fe2cc2ed0ed9e29692.tar.xz |
Use params->version == 0 for implicit specification of version 1.0
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libar2_encode_params.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/libar2_encode_params.c b/libar2_encode_params.c index 498de9c..bcc46b8 100644 --- a/libar2_encode_params.c +++ b/libar2_encode_params.c @@ -7,22 +7,34 @@ libar2_encode_params(char *buf, const struct libar2_argon2_parameters *params) { size_t off; -#define FMT_AND_ARGS\ - "$%s$v=%i$m=%lu,t=%lu,p=%lu$",\ - libar2_type_to_string(params->type, LIBAR2_LOWER_CASE),\ - (int)params->version,\ +#define FMT_AND_ARGS_HEAD\ + "$%s$",\ + libar2_type_to_string(params->type, LIBAR2_LOWER_CASE) + +#define FMT_AND_ARGS_VERSION\ + "v=%i$",\ + (int)params->version + +#define FMT_AND_ARGS_TAIL\ + "m=%lu,t=%lu,p=%lu$",\ (unsigned long int)params->m_cost,\ (unsigned long int)params->t_cost,\ (unsigned long int)params->lanes if (buf) { - off = (size_t)sprintf(buf, FMT_AND_ARGS); + off = (size_t)sprintf(buf, FMT_AND_ARGS_HEAD); + if (params->version) + off += (size_t)sprintf(&buf[off], FMT_AND_ARGS_VERSION); + off += (size_t)sprintf(&buf[off], FMT_AND_ARGS_TAIL); off += libar2_encode_base64(&buf[off], params->salt, params->saltlen) - 1; buf[off++] = '$'; buf[off++] = '\0'; } else { - off = (size_t)snprintf(NULL, 0, FMT_AND_ARGS); + off = (size_t)snprintf(NULL, 0, FMT_AND_ARGS_HEAD); + if (params->version) + off += (size_t)snprintf(NULL, 0, FMT_AND_ARGS_VERSION); + off += (size_t)snprintf(NULL, 0, FMT_AND_ARGS_TAIL); off += libar2_encode_base64(NULL, params->salt, params->saltlen) - 1; off += 2; } |