Add Windows passphrase prompt.

pull/2/head
Christopher Wellons 2017-03-03 20:49:45 -05:00
parent 34cda4e9a1
commit bb46184a49
3 changed files with 33 additions and 1 deletions

0
UNLICENSE Normal file → Executable file
View File

34
enchive.c Normal file → Executable file
View File

@ -111,8 +111,40 @@ get_passphrase(char *buf, size_t len, char *prompt)
fatal("could not read passphrase from /dev/tty");
}
}
#else
#elif defined(_WIN32)
#include <windows.h>
static void
get_passphrase(char *buf, size_t len, char *prompt)
{
DWORD orig;
HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
if (!GetConsoleMode(in, &orig)) {
get_passphrase_dumb(buf, len, prompt);
} else {
size_t passlen;
size_t i = 0;
DWORD n;
SetConsoleMode(in, orig & ~ENABLE_ECHO_INPUT);
fputs(prompt, stderr);
if (!fgets(buf, len, stdin))
fatal("could not read passphrase");
fputc('\n', stderr);
passlen = strlen(buf);
if (buf[passlen - 1] < ' ')
buf[passlen - 1] = 0;
}
}
/* fallback to standard open */
static FILE *
secure_creat(char *file)
{
return fopen(file, "wb");
}
#else
/* fallback to standard open */
static FILE *
secure_creat(char *file)

0
sha256.h Normal file → Executable file
View File