37 #ifndef VIRGIL_BYTE_ARRAY_H 38 #define VIRGIL_BYTE_ARRAY_H 48 namespace virgil {
namespace crypto {
61 #define VIRGIL_BYTE_ARRAY_TO_PTR_AND_LEN(array) reinterpret_cast<const unsigned char *>(array.data()), array.size() 64 #define VIRGIL_BYTE_ARRAY_FROM_PTR_AND_LEN(ptr, len)\ 65 virgil::crypto::VirgilByteArray(reinterpret_cast<virgil::crypto::VirgilByteArray::const_pointer >(ptr), \ 66 reinterpret_cast<virgil::crypto::VirgilByteArray::const_pointer >((ptr) + (len))) 69 namespace virgil {
namespace crypto {
75 return VIRGIL_BYTE_ARRAY_FROM_PTR_AND_LEN(str.data(), str.size());
82 return std::string(reinterpret_cast<const char*>(array.data()), array.size());
92 std::istringstream istr(hexStr);
93 char hexChars[3] = {0x00};
94 while (istr.read(hexChars, 2)) {
96 std::istringstream(hexChars) >> std::hex >> byte;
97 result.push_back((
unsigned char) byte);
110 std::ostringstream hexStream;
111 hexStream << std::setfill(
'0');
112 for (
size_t i = 0; i < array.size(); ++i) {
113 hexStream << std::hex << std::setw(2) << (int) array[i];
115 hexStream << (((i + 1) % 16 == 0) ?
"\n" :
" ");
118 return hexStream.str();
128 size_t n = array.size();
129 volatile unsigned char* p =
const_cast<unsigned char*
>(array.data());
130 while (n--) { *p++ = 0; }
137 size_t n = str.size();
138 volatile char* p =
const_cast<char*
>(str.c_str());
139 while (n--) { *p++ =
'\0'; }
150 dst.insert(dst.end(), src.cbegin(), src.cend());
161 return std::make_tuple(
172 const auto halfPos = src.size() >> 1;
VirgilByteArray str2bytes(const std::string &str)
Represents given string as byte array.
Definition: VirgilByteArray.h:74
VirgilByteArray & bytes_append(VirgilByteArray &dst, const VirgilByteArray &src)
Append given source bytes to the existing destination bytes.
Definition: VirgilByteArray.h:149
std::tuple< VirgilByteArray, VirgilByteArray > bytes_split_half(const VirgilByteArray &src)
Split given bytes to two sequences of the same size.
Definition: VirgilByteArray.h:171
VirgilByteArray hex2bytes(const std::string hexStr)
Translate given HEX string to the byte array.
Definition: VirgilByteArray.h:90
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:54
void bytes_zeroize(VirgilByteArray &array)
Make all bytes zero.
Definition: VirgilByteArray.h:127
std::string bytes2hex(const VirgilByteArray &array, bool formatted=false)
Translate given byte array to the HEX string.
Definition: VirgilByteArray.h:109
void string_zeroize(std::string &str)
Make all chars zero.
Definition: VirgilByteArray.h:136
std::string bytes2str(const VirgilByteArray &array)
Represent given byte array as string.
Definition: VirgilByteArray.h:81
std::tuple< VirgilByteArray, VirgilByteArray > bytes_split(const VirgilByteArray &src, size_t pos)
Split given bytes to two sequences.
Definition: VirgilByteArray.h:160