-/* Copyright (c) 2014 Samsung Electronics Co.
+/* Copyright (c) 2014-2019 Samsung Electronics Co., Ltd. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// used to pass password and raw key data
typedef SafeBuffer<unsigned char>::Type RawBuffer;
+template <class T, bool Uppercase = false>
+T hexDump(const RawBuffer &raw) {
+ T dump;
+ dump.reserve(2 * raw.size());
+ constexpr char digit[2][16] = {{
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'a', 'b', 'c', 'd', 'e', 'f'
+ }, {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'A', 'B', 'C', 'D', 'E', 'F'
+ }};
+ for (auto &e : raw) {
+ dump.push_back(digit[Uppercase][e / 16]);
+ dump.push_back(digit[Uppercase][e % 16]);
+ }
+ return dump;
+}
+
} // namespace CKM
#endif //_SAFE_BUFFER_H_
#include <cstdint>
#include <cstring>
#include <cassert>
-#include <iomanip>
-#include <sstream>
#include <unordered_map>
namespace CKM {
//raw to hex string conversion to print persistent storage data ID
static std::string rawToHexString(const RawBuffer &raw)
{
- std::string dump;
-
- for (auto &e : raw) {
- char buf[3];
- snprintf(buf, sizeof(buf), "%02x", (e & 0xff));
- dump.push_back(buf[0]);
- dump.push_back(buf[1]);
- }
-
- return dump;
+ return hexDump<std::string>(raw);
}
/*
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2019 Samsung Electronics Co., Ltd. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
RawBuffer rawToHexString(const RawBuffer &raw)
{
- RawBuffer output;
-
- for (auto &e : raw) {
- char result[3];
- snprintf(result, sizeof(result), "%02X", (e & 0xff));
- output.push_back(static_cast<unsigned char>(result[0]));
- output.push_back(static_cast<unsigned char>(result[1]));
- }
-
- return output;
+ return hexDump<RawBuffer, true>(raw);
}
RawBuffer createHexPass(const RawBuffer &rawPass)
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd. All rights reserved
*
* Contact: Kyungwook Tak <k.tak@samsung.com>
*
* @brief
*/
#include <test_common.h>
-#include <iostream>
#include <cstdlib>
#include <time.h>
//raw to hex string conversion from SqlConnection
std::string rawToHexString(const RawBuffer &raw)
{
- std::string dump;
-
- for (auto &e : raw) {
- char buf[3];
- snprintf(buf, sizeof(buf), "%02x", (e & 0xff));
- dump.push_back(buf[0]);
- dump.push_back(buf[1]);
- }
-
- return dump;
+ return hexDump<std::string>(raw);
}