The has_FOO for pointer-valued FOO are redundant, except for arrays.
They are also a nuisance to work with. Recent commit "qapi: Start to
elide redundant has_FOO in generated C" provided the means to elide
them step by step. This is the step for qapi/crypto.json.
Said commit explains the transformation in more detail. The invariant
violations mentioned there do not occur here.
Cc: Daniel P. Berrangé" <berrange@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
crypto/block-luks.c | 16 ++++++++--------
tests/unit/test-crypto-block.c | 6 ------
scripts/qapi/schema.py | 1 -
3 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index f62be6836b..4205bc491e 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -1629,13 +1629,13 @@ qcrypto_block_luks_amend_add_keyslot(QCryptoBlock *block,
g_autofree char *new_password = NULL;
g_autofree uint8_t *master_key = NULL;
- char *secret = opts_luks->has_secret ? opts_luks->secret : luks->secret;
+ char *secret = opts_luks->secret ?: luks->secret;
- if (!opts_luks->has_new_secret) {
+ if (!opts_luks->new_secret) {
error_setg(errp, "'new-secret' is required to activate a keyslot");
return -1;
}
- if (opts_luks->has_old_secret) {
+ if (opts_luks->old_secret) {
error_setg(errp,
"'old-secret' must not be given when activating keyslots");
return -1;
@@ -1709,7 +1709,7 @@ qcrypto_block_luks_amend_erase_keyslots(QCryptoBlock *block,
g_autofree uint8_t *tmpkey = NULL;
g_autofree char *old_password = NULL;
- if (opts_luks->has_new_secret) {
+ if (opts_luks->new_secret) {
error_setg(errp,
"'new-secret' must not be given when erasing keyslots");
return -1;
@@ -1719,14 +1719,14 @@ qcrypto_block_luks_amend_erase_keyslots(QCryptoBlock *block,
"'iter-time' must not be given when erasing keyslots");
return -1;
}
- if (opts_luks->has_secret) {
+ if (opts_luks->secret) {
error_setg(errp,
"'secret' must not be given when erasing keyslots");
return -1;
}
/* Load the old password if given */
- if (opts_luks->has_old_secret) {
+ if (opts_luks->old_secret) {
old_password = qcrypto_secret_lookup_as_utf8(opts_luks->old_secret,
errp);
if (!old_password) {
@@ -1751,7 +1751,7 @@ qcrypto_block_luks_amend_erase_keyslots(QCryptoBlock *block,
return -1;
}
- if (opts_luks->has_old_secret) {
+ if (opts_luks->old_secret) {
int rv = qcrypto_block_luks_load_key(block,
keyslot,
old_password,
@@ -1793,7 +1793,7 @@ qcrypto_block_luks_amend_erase_keyslots(QCryptoBlock *block,
}
/* Erase all keyslots that match the given old password */
- } else if (opts_luks->has_old_secret) {
+ } else if (opts_luks->old_secret) {
unsigned long slots_to_erase_bitmap = 0;
size_t i;
diff --git a/tests/unit/test-crypto-block.c b/tests/unit/test-crypto-block.c
index 3417b67be5..6bef471afb 100644
--- a/tests/unit/test-crypto-block.c
+++ b/tests/unit/test-crypto-block.c
@@ -39,7 +39,6 @@
static QCryptoBlockCreateOptions qcow_create_opts = {
.format = Q_CRYPTO_BLOCK_FORMAT_QCOW,
.u.qcow = {
- .has_key_secret = true,
.key_secret = (char *)"sec0",
},
};
@@ -47,7 +46,6 @@ static QCryptoBlockCreateOptions qcow_create_opts = {
static QCryptoBlockOpenOptions qcow_open_opts = {
.format = Q_CRYPTO_BLOCK_FORMAT_QCOW,
.u.qcow = {
- .has_key_secret = true,
.key_secret = (char *)"sec0",
},
};
@@ -57,7 +55,6 @@ static QCryptoBlockOpenOptions qcow_open_opts = {
static QCryptoBlockOpenOptions luks_open_opts = {
.format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
.u.luks = {
- .has_key_secret = true,
.key_secret = (char *)"sec0",
},
};
@@ -67,7 +64,6 @@ static QCryptoBlockOpenOptions luks_open_opts = {
static QCryptoBlockCreateOptions luks_create_opts_default = {
.format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
.u.luks = {
- .has_key_secret = true,
.key_secret = (char *)"sec0",
},
};
@@ -77,7 +73,6 @@ static QCryptoBlockCreateOptions luks_create_opts_default = {
static QCryptoBlockCreateOptions luks_create_opts_aes256_cbc_plain64 = {
.format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
.u.luks = {
- .has_key_secret = true,
.key_secret = (char *)"sec0",
.has_cipher_alg = true,
.cipher_alg = QCRYPTO_CIPHER_ALG_AES_256,
@@ -92,7 +87,6 @@ static QCryptoBlockCreateOptions luks_create_opts_aes256_cbc_plain64 = {
static QCryptoBlockCreateOptions luks_create_opts_aes256_cbc_essiv = {
.format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
.u.luks = {
- .has_key_secret = true,
.key_secret = (char *)"sec0",
.has_cipher_alg = true,
.cipher_alg = QCRYPTO_CIPHER_ALG_AES_256,
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 707c671133..21d0b28790 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -759,7 +759,6 @@ def need_has(self):
assert self.type
# Temporary hack to support dropping the has_FOO in reviewable chunks
opt_out = [
- 'qapi/crypto.json',
'qapi/dump.json',
'qapi/job.json',
'qapi/machine.json',
--
2.37.2