From 811082063c0dfd895a2c01d446af1411951f285b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 3 May 2020 17:04:27 +0000 Subject: [PATCH] signing: Add #define OSTREE_SIGN_NAME_ED25519 Using `#define` or constants instead of strings helps avoid typos and encourages documentation. --- src/libostree/ostree-sign.c | 2 +- src/libostree/ostree-sign.h | 6 ++++++ src/ostree/ot-builtin-commit.c | 3 +-- src/ostree/ot-builtin-sign.c | 3 +-- src/ostree/ot-builtin-summary.c | 3 +-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/libostree/ostree-sign.c b/src/libostree/ostree-sign.c index 281fabc8..68447da6 100644 --- a/src/libostree/ostree-sign.c +++ b/src/libostree/ostree-sign.c @@ -62,7 +62,7 @@ typedef struct _sign_type sign_types[] = { #if defined(HAVE_LIBSODIUM) - {"ed25519", 0}, + {OSTREE_SIGN_NAME_ED25519, 0}, #endif {"dummy", 0} }; diff --git a/src/libostree/ostree-sign.h b/src/libostree/ostree-sign.h index 678f182d..da10469b 100644 --- a/src/libostree/ostree-sign.h +++ b/src/libostree/ostree-sign.h @@ -49,6 +49,12 @@ static inline gboolean OSTREE_IS_SIGN (gpointer ptr) { return G_TYPE_CHECK_INSTA static inline OstreeSignInterface *OSTREE_SIGN_GET_IFACE (gpointer ptr) { return G_TYPE_INSTANCE_GET_INTERFACE (ptr, ostree_sign_get_type (), OstreeSignInterface); } G_GNUC_END_IGNORE_DEPRECATIONS +/** + * OSTREE_SIGN_NAME_ED25519: + * The name of the default ed25519 signing type. + */ +#define OSTREE_SIGN_NAME_ED25519 "ed25519" + /* Have to use glib-2.44 for this _OSTREE_PUBLIC G_DECLARE_INTERFACE (OstreeSign, ostree_sign, OSTREE, SIGN, GObject) diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index 72fa2841..88a5d4f4 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -868,8 +868,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (opt_key_ids) { /* Initialize crypto system */ - if (!opt_sign_name) - opt_sign_name = "ed25519"; + opt_sign_name = opt_sign_name ?: OSTREE_SIGN_NAME_ED25519; sign = ostree_sign_get_by_name (opt_sign_name, error); if (sign == NULL) diff --git a/src/ostree/ot-builtin-sign.c b/src/ostree/ot-builtin-sign.c index 73561b43..d6cc167a 100644 --- a/src/ostree/ot-builtin-sign.c +++ b/src/ostree/ot-builtin-sign.c @@ -105,8 +105,7 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, goto out; /* Initialize crypto system */ - if (!opt_sign_name) - opt_sign_name = "ed25519"; + opt_sign_name = opt_sign_name ?: OSTREE_SIGN_NAME_ED25519; sign = ostree_sign_get_by_name (opt_sign_name, error); if (sign == NULL) diff --git a/src/ostree/ot-builtin-summary.c b/src/ostree/ot-builtin-summary.c index de6df835..0938f11e 100644 --- a/src/ostree/ot-builtin-summary.c +++ b/src/ostree/ot-builtin-summary.c @@ -103,8 +103,7 @@ ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocati /* Initialize crypto system */ if (opt_key_ids) { - if (!opt_sign_name) - opt_sign_name = "ed25519"; + opt_sign_name = opt_sign_name ?: OSTREE_SIGN_NAME_ED25519; sign = ostree_sign_get_by_name (opt_sign_name, error); if (sign == NULL)