From c63b1a4591a0a54d3ccd449573f408739ea29af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 31 Jan 2021 21:13:19 +0100 Subject: Storage: hexadecimal encoding of binary record items --- src/storage.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/storage.cpp') diff --git a/src/storage.cpp b/src/storage.cpp index 6e2f118..4cfa08d 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1,5 +1,4 @@ #include "storage.h" -#include "base64.h" #include #include @@ -1018,9 +1017,17 @@ optional> RecordT::decode(const S & st, } else if (type == "t") items->emplace_back(name, value); - else if (type == "b") - items->emplace_back(name, base64::decode(value)); - else if (type == "d") + else if (type == "b") { + if (value.size() % 2) + return nullopt; + vector binary(value.size() / 2, 0); + + for (size_t i = 0; i < binary.size(); i++) + std::from_chars(value.data() + 2 * i, + value.data() + 2 * i + 2, + binary[i], 16); + items->emplace_back(name, std::move(binary)); + } else if (type == "d") items->emplace_back(name, ZonedTime(value)); else if (type == "u") items->emplace_back(name, UUID(value)); @@ -1100,7 +1107,11 @@ vector RecordT::encodeInner() const value = *x; } else if (auto x = item.asBinary()) { type = "b"; - value = base64::encode(*x); + value.resize(x->size() * 2, '0'); + for (size_t i = 0; i < x->size(); i++) + std::to_chars(value.data() + 2 * i + ((*x)[i] < 0x10), + value.data() + 2 * i + 2, + (*x)[i], 16); } else if (auto x = item.asDate()) { type = "d"; value = string(*x); -- cgit v1.2.3