Skip to content

Commit

Permalink
Bug 970539, NSS tool improvements/fixes: certutil/btoa/pp/httpserv, r…
Browse files Browse the repository at this point in the history
…=rrelyea

--HG--
extra : amend_source : 50ec9151d179f3cadbf66ff958e7bda7198405f9
  • Loading branch information
kaie committed May 29, 2014
1 parent 2c45353 commit a435c03
Show file tree
Hide file tree
Showing 15 changed files with 858 additions and 114 deletions.
20 changes: 19 additions & 1 deletion cmd/btoa/btoa.c
Expand Up @@ -92,6 +92,10 @@ static void Usage(char *progName)
"-i input");
fprintf(stderr, "%-20s Define an output file to use (default is stdout)\n",
"-o output");
fprintf(stderr, "%-20s Wrap output in BEGIN/END lines and the given suffix\n",
"-w suffix");
fprintf(stderr, "%-20s (use \"c\" as a shortcut for suffix CERTIFICATE)\n",
"");
exit(-1);
}

Expand All @@ -102,6 +106,7 @@ int main(int argc, char **argv)
FILE *inFile, *outFile;
PLOptState *optstate;
PLOptStatus status;
char *suffix = NULL;

inFile = 0;
outFile = 0;
Expand All @@ -111,7 +116,7 @@ int main(int argc, char **argv)
progName = progName ? progName+1 : argv[0];

/* Parse command line arguments */
optstate = PL_CreateOptState(argc, argv, "i:o:");
optstate = PL_CreateOptState(argc, argv, "i:o:w:");
while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) {
switch (optstate->option) {
default:
Expand All @@ -135,6 +140,13 @@ int main(int argc, char **argv)
return -1;
}
break;

case 'w':
if (!strcmp(optstate->value, "c"))
suffix = strdup("CERTIFICATE");
else
suffix = strdup(optstate->value);
break;
}
}
if (status == PL_OPT_BAD)
Expand Down Expand Up @@ -171,11 +183,17 @@ int main(int argc, char **argv)
#endif
outFile = stdout;
}
if (suffix) {
fprintf(outFile, "-----BEGIN %s-----\n", suffix);
}
rv = encode_file(outFile, inFile);
if (rv != SECSuccess) {
fprintf(stderr, "%s: lossage: error=%d errno=%d\n",
progName, PORT_GetError(), errno);
return -1;
}
if (suffix) {
fprintf(outFile, "-----END %s-----\n", suffix);
}
return 0;
}

0 comments on commit a435c03

Please sign in to comment.