OPK v19.2
This commit is contained in:
@@ -32,12 +32,12 @@ const char kBase64SafeCodes[] =
|
||||
|
||||
// Decodes a single Base64 encoded character into its 6-bit value.
|
||||
// The provided |codes| must be a Base64 character map.
|
||||
int DecodeBase64Char(char c, const char* codes) {
|
||||
int32_t DecodeBase64Char(char c, const char* codes) {
|
||||
const char* c_in_codes = strchr(codes, c);
|
||||
if (c_in_codes == nullptr) return -1;
|
||||
const uintptr_t c_in_codes_int = reinterpret_cast<uintptr_t>(c_in_codes);
|
||||
const uintptr_t codes_int = reinterpret_cast<uintptr_t>(codes);
|
||||
return static_cast<int>(c_in_codes_int - codes_int);
|
||||
return static_cast<int32_t>(c_in_codes_int - codes_int);
|
||||
}
|
||||
|
||||
bool DecodeHexChar(char ch, uint8_t* digit) {
|
||||
@@ -124,7 +124,7 @@ std::vector<uint8_t> Base64DecodeInternal(const char* encoded, size_t length,
|
||||
break;
|
||||
}
|
||||
|
||||
const int decoded = DecodeBase64Char(encoded[i], codes);
|
||||
const int32_t decoded = DecodeBase64Char(encoded[i], codes);
|
||||
if (decoded < 0) {
|
||||
LOGE("base64Decode failed");
|
||||
return std::vector<uint8_t>();
|
||||
@@ -167,8 +167,8 @@ std::vector<uint8_t> a2b_hex(const std::string& byte) {
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < count / 2; ++i) {
|
||||
unsigned char msb = 0; // most significant 4 bits
|
||||
unsigned char lsb = 0; // least significant 4 bits
|
||||
uint8_t msb = 0; // most significant 4 bits
|
||||
uint8_t lsb = 0; // least significant 4 bits
|
||||
if (!DecodeHexChar(byte[i * 2], &msb) ||
|
||||
!DecodeHexChar(byte[i * 2 + 1], &lsb)) {
|
||||
LOGE("Invalid hex value %c%c at index %zu", byte[i * 2], byte[i * 2 + 1],
|
||||
@@ -219,7 +219,7 @@ std::string unlimited_b2a_hex(const std::string& byte) {
|
||||
}
|
||||
|
||||
std::string HexEncode(const uint8_t* in_buffer, size_t size) {
|
||||
constexpr unsigned int kMaxSafeSize = 2048;
|
||||
constexpr size_t kMaxSafeSize = 2048;
|
||||
if (size > kMaxSafeSize) size = kMaxSafeSize;
|
||||
return UnlimitedHexEncode(in_buffer, size);
|
||||
}
|
||||
@@ -229,7 +229,7 @@ std::string UnlimitedHexEncode(const uint8_t* in_buffer, size_t size) {
|
||||
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) {
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
char byte = in_buffer[i];
|
||||
out_buffer[(i << 1)] = kHexChars[(byte >> 4) & 0xf];
|
||||
out_buffer[(i << 1) + 1] = kHexChars[byte & 0xf];
|
||||
@@ -331,7 +331,7 @@ int64_t htonll64(int64_t x) {
|
||||
}
|
||||
|
||||
// Encode unsigned integer into a big endian formatted string
|
||||
std::string EncodeUint32(unsigned int u) {
|
||||
std::string EncodeUint32(uint32_t u) {
|
||||
std::string s;
|
||||
s.push_back((u >> 24) & 0xFF);
|
||||
s.push_back((u >> 16) & 0xFF);
|
||||
|
||||
Reference in New Issue
Block a user