From patchwork Mon Sep 5 17:05:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 9314699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 16B39607D3 for ; Mon, 5 Sep 2016 17:06:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00E1628716 for ; Mon, 5 Sep 2016 17:06:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E805E28A19; Mon, 5 Sep 2016 17:06:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6762128716 for ; Mon, 5 Sep 2016 17:06:45 +0000 (UTC) Received: from localhost ([::1]:55909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgxM4-0001pU-Aa for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Sep 2016 13:06:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgxLD-0001SJ-Nf for qemu-devel@nongnu.org; Mon, 05 Sep 2016 13:05:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgxL8-0002gb-8n for qemu-devel@nongnu.org; Mon, 05 Sep 2016 13:05:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43426) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgxL7-0002gQ-UJ for qemu-devel@nongnu.org; Mon, 05 Sep 2016 13:05:46 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75CA183F3A for ; Mon, 5 Sep 2016 17:05:45 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-6-221.ams2.redhat.com [10.36.6.221]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u85H5imk005172; Mon, 5 Sep 2016 13:05:44 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Mon, 5 Sep 2016 18:05:35 +0100 Message-Id: <1473095135-15915-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 05 Sep 2016 17:05:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] crypto: report enum strings instead of values in errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Several error messages print out the raw enum value, which is less than helpful to users, as these values are not documented, nor stable across QEMU releases. Switch to use the enum string instead. The nettle impl also had two typos where it said "algorithm" instead of "mode". Signed-off-by: Daniel P. Berrange Reviewed-by: Markus Armbruster --- crypto/block.c | 6 ++++-- crypto/cipher-builtin.c | 9 ++++++--- crypto/cipher-gcrypt.c | 6 ++++-- crypto/cipher-nettle.c | 14 ++++++++------ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/crypto/block.c b/crypto/block.c index be823ee..64c8420 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -59,7 +59,8 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions *options, if (options->format >= G_N_ELEMENTS(qcrypto_block_drivers) || !qcrypto_block_drivers[options->format]) { - error_setg(errp, "Unsupported block driver %d", options->format); + error_setg(errp, "Unsupported block driver %s", + QCryptoBlockFormat_lookup[options->format]); g_free(block); return NULL; } @@ -88,7 +89,8 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options, if (options->format >= G_N_ELEMENTS(qcrypto_block_drivers) || !qcrypto_block_drivers[options->format]) { - error_setg(errp, "Unsupported block driver %d", options->format); + error_setg(errp, "Unsupported block driver %s", + QCryptoBlockFormat_lookup[options->format]); g_free(block); return NULL; } diff --git a/crypto/cipher-builtin.c b/crypto/cipher-builtin.c index 88963f6..9d25842 100644 --- a/crypto/cipher-builtin.c +++ b/crypto/cipher-builtin.c @@ -244,7 +244,8 @@ static int qcrypto_cipher_init_aes(QCryptoCipher *cipher, if (cipher->mode != QCRYPTO_CIPHER_MODE_CBC && cipher->mode != QCRYPTO_CIPHER_MODE_ECB && cipher->mode != QCRYPTO_CIPHER_MODE_XTS) { - error_setg(errp, "Unsupported cipher mode %d", cipher->mode); + error_setg(errp, "Unsupported cipher mode %s", + QCryptoCipherMode_lookup[cipher->mode]); return -1; } @@ -376,7 +377,8 @@ static int qcrypto_cipher_init_des_rfb(QCryptoCipher *cipher, QCryptoCipherBuiltin *ctxt; if (cipher->mode != QCRYPTO_CIPHER_MODE_ECB) { - error_setg(errp, "Unsupported cipher mode %d", cipher->mode); + error_setg(errp, "Unsupported cipher mode %s", + QCryptoCipherMode_lookup[cipher->mode]); return -1; } @@ -442,7 +444,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, break; default: error_setg(errp, - "Unsupported cipher algorithm %d", cipher->alg); + "Unsupported cipher algorithm %s", + QCryptoCipherAlgorithm_lookup[cipher->alg]); goto error; } diff --git a/crypto/cipher-gcrypt.c b/crypto/cipher-gcrypt.c index 3652aa1..da3f4c7 100644 --- a/crypto/cipher-gcrypt.c +++ b/crypto/cipher-gcrypt.c @@ -70,7 +70,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, gcrymode = GCRY_CIPHER_MODE_CBC; break; default: - error_setg(errp, "Unsupported cipher mode %d", mode); + error_setg(errp, "Unsupported cipher mode %s", + QCryptoCipherMode_lookup[mode]); return NULL; } @@ -120,7 +121,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, break; default: - error_setg(errp, "Unsupported cipher algorithm %d", alg); + error_setg(errp, "Unsupported cipher algorithm %s", + QCryptoCipherAlgorithm_lookup[alg]); return NULL; } diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c index 0267da5..879d831 100644 --- a/crypto/cipher-nettle.c +++ b/crypto/cipher-nettle.c @@ -227,7 +227,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, case QCRYPTO_CIPHER_MODE_XTS: break; default: - error_setg(errp, "Unsupported cipher mode %d", mode); + error_setg(errp, "Unsupported cipher mode %s", + QCryptoCipherMode_lookup[mode]); return NULL; } @@ -357,7 +358,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg, break; default: - error_setg(errp, "Unsupported cipher algorithm %d", alg); + error_setg(errp, "Unsupported cipher algorithm %s", + QCryptoCipherAlgorithm_lookup[alg]); goto error; } @@ -429,8 +431,8 @@ int qcrypto_cipher_encrypt(QCryptoCipher *cipher, break; default: - error_setg(errp, "Unsupported cipher algorithm %d", - cipher->alg); + error_setg(errp, "Unsupported cipher mode %s", + QCryptoCipherMode_lookup[cipher->mode]); return -1; } return 0; @@ -469,8 +471,8 @@ int qcrypto_cipher_decrypt(QCryptoCipher *cipher, break; default: - error_setg(errp, "Unsupported cipher algorithm %d", - cipher->alg); + error_setg(errp, "Unsupported cipher mode %s", + QCryptoCipherMode_lookup[cipher->mode]); return -1; } return 0;