Use dynamic registration/usage invocation of command types
This commit is contained in:
@@ -31,7 +31,7 @@ static int gen(int argc, char *argv[])
|
||||
switch (getopt_long(argc, argv, "", command_opts, NULL))
|
||||
{
|
||||
case 'h':
|
||||
return command_usage(CMD_GEN, NULL);
|
||||
return command_usage(NULL);
|
||||
case 't':
|
||||
if (streq(optarg, "rsa"))
|
||||
{
|
||||
@@ -43,26 +43,26 @@ static int gen(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
return command_usage(CMD_GEN, "invalid key type");
|
||||
return command_usage("invalid key type");
|
||||
}
|
||||
continue;
|
||||
case 'o':
|
||||
if (!get_form(optarg, &form, FALSE))
|
||||
{
|
||||
return command_usage(CMD_GEN, "invalid key output format");
|
||||
return command_usage("invalid key output format");
|
||||
}
|
||||
continue;
|
||||
case 's':
|
||||
size = atoi(optarg);
|
||||
if (!size)
|
||||
{
|
||||
return command_usage(CMD_GEN, "invalid key size");
|
||||
return command_usage("invalid key size");
|
||||
}
|
||||
continue;
|
||||
case EOF:
|
||||
break;
|
||||
default:
|
||||
return command_usage(CMD_GEN, "invalid --gen option");
|
||||
return command_usage("invalid --gen option");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ static int gen(int argc, char *argv[])
|
||||
*/
|
||||
static void __attribute__ ((constructor))reg()
|
||||
{
|
||||
command_register(CMD_GEN, (command_t) {
|
||||
command_register((command_t) {
|
||||
gen, 'g', "gen", "generate a new private key",
|
||||
{"[--type rsa|ecdsa] [--size bits] [--outform der|pem|pgp]"},
|
||||
{
|
||||
|
||||
@@ -247,7 +247,7 @@ end:
|
||||
usage:
|
||||
san->destroy_offset(san, offsetof(identification_t, destroy));
|
||||
options->destroy(options);
|
||||
return command_usage(CMD_ISSUE, error);
|
||||
return command_usage(error);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,7 +255,7 @@ usage:
|
||||
*/
|
||||
static void __attribute__ ((constructor))reg()
|
||||
{
|
||||
command_register(CMD_ISSUE, (command_t) {
|
||||
command_register((command_t) {
|
||||
issue, 'i', "issue",
|
||||
"issue a certificate using a CA certificate and key",
|
||||
{"[--in file] [--type pub|pkcs10]",
|
||||
|
||||
@@ -37,7 +37,7 @@ static int keyid(int argc, char *argv[])
|
||||
switch (getopt_long(argc, argv, "", command_opts, NULL))
|
||||
{
|
||||
case 'h':
|
||||
return command_usage(CMD_KEYID, NULL);
|
||||
return command_usage(NULL);
|
||||
case 't':
|
||||
if (streq(optarg, "rsa-priv"))
|
||||
{
|
||||
@@ -61,7 +61,7 @@ static int keyid(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
return command_usage(CMD_KEYID, "invalid input type");
|
||||
return command_usage( "invalid input type");
|
||||
}
|
||||
continue;
|
||||
case 'i':
|
||||
@@ -70,7 +70,7 @@ static int keyid(int argc, char *argv[])
|
||||
case EOF:
|
||||
break;
|
||||
default:
|
||||
return command_usage(CMD_KEYID, "invalid --keyid option");
|
||||
return command_usage("invalid --keyid option");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ static int keyid(int argc, char *argv[])
|
||||
*/
|
||||
static void __attribute__ ((constructor))reg()
|
||||
{
|
||||
command_register(CMD_KEYID, (command_t)
|
||||
command_register((command_t)
|
||||
{ keyid, 'k', "keyid",
|
||||
"calculate key identifiers of a key/certificate",
|
||||
{"[--in file] [--type rsa-priv|ecdsa-priv|pub|x509]"},
|
||||
|
||||
@@ -38,7 +38,7 @@ static int pub(int argc, char *argv[])
|
||||
switch (getopt_long(argc, argv, "", command_opts, NULL))
|
||||
{
|
||||
case 'h':
|
||||
return command_usage(CMD_PUB, NULL);
|
||||
return command_usage(NULL);
|
||||
case 't':
|
||||
if (streq(optarg, "rsa"))
|
||||
{
|
||||
@@ -57,13 +57,13 @@ static int pub(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
return command_usage(CMD_PUB, "invalid input type");
|
||||
return command_usage("invalid input type");
|
||||
}
|
||||
continue;
|
||||
case 'f':
|
||||
if (!get_form(optarg, &form, TRUE))
|
||||
{
|
||||
return command_usage(CMD_PUB, "invalid output format");
|
||||
return command_usage("invalid output format");
|
||||
}
|
||||
continue;
|
||||
case 'i':
|
||||
@@ -72,7 +72,7 @@ static int pub(int argc, char *argv[])
|
||||
case EOF:
|
||||
break;
|
||||
default:
|
||||
return command_usage(CMD_PUB, "invalid --pub option");
|
||||
return command_usage("invalid --pub option");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ static int pub(int argc, char *argv[])
|
||||
*/
|
||||
static void __attribute__ ((constructor))reg()
|
||||
{
|
||||
command_register(CMD_PUB, (command_t) {
|
||||
command_register((command_t) {
|
||||
pub, 'p', "pub",
|
||||
"extract the public key from a private key/certificate",
|
||||
{"[--in file] [--type rsa|ecdsa|x509] [--outform der|pem|pgp]"},
|
||||
|
||||
@@ -206,7 +206,7 @@ end:
|
||||
usage:
|
||||
san->destroy_offset(san, offsetof(identification_t, destroy));
|
||||
options->destroy(options);
|
||||
return command_usage(CMD_SELF, error);
|
||||
return command_usage(error);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,7 +214,7 @@ usage:
|
||||
*/
|
||||
static void __attribute__ ((constructor))reg()
|
||||
{
|
||||
command_register(CMD_SELF, (command_t) {
|
||||
command_register((command_t) {
|
||||
self, 's', "self",
|
||||
"create a self signed certificate",
|
||||
{"[--in file] [--type rsa|ecdsa]",
|
||||
|
||||
@@ -32,7 +32,7 @@ static int verify(int argc, char *argv[])
|
||||
switch (getopt_long(argc, argv, "", command_opts, NULL))
|
||||
{
|
||||
case 'h':
|
||||
return command_usage(CMD_VERIFY, NULL);
|
||||
return command_usage(NULL);
|
||||
case 'i':
|
||||
file = optarg;
|
||||
continue;
|
||||
@@ -42,7 +42,7 @@ static int verify(int argc, char *argv[])
|
||||
case EOF:
|
||||
break;
|
||||
default:
|
||||
return command_usage(CMD_VERIFY, "invalid --verify option");
|
||||
return command_usage("invalid --verify option");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ static int verify(int argc, char *argv[])
|
||||
*/
|
||||
static void __attribute__ ((constructor))reg()
|
||||
{
|
||||
command_register(CMD_VERIFY, (command_t) {
|
||||
command_register((command_t) {
|
||||
verify, 'v', "verify",
|
||||
"verify a certificate using the CA certificate",
|
||||
{"[--in file] [--ca file]"},
|
||||
|
||||
Reference in New Issue
Block a user