aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-08-24 10:46:04 +0200
committerMarkus Armbruster <armbru@redhat.com>2017-09-04 13:09:13 +0200
commit9ae33079c2061d73c88dbe2dd79373dedc50f693 (patch)
tree5a67a969cd1c7a5b2415946ab54d26b2a45ce065
parent8d5fb199fb20446f8233226124b9f13be1434efc (diff)
crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup()
Cc: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1503564371-26090-10-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Acked-by: Daniel P. Berrange <berrange@redhat.com>
-rw-r--r--crypto/block-luks.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index afb8543108..c3cacdb1ed 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -20,6 +20,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
+#include "qapi/util.h"
#include "qemu/bswap.h"
#include "crypto/block-luks.h"
@@ -265,39 +266,33 @@ qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlgorithm alg,
* make that function emit a more friendly error message */
static int qcrypto_block_luks_name_lookup(const char *name,
const char *const *map,
- size_t maplen,
const char *type,
Error **errp)
{
- size_t i;
- for (i = 0; i < maplen; i++) {
- if (g_str_equal(map[i], name)) {
- return i;
- }
- }
+ int ret = qapi_enum_parse(map, name, -1, NULL);
- error_setg(errp, "%s %s not supported", type, name);
- return 0;
+ if (ret < 0) {
+ error_setg(errp, "%s %s not supported", type, name);
+ return 0;
+ }
+ return ret;
}
#define qcrypto_block_luks_cipher_mode_lookup(name, errp) \
qcrypto_block_luks_name_lookup(name, \
QCryptoCipherMode_lookup, \
- QCRYPTO_CIPHER_MODE__MAX, \
"Cipher mode", \
errp)
#define qcrypto_block_luks_hash_name_lookup(name, errp) \
qcrypto_block_luks_name_lookup(name, \
QCryptoHashAlgorithm_lookup, \
- QCRYPTO_HASH_ALG__MAX, \
"Hash algorithm", \
errp)
#define qcrypto_block_luks_ivgen_name_lookup(name, errp) \
qcrypto_block_luks_name_lookup(name, \
QCryptoIVGenAlgorithm_lookup, \
- QCRYPTO_IVGEN_ALG__MAX, \
"IV generator", \
errp)