rip input_ready() and call isatty() instead
should be more portable (work on windows) relates to #12
This commit is contained in:
-17
@@ -57,23 +57,6 @@ FILE *open_file(const char *file_name, int mode) {
|
||||
return file;
|
||||
}
|
||||
|
||||
bool input_ready(FILE *file) {
|
||||
int fd = fileno(file);
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(fd, &rfds);
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
if(select(fd + 1, &rfds, NULL, NULL, &tv) == 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned char get_algorithm(EVP_PKEY *key) {
|
||||
int type = EVP_PKEY_type(key->type);
|
||||
switch(type) {
|
||||
|
||||
@@ -45,6 +45,5 @@ unsigned char get_algorithm(EVP_PKEY*);
|
||||
FILE *open_file(const char*, int);
|
||||
int get_object_id(enum enum_slot slot);
|
||||
bool set_component_with_len(unsigned char**, const BIGNUM*, int);
|
||||
bool input_ready(FILE*);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ykpiv.h"
|
||||
|
||||
@@ -290,7 +291,7 @@ static bool import_key(ykpiv_state *state, enum enum_key_format key_format,
|
||||
return false;
|
||||
}
|
||||
|
||||
if(input_file == stdin && !input_ready(input_file)) {
|
||||
if(isatty(fileno(input_file))) {
|
||||
fprintf(stderr, "Please paste the private key...\n");
|
||||
}
|
||||
|
||||
@@ -416,7 +417,7 @@ static bool import_cert(ykpiv_state *state, enum enum_key_format cert_format,
|
||||
return false;
|
||||
}
|
||||
|
||||
if(input_file == stdin && !input_ready(input_file)) {
|
||||
if(isatty(fileno(input_file))) {
|
||||
fprintf(stderr, "Please paste the certificate...\n");
|
||||
}
|
||||
|
||||
@@ -563,7 +564,7 @@ static bool request_certificate(ykpiv_state *state, enum enum_key_format key_for
|
||||
goto request_out;
|
||||
}
|
||||
|
||||
if(input_file == stdin && !input_ready(input_file)) {
|
||||
if(isatty(fileno(input_file))) {
|
||||
fprintf(stderr, "Please paste the public key...\n");
|
||||
}
|
||||
|
||||
@@ -746,7 +747,7 @@ static bool selfsign_certificate(ykpiv_state *state, enum enum_key_format key_fo
|
||||
goto selfsign_out;
|
||||
}
|
||||
|
||||
if(input_file == stdin && !input_ready(input_file)) {
|
||||
if(isatty(fileno(input_file))) {
|
||||
fprintf(stderr, "Please paste the public key...\n");
|
||||
}
|
||||
|
||||
@@ -1023,7 +1024,7 @@ static bool sign_file(ykpiv_state *state, const char *input, const char *output,
|
||||
return false;
|
||||
}
|
||||
|
||||
if(input_file == stdin && !input_ready(input_file)) {
|
||||
if(isatty(fileno(input_file))) {
|
||||
fprintf(stderr, "Please paste the input...\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user