pkcs15-crypt: Allow the use of stdin if no input file is specified.

This commit is contained in:
Chris Elledge 2016-01-20 15:35:44 -05:00
parent a0c0087446
commit 92e02b50dc
1 changed files with 13 additions and 9 deletions

View File

@ -157,13 +157,19 @@ static int read_input(u8 *buf, int buflen)
FILE *inf;
int c;
inf = fopen(opt_input, "rb");
if (inf == NULL) {
fprintf(stderr, "Unable to open '%s' for reading.\n", opt_input);
return -1;
if (opt_input==NULL) {
inf = stdin;
} else {
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);
fclose(inf);
if (inf!=stdin) {
fclose(inf);
}
if (c < 0) {
perror("read");
return -1;
@ -203,8 +209,7 @@ static int sign(struct sc_pkcs15_object *obj)
int r, c, len;
if (opt_input == NULL) {
fprintf(stderr, "No input file specified.\n");
return 2;
fprintf(stderr, "No input file specified. Reading from stdin\n");
}
c = read_input(buf, sizeof(buf));
@ -258,8 +263,7 @@ static int decipher(struct sc_pkcs15_object *obj)
int r, c, len;
if (opt_input == NULL) {
fprintf(stderr, "No input file specified.\n");
return 2;
fprintf(stderr, "No input file specified. Reading from stdin\n");
}
c = read_input(buf, sizeof(buf));
if (c < 0)