From 9ae33079c2061d73c88dbe2dd79373dedc50f693 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 24 Aug 2017 10:46:04 +0200 Subject: crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: "Daniel P. Berrange" Signed-off-by: Markus Armbruster Message-Id: <1503564371-26090-10-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau Acked-by: Daniel P. Berrange --- crypto/block-luks.c | 19 +++++++------------ 1 file 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) -- cgit v1.2.3