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>
This commit is contained in:
Markus Armbruster 2017-08-24 10:46:04 +02:00
parent 8d5fb199fb
commit 9ae33079c2

View File

@ -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)