summaryrefslogtreecommitdiff
path: root/futility/cmd_vbutil_key.c
diff options
context:
space:
mode:
Diffstat (limited to 'futility/cmd_vbutil_key.c')
-rw-r--r--futility/cmd_vbutil_key.c76
1 files changed, 35 insertions, 41 deletions
diff --git a/futility/cmd_vbutil_key.c b/futility/cmd_vbutil_key.c
index c8c1c61b..ea8dea0b 100644
--- a/futility/cmd_vbutil_key.c
+++ b/futility/cmd_vbutil_key.c
@@ -38,40 +38,32 @@ static const struct option long_opts[] = {
{NULL, 0, 0, 0}
};
-/* Print help and return error */
-static int PrintHelp(char *progname)
+static void print_help(const char *progname)
{
int i;
- fprintf(stderr,
- "This program wraps RSA keys with verified boot headers\n");
- fprintf(stderr,
- "\n"
- "Usage: %s --pack <outfile> [PARAMETERS]\n"
- "\n"
- " Required parameters:\n"
- " --key <infile> RSA key file (.keyb or .pem)\n"
- " --version <number> Key version number "
- "(required for .keyb,\n"
- " ignored for .pem)\n"
- " --algorithm <number> "
- "Signing algorithm to use with key:\n", progname);
+ printf("\n"
+ "Usage: " MYNAME " %s --pack <outfile> [PARAMETERS]\n"
+ "\n"
+ " Required parameters:\n"
+ " --key <infile> RSA key file (.keyb or .pem)\n"
+ " --version <number> Key version number "
+ "(required for .keyb,\n"
+ " ignored for .pem)\n"
+ " --algorithm <number> "
+ "Signing algorithm to use with key:\n", progname);
for (i = 0; i < kNumAlgorithms; i++) {
- fprintf(stderr,
- " %d = (%s)\n",
- i, algo_strings[i]);
+ printf(" %d = (%s)\n",
+ i, algo_strings[i]);
}
- fprintf(stderr,
- "\nOR\n\n"
- "Usage: %s --unpack <infile>\n"
- "\n"
- " Optional parameters:\n"
- " --copyto <file> "
- "Write a copy of the key to this file.\n" "\n", progname);
-
- return 1;
+ printf("\nOR\n\n"
+ "Usage: " MYNAME " %s --unpack <infile>\n"
+ "\n"
+ " Optional parameters:\n"
+ " --copyto <file> "
+ "Write a copy of the key to this file.\n\n", progname);
}
/* Pack a .keyb file into a .vbpubk, or a .pem into a .vbprivk */
@@ -86,7 +78,8 @@ static int Pack(const char *infile, const char *outfile, uint64_t algorithm,
return 1;
}
- if ((pubkey = PublicKeyReadKeyb(infile, algorithm, version))) {
+ pubkey = PublicKeyReadKeyb(infile, algorithm, version);
+ if (pubkey) {
if (0 != PublicKeyWrite(outfile, pubkey)) {
fprintf(stderr, "vbutil_key: Error writing key.\n");
return 1;
@@ -95,7 +88,8 @@ static int Pack(const char *infile, const char *outfile, uint64_t algorithm,
return 0;
}
- if ((privkey = PrivateKeyReadPem(infile, algorithm))) {
+ privkey = PrivateKeyReadPem(infile, algorithm);
+ if (privkey) {
if (0 != PrivateKeyWrite(outfile, privkey)) {
fprintf(stderr, "vbutil_key: Error writing key.\n");
return 1;
@@ -119,7 +113,8 @@ static int Unpack(const char *infile, const char *outfile)
return 1;
}
- if ((pubkey = PublicKeyRead(infile))) {
+ pubkey = PublicKeyRead(infile);
+ if (pubkey) {
printf("Public Key file: %s\n", infile);
printf("Algorithm: %" PRIu64 " %s\n", pubkey->algorithm,
(pubkey->algorithm < kNumAlgorithms ?
@@ -140,7 +135,8 @@ static int Unpack(const char *infile, const char *outfile)
return 0;
}
- if ((privkey = PrivateKeyRead(infile))) {
+ privkey = PrivateKeyRead(infile);
+ if (privkey) {
printf("Private Key file: %s\n", infile);
printf("Algorithm: %" PRIu64 " %s\n",
privkey->algorithm,
@@ -177,12 +173,6 @@ static int do_vbutil_key(int argc, char *argv[])
char *e;
int i;
- char *progname = strrchr(argv[0], '/');
- if (progname)
- progname++;
- else
- progname = argv[0];
-
while ((i = getopt_long(argc, argv, "", long_opts, NULL)) != -1) {
switch (i) {
case '?':
@@ -227,8 +217,10 @@ static int do_vbutil_key(int argc, char *argv[])
}
}
- if (parse_error)
- return PrintHelp(progname);
+ if (parse_error) {
+ print_help(argv[0]);
+ return 1;
+ }
switch (mode) {
case OPT_MODE_PACK:
@@ -237,9 +229,11 @@ static int do_vbutil_key(int argc, char *argv[])
return Unpack(infile, outfile);
default:
printf("Must specify a mode.\n");
- return PrintHelp(progname);
+ print_help(argv[0]);
+ return 1;
}
}
DECLARE_FUTIL_COMMAND(vbutil_key, do_vbutil_key,
- "Wraps RSA keys with vboot headers");
+ "Wraps RSA keys with vboot headers",
+ print_help);