Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cdoc/CDoc2Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ CDoc2Writer::encrypt(libcdoc::MultiDataSource& src, const std::vector<libcdoc::R
while(result == libcdoc::OK) {
if (result = tar->open(name, size); result != libcdoc::OK)
break;
if (result = tar->writeAll(src); result != libcdoc::OK)
if (result = tar->writeAll(src); result < 0)
break;
result = src.next(name, size);
}
Expand Down
40 changes: 32 additions & 8 deletions cdoc/cdoc-tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/

#include <iostream>
#ifndef _WIN32
#include <termios.h>
#include <unistd.h>
#endif

#include "CDocCipher.h"
#include "ConsoleLogger.h"
Expand Down Expand Up @@ -449,6 +453,32 @@ parse_key_data(LockData& ldata, const int& arg_idx, int argc, char *argv[])
return 0;
}

static std::string
inputSecret(std::string_view text)
{
cout << text;
#ifdef _WIN32
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(hStdin, &mode);
SetConsoleMode(hStdin, mode & ~ENABLE_ECHO_INPUT);
#else
termios o {};
tcgetattr(STDIN_FILENO, &o);
termios n = o;
n.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &n);
#endif
string result;
getline(std::cin, result);
#ifdef _WIN32
SetConsoleMode(hStdin, mode);
#else
tcsetattr(STDIN_FILENO, TCSANOW, &o);
cout << endl;
#endif
return result;
}

//
// cdoc-tool decrypt ARGUMENTS FILE [OUTPU_DIR]
Expand Down Expand Up @@ -504,14 +534,8 @@ static int ParseAndDecrypt(int argc, char *argv[])

// Ask secret if not provided
if (ldata.secret[0] == '?') {
ldata.secret.clear();
cout << "Enter secret: ";
int ch = std::getchar();
while (ch != '\n') {
ldata.secret.push_back((uint8_t) ch);
ch = std::getchar();
}
cout << std::endl;
std::string secret = inputSecret("Enter password: ");
ldata.secret.assign(secret.cbegin(), secret.cend());
}

CDocCipher cipher;
Expand Down
2 changes: 1 addition & 1 deletion test/pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct PipeCrypto : public libcdoc::CryptoBackend {
};

struct PipeWriter {
static constexpr size_t BUFSIZE = 1024 * 1024;
static constexpr size_t BUFSIZE = 1024 * 16;

PipeWriter(libcdoc::CDocWriter *writer, const std::vector<libcdoc::FileInfo>& files) : _writer(writer), _files(files), current(-1), cpos(0) {}

Expand Down