summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>2019-02-15 13:40:39 +0100
committerTomasz Swierczek <t.swierczek@samsung.com>2019-02-19 17:15:25 +0100
commitf1fcc2e65a5ee398c8121621ddf10a259c395db3 (patch)
tree0541d93245246c26bb0ba0378ab610dc9e4b02bb
parentee2c14eb1eafd0ecbdb660a8deb8568090230e33 (diff)
downloadkey-manager-f1fcc2e65a5ee398c8121621ddf10a259c395db3.tar.gz
key-manager-f1fcc2e65a5ee398c8121621ddf10a259c395db3.tar.bz2
key-manager-f1fcc2e65a5ee398c8121621ddf10a259c395db3.zip
Encode blobs with Base64 in ckm tools
If an unprintable data is returned as a result of sqlite query execution it will be encoded in base64 and prefixed with "b64:". This is to make binary data readable in ckm_db_tool/merge. Also extend the maximum size of printed row to 64 characters. Change-Id: I4471090977b19ded9b1bea76f26ff1b98d5ba826
-rw-r--r--tools/ckm_db_tool/db-wrapper.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/ckm_db_tool/db-wrapper.cpp b/tools/ckm_db_tool/db-wrapper.cpp
index e7027db..00a4756 100644
--- a/tools/ckm_db_tool/db-wrapper.cpp
+++ b/tools/ckm_db_tool/db-wrapper.cpp
@@ -20,12 +20,15 @@
* @version 1.0
*/
#include <string>
+#include <algorithm>
+
+#include <base64.h>
#include <db-wrapper.h>
namespace {
-const size_t MAX_LEN = 32;
+const size_t MAX_LEN = 64;
const char ELLIPSIS[] = "...";
const size_t ELLIPSIS_LEN = sizeof(ELLIPSIS) / sizeof(ELLIPSIS[0]);
@@ -111,6 +114,22 @@ void DbWrapper::displayRow(const DB::SqlConnection::Output::Row &row, bool trim)
for (auto it = row.begin(); it != row.end(); it++) {
std::string col = *it;
+ /*
+ * Convert unprintable data to base64. Note that a row may contain an incomplete data
+ * since it holds a binary data as a string.
+ */
+ if (std::any_of(col.begin(),
+ col.end(),
+ [](const char c){ return isprint(c) + iscntrl(c) == 0; })) {
+ Base64Encoder b64enc;
+ RawBuffer tmp(col.begin(), col.end());
+ b64enc.append(tmp);
+ b64enc.finalize();
+ col = "b64:";
+ RawBuffer encoded = b64enc.get();
+ std::copy(encoded.begin(), encoded.end(), std::back_inserter(col));
+ }
+
if (trim && col.size() > MAX_LEN) {
col.resize(MAX_LEN);
col.replace(MAX_LEN - ELLIPSIS_LEN, ELLIPSIS_LEN, ELLIPSIS);