aboutsummaryrefslogtreecommitdiffstats
path: root/libar2_string_to_type.c
blob: 98db6a84619cf9d46c3d19f78e40148ee390b33c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
	}
}