diff options
author | Mattias Andrée <maandree@kth.se> | 2021-04-12 23:05:22 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-04-12 23:05:22 +0200 |
commit | 90054e8a7df36eea21b612de6bd28d88e67989f9 (patch) | |
tree | 2fddd2123ea3aa13f7d4d031e685bd13979c4a38 /libsecauth_format_spec.c | |
download | secauth-90054e8a7df36eea21b612de6bd28d88e67989f9.tar.gz secauth-90054e8a7df36eea21b612de6bd28d88e67989f9.tar.bz2 secauth-90054e8a7df36eea21b612de6bd28d88e67989f9.tar.xz |
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libsecauth_format_spec.c')
-rw-r--r-- | libsecauth_format_spec.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libsecauth_format_spec.c b/libsecauth_format_spec.c new file mode 100644 index 0000000..83a08cf --- /dev/null +++ b/libsecauth_format_spec.c @@ -0,0 +1,29 @@ +/* See LICENSE file for copyright and license details. */ +#include "libsecauth.h" + +#include <inttypes.h> +#include <stdio.h> +#include <string.h> + + +size_t +libsecauth_format_spec(struct libsecauth_spec *spec, char *buffer, size_t buffer_size) +{ + char client_rounds[sizeof("4294967295")]; + char server_rounds[sizeof("4294967295")]; + int i, expected_with_dollars; + client_rounds[0] = '\0'; + server_rounds[0] = '\0'; + if (spec->client_rounds) + sprintf(client_rounds, "%"PRIu32, spec->client_rounds); + if (spec->server_rounds) + sprintf(server_rounds, "%"PRIu32, spec->server_rounds); + expected_with_dollars = spec->expected && strchr(spec->expected, '$'); + i = snprintf(buffer, buffer_size, "$secauth$%s%s%s$%s%s%s$%s$%s$%s%s%s$%s%s%s", + spec->prehash ? "{$" : "", spec->prehash ? spec->prehash : "", spec->prehash ? "$}" : "", + spec->xferhash ? "{$" : "", spec->xferhash ? spec->xferhash : "", spec->xferhash ? "$}" : "", + client_rounds, server_rounds, + spec->posthash ? "{$" : "", spec->posthash ? spec->posthash : "", spec->posthash ? "$}" : "", + expected_with_dollars ? "{$" : "", spec->expected ? spec->expected : "" , expected_with_dollars ? "$}" : ""); + return i > 0 ? (size_t)i : 0; +} |