Finish and hook up half-written name-to-enum / enum-to-name conversion for OATH modes.

This commit is contained in:
Dag-Erling Smørgrav 2016-10-03 12:26:30 +02:00 committed by Dag-Erling Smørgrav
parent a36ae775dd
commit be954631db
3 changed files with 21 additions and 17 deletions

View file

@ -45,9 +45,11 @@ const char *cryb_oath_version(void);
#define oath_key_alloc cryb_oath_key_alloc #define oath_key_alloc cryb_oath_key_alloc
#define oath_key_create cryb_oath_key_create #define oath_key_create cryb_oath_key_create
#define oath_key_dummy cryb_oath_key_dummy #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_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_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_alloc(void);
struct oath_key *oath_key_create(const char *, enum oath_mode, 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); 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 #endif

View file

@ -11,6 +11,7 @@ libcryb_oath_la_SOURCES = \
cryb_oath_key_from_uri.c \ cryb_oath_key_from_uri.c \
cryb_oath_key_free.c \ cryb_oath_key_free.c \
cryb_oath_key_to_uri.c \ cryb_oath_key_to_uri.c \
cryb_oath_mode.c \
\ \
cryb_oath.c cryb_oath.c

View file

@ -27,15 +27,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#ifdef HAVE_CONFIG_H #include "cryb/impl.h"
# include "config.h"
#endif
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include <strings.h> #include <strings.h>
#include <security/oath.h> #include <cryb/oath.h>
static const char *oath_mode_names[om_max] = { static const char *oath_mode_names[om_max] = {
[om_hotp] = "hotp", [om_hotp] = "hotp",
@ -43,13 +41,10 @@ static const char *oath_mode_names[om_max] = {
}; };
/* /*
* OATH * Returns the enum value that corresponds to an OATH mode name
*
* Converts a mode name to the corresponding enum value
*/ */
enum oath_mode enum oath_mode
oath_mode(const char *str) oath_mode_value(const char *str)
{ {
enum oath_mode om; enum oath_mode om;
@ -62,9 +57,14 @@ oath_mode(const char *str)
return (om_undef); return (om_undef);
} }
/** /*
* The =oath_mode function returns the =enum oath_mode value that * Returns the name of an OATH mode given its enum value
* corresponds to the specified string.
*
* AUTHOR UIO
*/ */
const char *
oath_mode_name(enum oath_mode om)
{
if (om >= 0 && om < om_max)
return (oath_mode_names[om]);
return (NULL);
}