Source release 19.1.0
This commit is contained in:
@@ -120,22 +120,46 @@ const char* HDCPCapabilityAsString(OEMCrypto_HDCP_Capability value) {
|
||||
// Return a printable string from data. If all the characters are printable,
|
||||
// then just use the string. Otherwise, convert to hex.
|
||||
std::string MaybeHex(const uint8_t* data, size_t length) {
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
// Check for a early null termination. This is common for the device
|
||||
// id in a keybox, which is padded with 0s.
|
||||
const size_t c_len = strnlen(reinterpret_cast<const char*>(data), length);
|
||||
// If there is any nonzero after the first zero, then just use hex.
|
||||
for (size_t i = c_len; i < length; i++) {
|
||||
if (data[i] != 0) return "0x" + wvutil::HexEncode(data, length);
|
||||
}
|
||||
for (size_t i = 0; i < c_len; i++) {
|
||||
if (!isprint(data[i])) return "0x" + wvutil::HexEncode(data, length);
|
||||
}
|
||||
return std::string(reinterpret_cast<const char*>(data), length);
|
||||
return std::string(reinterpret_cast<const char*>(data), c_len);
|
||||
}
|
||||
|
||||
std::string MaybeHex(const std::vector<uint8_t>& data) {
|
||||
return MaybeHex(data.data(), data.size());
|
||||
}
|
||||
|
||||
// Get the Device's ID and return it in a printable format.
|
||||
std::string GetDeviceId() {
|
||||
OEMCryptoResult sts;
|
||||
std::vector<uint8_t> dev_id(128, 0);
|
||||
size_t dev_id_len = dev_id.size();
|
||||
sts = OEMCrypto_GetDeviceID(dev_id.data(), &dev_id_len);
|
||||
if (sts == OEMCrypto_ERROR_SHORT_BUFFER) {
|
||||
if (dev_id_len <= 0) return "NO DEVICE ID";
|
||||
dev_id.resize(dev_id_len);
|
||||
sts = OEMCrypto_GetDeviceID(dev_id.data(), &dev_id_len);
|
||||
}
|
||||
if (sts != OEMCrypto_SUCCESS) return "NO DEVICE ID";
|
||||
dev_id.resize(dev_id_len);
|
||||
return MaybeHex(dev_id);
|
||||
}
|
||||
|
||||
/// @addtogroup basic
|
||||
/// @{
|
||||
|
||||
TEST_F(OEMCryptoClientTest, FreeUnallocatedSecureBufferNoFailure) {
|
||||
Session s;
|
||||
s.open();
|
||||
OEMCrypto_DestBufferDesc output_descriptor;
|
||||
OEMCrypto_DestBufferDesc output_descriptor = {};
|
||||
int secure_fd = kHugeRandomNumber;
|
||||
ASSERT_NE(OEMCrypto_SUCCESS,
|
||||
OEMCrypto_FreeSecureBuffer(s.session_id(), &output_descriptor,
|
||||
@@ -156,7 +180,7 @@ TEST_F(OEMCryptoClientTest, FreeUnallocatedSecureBufferNoFailure) {
|
||||
*/
|
||||
TEST_F(OEMCryptoClientTest, VersionNumber) {
|
||||
const std::string log_message =
|
||||
"OEMCrypto unit tests for API 18.5. Tests last updated 2024-03-21";
|
||||
"OEMCrypto unit tests for API 19.1. Tests last updated 2024-03-25";
|
||||
cout << " " << log_message << "\n";
|
||||
cout << " "
|
||||
<< "These tests are part of Android U."
|
||||
@@ -164,8 +188,8 @@ TEST_F(OEMCryptoClientTest, VersionNumber) {
|
||||
LOGI("%s", log_message.c_str());
|
||||
// If any of the following fail, then it is time to update the log message
|
||||
// above.
|
||||
EXPECT_EQ(ODK_MAJOR_VERSION, 18);
|
||||
EXPECT_EQ(ODK_MINOR_VERSION, 5);
|
||||
EXPECT_EQ(ODK_MAJOR_VERSION, 19);
|
||||
EXPECT_EQ(ODK_MINOR_VERSION, 1);
|
||||
EXPECT_EQ(kCurrentAPI, static_cast<unsigned>(ODK_MAJOR_VERSION));
|
||||
OEMCrypto_Security_Level level = OEMCrypto_SecurityLevel();
|
||||
EXPECT_GT(level, OEMCrypto_Level_Unknown);
|
||||
@@ -175,6 +199,9 @@ TEST_F(OEMCryptoClientTest, VersionNumber) {
|
||||
uint32_t minor_version = OEMCrypto_MinorAPIVersion();
|
||||
cout << " OEMCrypto API version is " << version << "."
|
||||
<< minor_version << endl;
|
||||
cout << " OEMCrypto Device ID is '" << GetDeviceId() << "'"
|
||||
<< endl;
|
||||
|
||||
if (OEMCrypto_SupportsUsageTable()) {
|
||||
cout << " OEMCrypto supports usage tables" << endl;
|
||||
} else {
|
||||
@@ -261,6 +288,9 @@ TEST_F(OEMCryptoClientTest, CheckSRMCapabilityV13) {
|
||||
}
|
||||
|
||||
TEST_F(OEMCryptoClientTest, CheckNullBuildInformationAPI17) {
|
||||
if (wvoec::global_features.api_version < 17) {
|
||||
GTEST_SKIP() << "Test for versions 17 and up only.";
|
||||
}
|
||||
OEMCryptoResult sts;
|
||||
std::string build_info;
|
||||
sts = OEMCrypto_BuildInformation(&build_info[0], nullptr);
|
||||
@@ -287,6 +317,9 @@ TEST_F(OEMCryptoClientTest, CheckNullBuildInformationAPI17) {
|
||||
}
|
||||
|
||||
TEST_F(OEMCryptoClientTest, CheckJsonBuildInformationAPI18) {
|
||||
if (wvoec::global_features.api_version < 18) {
|
||||
GTEST_SKIP() << "Test for versions 18 and up only.";
|
||||
}
|
||||
std::string build_info;
|
||||
OEMCryptoResult sts = OEMCrypto_BuildInformation(&build_info[0], nullptr);
|
||||
ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, sts);
|
||||
@@ -332,7 +365,7 @@ TEST_F(OEMCryptoClientTest, CheckJsonBuildInformationAPI18) {
|
||||
// check for existence in map
|
||||
// check if value matches expectation
|
||||
// remove from map
|
||||
for (int i = 0; i < jsmn_result; i++) {
|
||||
for (int32_t i = 0; i < jsmn_result; i++) {
|
||||
jsmntok_t token = tokens[i];
|
||||
std::string key = build_info.substr(token.start, token.end - token.start);
|
||||
if (expected.find(key) != expected.end()) {
|
||||
@@ -345,7 +378,7 @@ TEST_F(OEMCryptoClientTest, CheckJsonBuildInformationAPI18) {
|
||||
// if map is not empty, return false
|
||||
if (expected.size() > 0) {
|
||||
std::string missing;
|
||||
for (auto e : expected) {
|
||||
for (const auto& e : expected) {
|
||||
missing.append(e.first);
|
||||
missing.append(" ");
|
||||
}
|
||||
@@ -389,6 +422,9 @@ TEST_F(OEMCryptoClientTest, NormalInitTermination) {
|
||||
}
|
||||
|
||||
TEST_F(OEMCryptoClientTest, CheckDTCP2CapabilityAPI17) {
|
||||
if (wvoec::global_features.api_version < 17) {
|
||||
GTEST_SKIP() << "Test for versions 17 and up only.";
|
||||
}
|
||||
OEMCryptoResult sts;
|
||||
OEMCrypto_DTCP2_Capability capability;
|
||||
sts = OEMCrypto_GetDTCP2Capability(&capability);
|
||||
|
||||
Reference in New Issue
Block a user