diff options
author | Jack Lloyd <[email protected]> | 2017-09-02 08:26:50 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-09-02 08:26:50 -0400 |
commit | e2036b0dba7084728b209fc3901398e8d46b72b9 (patch) | |
tree | fe3abd50be827c3ebd7d885f15f5f4359dc5eea8 /src/cli/cli.h | |
parent | 6cea745e6408ac4cf266086681b5d65209b33d84 (diff) |
Avoid using std::cout and std::cerr within cli code
Prevents redirection using --output and --error-output
Diffstat (limited to 'src/cli/cli.h')
-rw-r--r-- | src/cli/cli.h | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/cli/cli.h b/src/cli/cli.h index 5955dfe19..249c87722 100644 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -417,25 +417,42 @@ class Command /* * Read an entire file into memory and return the contents */ - std::vector<uint8_t> slurp_file(const std::string& input_file) const + std::vector<uint8_t> slurp_file(const std::string& input_file, + size_t buf_size = 0) const { std::vector<uint8_t> buf; auto insert_fn = [&](const uint8_t b[], size_t l) { buf.insert(buf.end(), b, b + l); }; - this->read_file(input_file, insert_fn); + this->read_file(input_file, insert_fn, buf_size); return buf; } - std::string slurp_file_as_str(const std::string& input_file) + /* + * Read an entire file into memory and return the contents + */ + Botan::secure_vector<uint8_t> slurp_file_locked(const std::string& input_file, + size_t buf_size = 0) const + { + Botan::secure_vector<uint8_t> buf; + auto insert_fn = [&](const uint8_t b[], size_t l) + { + buf.insert(buf.end(), b, b + l); + }; + this->read_file(input_file, insert_fn, buf_size); + return buf; + } + + std::string slurp_file_as_str(const std::string& input_file, + size_t buf_size = 0) const { std::string str; auto insert_fn = [&](const uint8_t b[], size_t l) { str.append(reinterpret_cast<const char*>(b), l); }; - this->read_file(input_file, insert_fn); + this->read_file(input_file, insert_fn, buf_size); return str; } @@ -471,7 +488,8 @@ class Command while(in.good()) { in.read(reinterpret_cast<char*>(buf.data()), buf.size()); - consumer_fn(buf.data(), static_cast<size_t>(in.gcount())); + const size_t got = static_cast<size_t>(in.gcount()); + consumer_fn(buf.data(), got); } } |