diff options
author | David Clark <david.a.clark@nokia.com> | 2010-11-18 16:20:48 +1000 |
---|---|---|
committer | David Clark <david.a.clark@nokia.com> | 2010-11-18 16:20:48 +1000 |
commit | c223232bc15106750da632598047a35ad3762723 (patch) | |
tree | 403f7aa2c3a5a912edce6feae869046c89d29178 /old/botan/checks/misc.cpp | |
parent | b984b0b62076067f1f75db5a7eda5aaa2cdaad2a (diff) |
Diffstat (limited to 'old/botan/checks/misc.cpp')
-rw-r--r-- | old/botan/checks/misc.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/old/botan/checks/misc.cpp b/old/botan/checks/misc.cpp new file mode 100644 index 0000000..1986714 --- /dev/null +++ b/old/botan/checks/misc.cpp @@ -0,0 +1,77 @@ +#include <iostream> +#include <vector> +#include <string> + +#include <botan/pipe.h> +#include <botan/hex.h> +using namespace Botan; + +#include "common.h" + +void strip_comments(std::string& line) + { + if(line.find('#') != std::string::npos) + line = line.erase(line.find('#'), std::string::npos); + } + +void strip_newlines(std::string& line) + { + while(line.find('\n') != std::string::npos) + line = line.erase(line.find('\n'), 1); + } + +/* Strip comments, whitespace, etc */ +void strip(std::string& line) + { + strip_comments(line); + +#if 0 + while(line.find(' ') != std::string::npos) + line = line.erase(line.find(' '), 1); +#endif + + while(line.find('\t') != std::string::npos) + line = line.erase(line.find('\t'), 1); + } + +SecureVector<byte> decode_hex(const std::string& in) + { + SecureVector<byte> result; + + try { + Botan::Pipe pipe(new Botan::Hex_Decoder); + pipe.process_msg(in); + result = pipe.read_all(); + } + catch(std::exception& e) + { + result.destroy(); + } + return result; + } + +std::string hex_encode(const byte in[], u32bit len) + { + Botan::Pipe pipe(new Botan::Hex_Encoder); + pipe.process_msg(in, len); + return pipe.read_all_as_string(); + } + +std::vector<std::string> parse(const std::string& line) + { + const char DELIMITER = ':'; + std::vector<std::string> substr; + std::string::size_type start = 0, end = line.find(DELIMITER); + while(end != std::string::npos) + { + substr.push_back(line.substr(start, end-start)); + start = end+1; + end = line.find(DELIMITER, start); + } + if(line.size() > start) + substr.push_back(line.substr(start)); + while(substr.size() <= 4) // at least 5 substr, some possibly empty + substr.push_back(""); + return substr; + } + |