From: Jonas Rebmann <jre@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
Marco Felsch <m.felsch@pengutronix.de>,
Jonas Rebmann <jre@pengutronix.de>
Subject: [PATCH v4 2/8] crypto: keytoc: Improve readability
Date: Tue, 17 Mar 2026 16:19:46 +0100 [thread overview]
Message-ID: <20260317-keytoc-multi-env-v4-2-38ab473f8034@pengutronix.de> (raw)
In-Reply-To: <20260317-keytoc-multi-env-v4-0-38ab473f8034@pengutronix.de>
In preparation to a bigger change in the handling of the arguments list,
update variable names, function names and comments to improve
readability.
Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
scripts/keytoc.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/scripts/keytoc.c b/scripts/keytoc.c
index 77ada3af45..135a396d34 100644
--- a/scripts/keytoc.c
+++ b/scripts/keytoc.c
@@ -6,9 +6,10 @@
* URI to a C struct suitable to compile with barebox.
*
* TODO: Find a better way for reimport_key()
- *
*/
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations" /* ENGINE deprecated in OpenSSL 3.0 */
+
#include <stdio.h>
#include <string.h>
#include <time.h>
@@ -784,7 +785,7 @@ static bool parse_info(char *p, struct keyinfo *out)
}
}
-static bool get_name_path(const char *keyspec, struct keyinfo *out)
+static bool parse_keyspec(const char *keyspec, struct keyinfo *out)
{
char *sep, *spec;
@@ -814,7 +815,7 @@ static bool get_name_path(const char *keyspec, struct keyinfo *out)
int main(int argc, char *argv[])
{
- int i, opt, ret;
+ int keys_idx, opt, ret;
char *outfile = NULL;
int keycount;
struct keyinfo *keylist;
@@ -855,9 +856,9 @@ int main(int argc, char *argv[])
keycount = argc - optind;
keylist = calloc(sizeof(struct keyinfo), keycount);
- for (i = 0; i < keycount; i++) {
- const char *keyspec = try_resolve_env(argv[optind + i]);
- struct keyinfo *info = &keylist[i];
+ for (keys_idx = 0; keys_idx < keycount; keys_idx++) {
+ const char *keyspec = try_resolve_env(argv[optind + keys_idx]);
+ struct keyinfo *info = &keylist[keys_idx];
if (!keyspec)
exit(1);
@@ -865,7 +866,7 @@ int main(int argc, char *argv[])
if (!strncmp(keyspec, "pkcs11:", 7)) { // legacy format of pkcs11 URI
info->path = strdup(keyspec);
} else {
- if (!get_name_path(keyspec, info)) {
+ if (!parse_keyspec(keyspec, info)) {
fprintf(stderr, "invalid keyspec %i: %s\n", optind, keyspec);
exit(1);
}
@@ -885,14 +886,14 @@ int main(int argc, char *argv[])
}
- for (i = 0; i < keycount; i++) {
- struct keyinfo *info = &keylist[i];
+ for (keys_idx = 0; keys_idx < keycount; keys_idx++) {
+ struct keyinfo *info = &keylist[keys_idx];
/* resolve __ENV__ for name_hint and path */
info->name_hint = try_resolve_env(info->name_hint);
info->path = try_resolve_env(info->path);
- if (asprintf(&info->name_c, "key_%i", i + 1) < 0)
+ if (asprintf(&info->name_c, "key_%i", keys_idx + 1) < 0)
enomem_exit("asprintf");
/* unfortunately, the fit name hint is mandatory in the barebox codebase */
@@ -901,7 +902,7 @@ int main(int argc, char *argv[])
if (!info->keyring) {
info->keyring = strdup("fit");
- fprintf(stderr, "Warning: No keyring provided in keyspec, defaulting to keyring=fit for %s\n", argv[optind + i]);
+ fprintf(stderr, "Warning: No keyring provided in keyspec, defaulting to keyring=fit for %s\n", argv[optind + keys_idx]);
}
ret = gen_key(info);
--
2.53.0.308.g50d063e335
next prev parent reply other threads:[~2026-03-17 15:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 15:19 [PATCH v4 0/8] Allow multiple keyspecs in one environment variable Jonas Rebmann
2026-03-17 15:19 ` [PATCH v4 1/8] scripts: include: Add string_util.h for strsep_unescaped Jonas Rebmann
2026-03-17 15:19 ` Jonas Rebmann [this message]
2026-03-17 15:19 ` [PATCH v4 3/8] crypto: keytoc: Move special handling of legacy pkcs11 format to parse_keyspec Jonas Rebmann
2026-03-17 15:19 ` [PATCH v4 4/8] crypto: keytoc: Parse all keyspecs before writing to stdout Jonas Rebmann
2026-03-17 15:19 ` [PATCH v4 5/8] crypto: keytoc: Split env-provided full keyspec on spaces Jonas Rebmann
2026-03-17 15:19 ` [PATCH v4 6/8] Documentation: migration-guides: Document change in keyspec env vars Jonas Rebmann
2026-03-17 15:19 ` [PATCH v4 7/8] crypto: keytoc: Allow fields to start with underscore Jonas Rebmann
2026-03-17 15:19 ` [PATCH v4 8/8] crypto: keytoc: Deprecate fit-hint from env variable Jonas Rebmann
2026-03-18 7:34 ` [PATCH v4 0/8] Allow multiple keyspecs in one environment variable Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260317-keytoc-multi-env-v4-2-38ab473f8034@pengutronix.de \
--to=jre@pengutronix.de \
--cc=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=m.felsch@pengutronix.de \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox