Run clang-format on Core
This copies over formatting changes from the Widevine CDM repository that resulted from running clang-format with Google style on the shared core/ directory. It also copies over some rewordings of log messages that were made at the same time. Aside from the changed log messages, this should not affect behavior or functionality. Change-Id: I69c57c188f7a79f30fa3517afeed17365929b6b6
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
#include "device_files.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# include <CommonCrypto/CommonDigest.h>
|
||||
# define SHA256 CC_SHA256
|
||||
# define SHA256_DIGEST_LENGTH CC_SHA256_DIGEST_LENGTH
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#define SHA256 CC_SHA256
|
||||
#define SHA256_DIGEST_LENGTH CC_SHA256_DIGEST_LENGTH
|
||||
#else
|
||||
# include <openssl/sha.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/md5.h>
|
||||
#endif
|
||||
|
||||
@@ -49,7 +49,7 @@ bool Hash(const std::string& data, std::string* hash) {
|
||||
hash->resize(SHA256_DIGEST_LENGTH);
|
||||
|
||||
const unsigned char* input =
|
||||
reinterpret_cast<const unsigned char*>(data.data());
|
||||
reinterpret_cast<const unsigned char*>(data.data());
|
||||
unsigned char* output = reinterpret_cast<unsigned char*>(&(*hash)[0]);
|
||||
SHA256(input, data.size(), output);
|
||||
return true;
|
||||
@@ -60,9 +60,10 @@ bool Hash(const std::string& data, std::string* hash) {
|
||||
namespace wvcdm {
|
||||
|
||||
DeviceFiles::DeviceFiles()
|
||||
: file_(NULL), security_level_(kSecurityLevelUninitialized),
|
||||
initialized_(false), test_file_(false) {
|
||||
}
|
||||
: file_(NULL),
|
||||
security_level_(kSecurityLevelUninitialized),
|
||||
initialized_(false),
|
||||
test_file_(false) {}
|
||||
|
||||
DeviceFiles::~DeviceFiles() {
|
||||
if (test_file_) file_.release();
|
||||
@@ -119,8 +120,7 @@ bool DeviceFiles::RetrieveCertificate(std::string* certificate,
|
||||
}
|
||||
|
||||
std::string serialized_file;
|
||||
if (!RetrieveHashedFile(kCertificateFileName, &serialized_file))
|
||||
return false;
|
||||
if (!RetrieveHashedFile(kCertificateFileName, &serialized_file)) return false;
|
||||
|
||||
video_widevine_client::sdk::File file;
|
||||
if (!file.ParseFromString(serialized_file)) {
|
||||
@@ -200,15 +200,12 @@ bool DeviceFiles::StoreLicense(const std::string& key_set_id,
|
||||
return StoreFileWithHash(file_name.c_str(), serialized_file);
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveLicense(const std::string& key_set_id,
|
||||
LicenseState* state, CdmInitData* pssh_data,
|
||||
CdmKeyMessage* license_request,
|
||||
CdmKeyResponse* license_message,
|
||||
CdmKeyMessage* license_renewal_request,
|
||||
CdmKeyResponse* license_renewal,
|
||||
std::string* release_server_url,
|
||||
int64_t* playback_start_time,
|
||||
int64_t* last_playback_time) {
|
||||
bool DeviceFiles::RetrieveLicense(
|
||||
const std::string& key_set_id, LicenseState* state, CdmInitData* pssh_data,
|
||||
CdmKeyMessage* license_request, CdmKeyResponse* license_message,
|
||||
CdmKeyMessage* license_renewal_request, CdmKeyResponse* license_renewal,
|
||||
std::string* release_server_url, int64_t* playback_start_time,
|
||||
int64_t* last_playback_time) {
|
||||
if (!initialized_) {
|
||||
LOGW("DeviceFiles::RetrieveLicense: not initialized");
|
||||
return false;
|
||||
@@ -368,10 +365,8 @@ bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
|
||||
|
||||
provider_session->set_token(provider_session_token.data(),
|
||||
provider_session_token.size());
|
||||
provider_session->set_license_request(key_request.data(),
|
||||
key_request.size());
|
||||
provider_session->set_license(key_response.data(),
|
||||
key_response.size());
|
||||
provider_session->set_license_request(key_request.data(), key_request.size());
|
||||
provider_session->set_license(key_response.data(), key_response.size());
|
||||
|
||||
file.SerializeToString(&serialized_file);
|
||||
return StoreFileWithHash(file_name.c_str(), serialized_file);
|
||||
@@ -398,15 +393,18 @@ bool DeviceFiles::DeleteUsageInfo(const std::string& app_id,
|
||||
int index = 0;
|
||||
bool found = false;
|
||||
for (; index < usage_info->sessions_size(); ++index) {
|
||||
if (usage_info->sessions(index).token().compare(provider_session_token) == 0) {
|
||||
if (usage_info->sessions(index).token().compare(provider_session_token) ==
|
||||
0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
LOGW("DeviceFiles::DeleteUsageInfo: Unable to find provider session "
|
||||
"token: %s", b2a_hex(provider_session_token).c_str());
|
||||
LOGW(
|
||||
"DeviceFiles::DeleteUsageInfo: Unable to find provider session "
|
||||
"token: %s",
|
||||
b2a_hex(provider_session_token).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -439,7 +437,7 @@ bool DeviceFiles::DeleteAllUsageInfoForApp(const std::string& app_id) {
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveUsageInfo(
|
||||
const std::string &app_id,
|
||||
const std::string& app_id,
|
||||
std::vector<std::pair<CdmKeyMessage, CdmKeyResponse> >* usage_info) {
|
||||
if (!initialized_) {
|
||||
LOGW("DeviceFiles::RetrieveUsageInfo: not initialized");
|
||||
@@ -447,7 +445,8 @@ bool DeviceFiles::RetrieveUsageInfo(
|
||||
}
|
||||
|
||||
if (NULL == usage_info) {
|
||||
LOGW("DeviceFiles::RetrieveUsageInfo: license destination not "
|
||||
LOGW(
|
||||
"DeviceFiles::RetrieveUsageInfo: license destination not "
|
||||
"provided");
|
||||
return false;
|
||||
}
|
||||
@@ -581,24 +580,24 @@ bool DeviceFiles::StoreFileRaw(const char* name,
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t bytes = file_->Write(serialized_file.data(),
|
||||
serialized_file.size());
|
||||
ssize_t bytes = file_->Write(serialized_file.data(), serialized_file.size());
|
||||
file_->Close();
|
||||
|
||||
if (bytes != static_cast<ssize_t>(serialized_file.size())) {
|
||||
LOGW("DeviceFiles::StoreFileRaw: write failed: (actual: %d, expected: %d)",
|
||||
bytes,
|
||||
serialized_file.size());
|
||||
LOGW(
|
||||
"DeviceFiles::StoreFileRaw: write failed: (actual: %d, "
|
||||
"expected: %d)",
|
||||
bytes, serialized_file.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGV("DeviceFiles::StoreFileRaw: success: %s (%db)",
|
||||
path.c_str(),
|
||||
serialized_file.size());
|
||||
LOGV("DeviceFiles::StoreFileRaw: success: %s (%db)", path.c_str(),
|
||||
serialized_file.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceFiles::RetrieveHashedFile(const char* name, std::string* serialized_file) {
|
||||
bool DeviceFiles::RetrieveHashedFile(const char* name,
|
||||
std::string* serialized_file) {
|
||||
if (!file_.get()) {
|
||||
LOGW("DeviceFiles::RetrieveHashedFile: Invalid file handle");
|
||||
return false;
|
||||
@@ -610,13 +609,15 @@ bool DeviceFiles::RetrieveHashedFile(const char* name, std::string* serialized_f
|
||||
}
|
||||
|
||||
if (!serialized_file) {
|
||||
LOGW("DeviceFiles::RetrieveHashedFile: Unspecified serialized_file parameter");
|
||||
LOGW(
|
||||
"DeviceFiles::RetrieveHashedFile: Unspecified serialized_file "
|
||||
"parameter");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string path;
|
||||
if (!Properties::GetDeviceFilesBasePath(security_level_, &path)) {
|
||||
LOGW("DeviceFiles::StoreFile: Unable to get base path");
|
||||
LOGW("DeviceFiles::StoreFileWithHash: Unable to get base path");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -629,7 +630,8 @@ bool DeviceFiles::RetrieveHashedFile(const char* name, std::string* serialized_f
|
||||
|
||||
ssize_t bytes = file_->FileSize(path);
|
||||
if (bytes <= 0) {
|
||||
LOGW("DeviceFiles::RetrieveHashedFile: File size invalid: %s", path.c_str());
|
||||
LOGW("DeviceFiles::RetrieveHashedFile: File size invalid: %s",
|
||||
path.c_str());
|
||||
// Remove the corrupted file so the caller will not get the same error
|
||||
// when trying to access the file repeatedly, causing the system to stall.
|
||||
file_->Remove(path);
|
||||
@@ -750,8 +752,10 @@ std::string DeviceFiles::GetLicenseFileNameExtension() {
|
||||
}
|
||||
|
||||
std::string DeviceFiles::GetUsageInfoFileName(const std::string& app_id) {
|
||||
if (app_id == "") return std::string(kUsageInfoFileNamePrefix)
|
||||
+ std::string(kUsageInfoFileNameExt);
|
||||
if (app_id == "") {
|
||||
return std::string(kUsageInfoFileNamePrefix) +
|
||||
std::string(kUsageInfoFileNameExt);
|
||||
}
|
||||
std::vector<uint8_t> hash(MD5_DIGEST_LENGTH);
|
||||
const unsigned char* input =
|
||||
reinterpret_cast<const unsigned char*>(app_id.data());
|
||||
|
||||
Reference in New Issue
Block a user