aboutsummaryrefslogtreecommitdiffstats
path: root/libsecauth_format_spec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libsecauth_format_spec.c')
-rw-r--r--libsecauth_format_spec.c29
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;
+}