Version 17 plus test updates and OPK v17

This is the first public release of OPK v17.
See the file CHANGELOG.md for details.
This commit is contained in:
Fred Gylys-Colwell
2022-04-13 19:36:27 -07:00
parent 044a89ef55
commit 0a16cb2594
308 changed files with 58159 additions and 857 deletions

View File

@@ -77,10 +77,10 @@ std::string CdmRandomGenerator::RandomData(size_t length) {
return std::string();
}
CdmRandomLock lock(generator_lock_);
std::uniform_int_distribution<uint8_t> dist; // Range of [0, 255].
std::uniform_int_distribution<short> dist(0, 255); // Range of [0, 255].
std::string random_data(length, '\0');
std::generate(random_data.begin(), random_data.end(),
[&]() { return dist(generator_); });
[&]() { return static_cast<char>(dist(generator_)); });
return random_data;
}

View File

@@ -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];