diff --git a/include/cryb/oath.h b/include/cryb/oath.h index 9d19a20..5f19485 100644 --- a/include/cryb/oath.h +++ b/include/cryb/oath.h @@ -45,9 +45,11 @@ const char *cryb_oath_version(void); #define oath_key_alloc cryb_oath_key_alloc #define oath_key_create cryb_oath_key_create #define oath_key_dummy cryb_oath_key_dummy -#define oath_key_from_uri cryb_oath_key_from_uri #define oath_key_free cryb_oath_key_free +#define oath_key_from_uri cryb_oath_key_from_uri #define oath_key_to_uri cryb_oath_key_to_uri +#define oath_mode_name cryb_oath_mode_name +#define oath_mode_value cryb_oath_mode_value struct oath_key *oath_key_alloc(void); struct oath_key *oath_key_create(const char *, enum oath_mode, @@ -59,6 +61,7 @@ char *oath_key_to_uri(const struct oath_key *); struct oath_key *oath_key_dummy(enum oath_mode, enum oath_hash, unsigned int); -enum oath_mode oath_mode(const char *); +const char *oath_mode_name(enum oath_mode); +enum oath_mode oath_mode_value(const char *); #endif diff --git a/lib/oath/Makefile.am b/lib/oath/Makefile.am index e84f5da..c2c6123 100644 --- a/lib/oath/Makefile.am +++ b/lib/oath/Makefile.am @@ -11,6 +11,7 @@ libcryb_oath_la_SOURCES = \ cryb_oath_key_from_uri.c \ cryb_oath_key_free.c \ cryb_oath_key_to_uri.c \ + cryb_oath_mode.c \ \ cryb_oath.c diff --git a/lib/oath/cryb_oath_mode.c b/lib/oath/cryb_oath_mode.c index cb69d9b..4955dc9 100644 --- a/lib/oath/cryb_oath_mode.c +++ b/lib/oath/cryb_oath_mode.c @@ -27,15 +27,13 @@ * SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "cryb/impl.h" +#include #include -#include #include -#include +#include static const char *oath_mode_names[om_max] = { [om_hotp] = "hotp", @@ -43,13 +41,10 @@ static const char *oath_mode_names[om_max] = { }; /* - * OATH - * - * Converts a mode name to the corresponding enum value + * Returns the enum value that corresponds to an OATH mode name */ - enum oath_mode -oath_mode(const char *str) +oath_mode_value(const char *str) { enum oath_mode om; @@ -62,9 +57,14 @@ oath_mode(const char *str) return (om_undef); } -/** - * The =oath_mode function returns the =enum oath_mode value that - * corresponds to the specified string. - * - * AUTHOR UIO +/* + * Returns the name of an OATH mode given its enum value */ +const char * +oath_mode_name(enum oath_mode om) +{ + + if (om >= 0 && om < om_max) + return (oath_mode_names[om]); + return (NULL); +}