challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

commit 0d9cfe4eb122ac3829d9d9168482f24fce9342ca
parent 155a5ad0e36d0465ead04185628bab8a77cbb854
Author: Bohdan Potuzhnyi <potub1@bfh.ch>
Date:   Sun, 15 Sep 2024 21:43:37 +0000

small fix

Diffstat:
Msrc/challenger/.gitignore | 2++
Asrc/challenger/src/challenger_cm_enums.c | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/challenger/src/challenger_cm_enums.h | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 0 deletions(-)

diff --git a/src/challenger/.gitignore b/src/challenger/.gitignore @@ -1 +1,2 @@ challenger-admin +src/.* +\ No newline at end of file diff --git a/src/challenger/src/challenger_cm_enums.c b/src/challenger/src/challenger_cm_enums.c @@ -0,0 +1,58 @@ +/* + This file is part of Challenger + Copyright (C) 2023 Taler Systems SA + + Challenger is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + Challenger is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file challenger_cm_enums.c + * @brief enums to handle challenge method + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ + +#include "challenger_cm_enums.h" +#include <string.h> +#include <stdint.h> + + +enum CHALLENGER_CM +CHALLENGER_cm_from_string(const char *method_str) +{ + if (NULL == method_str || 0 == strcmp(method_str, "")) + return CHALLENGER_CM_EMPTY; + + if (0 == strcmp(method_str, "plain")) + return CHALLENGER_CM_PLAIN; + + if (0 == strcmp(method_str, "S256") || 0 == strcmp(method_str, "sha256")) + return CHALLENGER_CM_S256; + + return CHALLENGER_CM_UNKNOWN; +} + + +enum CHALLENGER_CM +CHALLENGER_cm_from_int(uint32_t method_int) +{ + switch (method_int) + { + case 0: + return CHALLENGER_CM_EMPTY; + case 1: + return CHALLENGER_CM_PLAIN; + case 2: + return CHALLENGER_CM_S256; + default: + return CHALLENGER_CM_UNKNOWN; // Invalid or unrecognized value + } +} +\ No newline at end of file diff --git a/src/challenger/src/challenger_cm_enums.h b/src/challenger/src/challenger_cm_enums.h @@ -0,0 +1,58 @@ +/* + This file is part of Challenger + Copyright (C) 2023 Taler Systems SA + + Challenger is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + Challenger is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file challenger_cm_enums.h + * @brief enums to handle challenge method + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ + +#ifndef CHALLENGER_CM_ENUMS_H +#define CHALLENGER_CM_ENUMS_H + +#include <stdint.h> + +enum CHALLENGER_CM +{ + CHALLENGER_CM_EMPTY, + CHALLENGER_CM_PLAIN, + CHALLENGER_CM_S256, + CHALLENGER_CM_UNKNOWN +}; + + +/** + * Convert a string to the corresponding enum value. + * + * @param method_str the string representing the code challenge method + * @return the corresponding enum value, or CHALLENGER_CM_UNKNOWN if not recognized + */ +enum CHALLENGER_CM +CHALLENGER_cm_from_string(const char *method_str); + + +/** + * Convert an int to the corresponding enum value. + * Returns CHALLENGER_CM_UNKNOWN if the int does not match a valid enum value. + * + * @param method_int integer representation of the code challenge method + * @return the corresponding enum value + */ +enum CHALLENGER_CM +CHALLENGER_cm_from_int(uint32_t method_int); + + +#endif /* CHALLENGER_CM_ENUMS_H */ +\ No newline at end of file