Reboot test: save large files
[ Merge of http://go/wvgerrit/143629 ] The standard b2a_hex only saves about 2k, so we need a special version that can handle larger strings. This is needed because a license file is about 7k. Bug: 194342751 Test: GtsMediaTestCases on sunfish Change-Id: I6a6ac3f8f4fa6d9cd8a0119fc64fc8f3cc5f3ae8
This commit is contained in:
@@ -201,20 +201,34 @@ std::string b2a_hex(const std::vector<uint8_t>& byte) {
|
||||
return HexEncode(byte.data(), byte.size());
|
||||
}
|
||||
|
||||
std::string unlimited_b2a_hex(const std::vector<uint8_t>& byte) {
|
||||
if (byte.empty()) return "";
|
||||
return UnlimitedHexEncode(byte.data(), byte.size());
|
||||
}
|
||||
|
||||
std::string b2a_hex(const std::string& byte) {
|
||||
if (byte.empty()) return "";
|
||||
return HexEncode(reinterpret_cast<const uint8_t*>(byte.data()),
|
||||
byte.length());
|
||||
}
|
||||
|
||||
std::string unlimited_b2a_hex(const std::string& byte) {
|
||||
if (byte.empty()) return "";
|
||||
return UnlimitedHexEncode(reinterpret_cast<const uint8_t*>(byte.data()),
|
||||
byte.length());
|
||||
}
|
||||
|
||||
std::string HexEncode(const uint8_t* in_buffer, size_t size) {
|
||||
static const char kHexChars[] = "0123456789ABCDEF";
|
||||
if (size == 0) return "";
|
||||
constexpr unsigned int kMaxSafeSize = 2048;
|
||||
if (size > kMaxSafeSize) size = kMaxSafeSize;
|
||||
return UnlimitedHexEncode(in_buffer, size);
|
||||
}
|
||||
|
||||
std::string UnlimitedHexEncode(const uint8_t* in_buffer, size_t size) {
|
||||
static const char kHexChars[] = "0123456789ABCDEF";
|
||||
if (size == 0) return "";
|
||||
// Each input byte creates two output hex characters.
|
||||
std::string out_buffer(size * 2, '\0');
|
||||
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
char byte = in_buffer[i];
|
||||
out_buffer[(i << 1)] = kHexChars[(byte >> 4) & 0xf];
|
||||
|
||||
Reference in New Issue
Block a user