crypto: Move USER_CREATABLE to secret_common base class

Instead of duplicating the code for user creatable objects in secret and
secret_keyring, move it to the common base clase secret_common. As the
base class is abstract, it won't become user creatable itself.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Kevin Wolf 2020-11-30 11:56:12 +01:00 committed by Daniel P. Berrangé
parent 8573431b9c
commit 31b6aefdbd
3 changed files with 15 additions and 28 deletions

View File

@ -107,13 +107,6 @@ qcrypto_secret_prop_get_file(Object *obj,
} }
static void
qcrypto_secret_complete(UserCreatable *uc, Error **errp)
{
object_property_set_bool(OBJECT(uc), "loaded", true, errp);
}
static void static void
qcrypto_secret_finalize(Object *obj) qcrypto_secret_finalize(Object *obj)
{ {
@ -129,9 +122,6 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data)
QCryptoSecretCommonClass *sic = QCRYPTO_SECRET_COMMON_CLASS(oc); QCryptoSecretCommonClass *sic = QCRYPTO_SECRET_COMMON_CLASS(oc);
sic->load_data = qcrypto_secret_load_data; sic->load_data = qcrypto_secret_load_data;
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
ucc->complete = qcrypto_secret_complete;
object_class_property_add_str(oc, "data", object_class_property_add_str(oc, "data",
qcrypto_secret_prop_get_data, qcrypto_secret_prop_get_data,
qcrypto_secret_prop_set_data); qcrypto_secret_prop_set_data);
@ -148,10 +138,6 @@ static const TypeInfo qcrypto_secret_info = {
.instance_finalize = qcrypto_secret_finalize, .instance_finalize = qcrypto_secret_finalize,
.class_size = sizeof(QCryptoSecretClass), .class_size = sizeof(QCryptoSecretClass),
.class_init = qcrypto_secret_class_init, .class_init = qcrypto_secret_class_init,
.interfaces = (InterfaceInfo[]) {
{ TYPE_USER_CREATABLE },
{ }
}
}; };

View File

@ -268,6 +268,13 @@ qcrypto_secret_prop_get_keyid(Object *obj,
} }
static void
qcrypto_secret_complete(UserCreatable *uc, Error **errp)
{
object_property_set_bool(OBJECT(uc), "loaded", true, errp);
}
static void static void
qcrypto_secret_finalize(Object *obj) qcrypto_secret_finalize(Object *obj)
{ {
@ -281,6 +288,10 @@ qcrypto_secret_finalize(Object *obj)
static void static void
qcrypto_secret_class_init(ObjectClass *oc, void *data) qcrypto_secret_class_init(ObjectClass *oc, void *data)
{ {
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
ucc->complete = qcrypto_secret_complete;
object_class_property_add_bool(oc, "loaded", object_class_property_add_bool(oc, "loaded",
qcrypto_secret_prop_get_loaded, qcrypto_secret_prop_get_loaded,
qcrypto_secret_prop_set_loaded); qcrypto_secret_prop_set_loaded);
@ -390,6 +401,10 @@ static const TypeInfo qcrypto_secret_info = {
.class_size = sizeof(QCryptoSecretCommonClass), .class_size = sizeof(QCryptoSecretCommonClass),
.class_init = qcrypto_secret_class_init, .class_init = qcrypto_secret_class_init,
.abstract = true, .abstract = true,
.interfaces = (InterfaceInfo[]) {
{ TYPE_USER_CREATABLE },
{ }
}
}; };

View File

@ -102,22 +102,12 @@ qcrypto_secret_prop_get_key(Object *obj, Visitor *v,
} }
static void
qcrypto_secret_keyring_complete(UserCreatable *uc, Error **errp)
{
object_property_set_bool(OBJECT(uc), "loaded", true, errp);
}
static void static void
qcrypto_secret_keyring_class_init(ObjectClass *oc, void *data) qcrypto_secret_keyring_class_init(ObjectClass *oc, void *data)
{ {
QCryptoSecretCommonClass *sic = QCRYPTO_SECRET_COMMON_CLASS(oc); QCryptoSecretCommonClass *sic = QCRYPTO_SECRET_COMMON_CLASS(oc);
sic->load_data = qcrypto_secret_keyring_load_data; sic->load_data = qcrypto_secret_keyring_load_data;
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
ucc->complete = qcrypto_secret_keyring_complete;
object_class_property_add(oc, "serial", "int32_t", object_class_property_add(oc, "serial", "int32_t",
qcrypto_secret_prop_get_key, qcrypto_secret_prop_get_key,
qcrypto_secret_prop_set_key, qcrypto_secret_prop_set_key,
@ -130,10 +120,6 @@ static const TypeInfo qcrypto_secret_info = {
.name = TYPE_QCRYPTO_SECRET_KEYRING, .name = TYPE_QCRYPTO_SECRET_KEYRING,
.instance_size = sizeof(QCryptoSecretKeyring), .instance_size = sizeof(QCryptoSecretKeyring),
.class_init = qcrypto_secret_keyring_class_init, .class_init = qcrypto_secret_keyring_class_init,
.interfaces = (InterfaceInfo[]) {
{ TYPE_USER_CREATABLE },
{ }
}
}; };