aboutsummaryrefslogtreecommitdiffstats
path: root/libar2_string_to_type.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-01-16 19:58:57 +0100
committerMattias Andrée <maandree@kth.se>2022-01-16 19:58:57 +0100
commit8bdc2e4929068210d523c34c0b171b51ce96057f (patch)
treec77331e77b9777a37716bffb7365c4486a6df9a0 /libar2_string_to_type.c
downloadlibar2-1.0.tar.gz
libar2-1.0.tar.bz2
libar2-1.0.tar.xz
First commit1.0
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libar2_string_to_type.c')
-rw-r--r--libar2_string_to_type.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/libar2_string_to_type.c b/libar2_string_to_type.c
new file mode 100644
index 0000000..98db6a8
--- /dev/null
+++ b/libar2_string_to_type.c
@@ -0,0 +1,30 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libar2_string_to_type(const char *str, enum libar2_argon2_type *typep)
+{
+#define STRSTARTS(A, B) (!strncmp(A, B, sizeof(B) - 1))
+
+ if (!strcasecmp(str, "argon2d") || STRSTARTS(str, "argon2d$")) {
+ *typep = LIBAR2_ARGON2D;
+ return 0;
+
+ } else if (!strcasecmp(str, "argon2i") || STRSTARTS(str, "argon2i$")) {
+ *typep = LIBAR2_ARGON2I;
+ return 0;
+
+ } else if (!strcasecmp(str, "argon2id") || STRSTARTS(str, "argon2id$")) {
+ *typep = LIBAR2_ARGON2ID;
+ return 0;
+
+ } else if (!strcasecmp(str, "argon2ds") || STRSTARTS(str, "argon2ds$")) {
+ *typep = LIBAR2_ARGON2DS;
+ return 0;
+
+ } else {
+ errno = EINVAL;
+ return -1;
+ }
+}