Merge pull request #663 from digitallumens/pkcs15-crypt/stdin
pkcs15-crypt: Allow the use of stdin if no input file is specified.
This commit is contained in:
commit
b09d2777d1
|
@ -62,7 +62,8 @@
|
||||||
<option>--input</option> <replaceable>file</replaceable>,
|
<option>--input</option> <replaceable>file</replaceable>,
|
||||||
<option>-i</option> <replaceable>file</replaceable>
|
<option>-i</option> <replaceable>file</replaceable>
|
||||||
</term>
|
</term>
|
||||||
<listitem><para>Specifies the input file to use.</para></listitem>
|
<listitem><para>Specifies the input file to use. Defaults to stdin if
|
||||||
|
not specified.</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
@ -78,7 +79,8 @@
|
||||||
<option>--output</option> <replaceable>file</replaceable>,
|
<option>--output</option> <replaceable>file</replaceable>,
|
||||||
<option>-o</option> <replaceable>file</replaceable>
|
<option>-o</option> <replaceable>file</replaceable>
|
||||||
</term>
|
</term>
|
||||||
<listitem><para>Any output will be sent to the specified file.</para></listitem>
|
<listitem><para>Any output will be sent to the specified file. Defaults
|
||||||
|
to stdout if not specified.</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
|
|
@ -88,8 +88,8 @@ static const char *option_help[] = {
|
||||||
"Decipher operation",
|
"Decipher operation",
|
||||||
"Selects the private key ID to use",
|
"Selects the private key ID to use",
|
||||||
"Uses reader number <arg>",
|
"Uses reader number <arg>",
|
||||||
"Selects the input file to use",
|
"Selects the input file to use (defaults to stdin)",
|
||||||
"Outputs to file <arg>",
|
"Outputs to file <arg> (defaults to stdout)",
|
||||||
"Format for ECDSA signature <arg>: 'rs' (default), 'sequence', 'openssl'",
|
"Format for ECDSA signature <arg>: 'rs' (default), 'sequence', 'openssl'",
|
||||||
"Outputs raw 8 bit data",
|
"Outputs raw 8 bit data",
|
||||||
"Input file is a SHA-1 hash",
|
"Input file is a SHA-1 hash",
|
||||||
|
@ -157,13 +157,19 @@ static int read_input(u8 *buf, int buflen)
|
||||||
FILE *inf;
|
FILE *inf;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
inf = fopen(opt_input, "rb");
|
if (opt_input==NULL) {
|
||||||
if (inf == NULL) {
|
inf = stdin;
|
||||||
fprintf(stderr, "Unable to open '%s' for reading.\n", opt_input);
|
} else {
|
||||||
return -1;
|
inf = fopen(opt_input, "rb");
|
||||||
|
if (inf == NULL) {
|
||||||
|
fprintf(stderr, "Unable to open '%s' for reading.\n", opt_input);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c = fread(buf, 1, buflen, inf);
|
c = fread(buf, 1, buflen, inf);
|
||||||
fclose(inf);
|
if (inf!=stdin) {
|
||||||
|
fclose(inf);
|
||||||
|
}
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
perror("read");
|
perror("read");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -203,8 +209,7 @@ static int sign(struct sc_pkcs15_object *obj)
|
||||||
int r, c, len;
|
int r, c, len;
|
||||||
|
|
||||||
if (opt_input == NULL) {
|
if (opt_input == NULL) {
|
||||||
fprintf(stderr, "No input file specified.\n");
|
fprintf(stderr, "No input file specified. Reading from stdin\n");
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c = read_input(buf, sizeof(buf));
|
c = read_input(buf, sizeof(buf));
|
||||||
|
@ -258,8 +263,7 @@ static int decipher(struct sc_pkcs15_object *obj)
|
||||||
int r, c, len;
|
int r, c, len;
|
||||||
|
|
||||||
if (opt_input == NULL) {
|
if (opt_input == NULL) {
|
||||||
fprintf(stderr, "No input file specified.\n");
|
fprintf(stderr, "No input file specified. Reading from stdin\n");
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
c = read_input(buf, sizeof(buf));
|
c = read_input(buf, sizeof(buf));
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
|
|
Loading…
Reference in New Issue