Add clang-tidy support for the CDM

Bug: 256230932
Change-Id: Id3fcf024cd7dcf95218876b81359d6418f5aa067
This commit is contained in:
Ian Benz
2023-04-11 20:46:08 +00:00
committed by Robert Shih
parent b7b423aca3
commit cebd90e300
37 changed files with 209 additions and 185 deletions

View File

@@ -1249,7 +1249,7 @@ CdmResponseType CdmSession::LoadPrivateKey(
DrmKeyTypeToMetricValue(private_key.type()));
drm_certificate_ = drm_certificate;
wrapped_private_key_ = std::move(private_key);
wrapped_private_key_ = private_key;
return CdmResponseType(NO_ERROR);
case SESSION_LOST_STATE_ERROR:
case SYSTEM_INVALIDATED_ERROR:

View File

@@ -317,8 +317,6 @@ CdmResponseType CdmUsageTable::LoadEntry(CryptoSession* crypto_session,
return CdmResponseType(USAGE_INVALID_LOAD_ENTRY);
}
}
metrics::CryptoMetrics* metrics = crypto_session->GetCryptoMetrics();
if (metrics == nullptr) metrics = &alternate_crypto_metrics_;
const CdmResponseType status =
crypto_session->LoadUsageEntry(entry_index, entry);
@@ -590,14 +588,11 @@ CdmResponseType CdmUsageTable::RelocateNewEntry(
}
bool CdmUsageTable::IsEntryUnoccupied(const UsageEntryIndex entry_index) const {
if (entry_info_list_[entry_index].storage_type != kStorageTypeUnknown) {
return false;
}
// TODO(sigquit): Check that entry is not in use by another session.
// NOTE: The |storage_type| check will protect the integrity of the
// entry. Attempting to use an entry index that is used by another
// session is recoverable and will not affect any opened sessions.
return true;
return entry_info_list_[entry_index].storage_type == kStorageTypeUnknown;
}
void CdmUsageTable::SetOfflineEntryInfo(const UsageEntryIndex entry_index,

View File

@@ -89,7 +89,6 @@ bool RetrieveOemCertificateAndLoadPrivateKey(CryptoSession& crypto_session,
} // namespace
// Protobuf generated classes.
using video_widevine::DrmCertificate;
using video_widevine::EncryptedClientIdentification;
using video_widevine::HashAlgorithmProto;
using video_widevine::ProvisioningOptions;
using video_widevine::ProvisioningRequest;

View File

@@ -62,11 +62,6 @@ using ClientCapabilities =
video_widevine::ClientIdentification::ClientCapabilities;
using AnalogOutputCapabilities = ClientCapabilities::AnalogOutputCapabilities;
using video_widevine::ClientIdentification_NameValue;
using video_widevine::EncryptedClientIdentification;
using video_widevine::ProvisioningOptions;
using video_widevine::ProvisioningRequest;
using video_widevine::ProvisioningResponse;
using video_widevine::SignedProvisioningMessage;
CdmResponseType ClientIdentification::InitForProvisioningRequest(
const std::string& client_token, CryptoSession* crypto_session) {

View File

@@ -693,9 +693,7 @@ bool DeviceFiles::RetrieveLegacyCertificate(std::string* certificate,
const CertificateState state = RetrieveCertificate(
kCertificateLegacy, certificate, private_key, serial_number, system_id);
if (state == kCertificateValid || state == kCertificateExpired) return true;
return false;
return state == kCertificateValid || state == kCertificateExpired;
}
bool DeviceFiles::HasCertificate(bool atsc_mode_enabled) {

View File

@@ -43,11 +43,8 @@ namespace wvcdm {
// Protobuf generated classes.
using video_widevine::WidevinePsshData;
using video_widevine::WidevinePsshData_Algorithm;
using video_widevine::WidevinePsshData_Algorithm_AESCTR;
using video_widevine::WidevinePsshData_Type;
using video_widevine::WidevinePsshData_Type_ENTITLED_KEY;
using video_widevine::WidevinePsshData_Type_SINGLE;
InitializationData::InitializationData(const std::string& type,
const CdmInitData& data,
@@ -376,7 +373,7 @@ bool InitializationData::ExtractHlsAttributes(const std::string& attribute_list,
std::vector<std::string> versions = ExtractKeyFormatVersions(value);
bool supported = false;
for (size_t i = 0; i < versions.size(); ++i) {
if (versions[i].compare(HLS_KEYFORMAT_VERSION_VALUE_1) == 0) {
if (versions[i] == HLS_KEYFORMAT_VERSION_VALUE_1) {
supported = true;
break;
}
@@ -393,11 +390,11 @@ bool InitializationData::ExtractHlsAttributes(const std::string& attribute_list,
return false;
}
if (value.compare(HLS_METHOD_AES_128) == 0) {
if (value == HLS_METHOD_AES_128) {
*method = kHlsMethodAes128;
} else if (value.compare(HLS_METHOD_SAMPLE_AES) == 0) {
} else if (value == HLS_METHOD_SAMPLE_AES) {
*method = kHlsMethodSampleAes;
} else if (value.compare(HLS_METHOD_NONE) == 0) {
} else if (value == HLS_METHOD_NONE) {
*method = kHlsMethodNone;
} else {
LOGV("HLS method unrecognized: value = %s", value.c_str());
@@ -734,7 +731,8 @@ void InitializationData::DumpToLogs() const {
}
for (int i = 0; i < pssh.entitled_keys_size(); i++) {
video_widevine::WidevinePsshData_EntitledKey key = pssh.entitled_keys(i);
const video_widevine::WidevinePsshData_EntitledKey& key =
pssh.entitled_keys(i);
LOGD("InitData: entitlement_key_id %d: %s -> %s", i,
wvutil::b2a_hex(key.entitlement_key_id()).c_str(),
wvutil::b2a_hex(key.key_id()).c_str());

View File

@@ -323,7 +323,7 @@ void LicenseKeyStatus::ParseContentKey(const KeyContainer& key,
void LicenseKeyStatus::ParseOperatorSessionKey(const KeyContainer& key) {
is_content_key_ = false;
if (key.has_operator_session_key_permissions()) {
OperatorSessionKeyPermissions permissions =
const OperatorSessionKeyPermissions& permissions =
key.operator_session_key_permissions();
if (permissions.has_allow_encrypt())
allowed_usage_.generic_encrypt = permissions.allow_encrypt();

View File

@@ -10,8 +10,6 @@
#include "log.h"
using video_widevine::License;
namespace wvcdm {
void PolicyTimers::SetLicense(const video_widevine::License& license) {
@@ -68,7 +66,7 @@ bool PolicyTimers::GetSecondsSinceStarted(int64_t current_time,
if (playback_start_time_ == 0) return false;
*seconds_since_started = current_time - playback_start_time_;
return (*seconds_since_started >= 0) ? true : false;
return *seconds_since_started >= 0;
}
bool PolicyTimers::GetSecondsSinceLastPlayed(
@@ -81,7 +79,7 @@ bool PolicyTimers::GetSecondsSinceLastPlayed(
if (last_playback_time_ == 0) return false;
*seconds_since_last_played = current_time - last_playback_time_;
return (*seconds_since_last_played >= 0) ? true : false;
return *seconds_since_last_played >= 0;
}
bool PolicyTimers::IsLicenseForFuture(int64_t current_time) {

View File

@@ -28,11 +28,8 @@ bool PolicyTimersV16::UpdateLicense(int64_t current_time,
next_renewal_time_ =
license.license_start_time() + policy_.renewal_delay_seconds();
if (!policy_.can_play() ||
HasLicenseOrRentalOrPlaybackDurationExpired(current_time))
return false;
return true;
return policy_.can_play() &&
!HasLicenseOrRentalOrPlaybackDurationExpired(current_time);
}
void PolicyTimersV16::BeginDecryption(int64_t current_time) {

View File

@@ -65,11 +65,8 @@ bool PolicyTimersV18::UpdateLicense(int64_t current_time,
license_renewal_ = true;
}
if (!policy_.can_play() ||
HasLicenseOrRentalOrPlaybackDurationExpired(current_time))
return false;
return true;
return policy_.can_play() &&
!HasLicenseOrRentalOrPlaybackDurationExpired(current_time);
}
void PolicyTimersV18::BeginDecryption(int64_t current_time) {

View File

@@ -19,7 +19,7 @@ namespace {
// as the root of a signing chain.
// clang-format off
static const unsigned char kRootCertForProd[] = {
const unsigned char kRootCertForProd[] = {
0x0a, 0x9c, 0x03, 0x08, 0x00, 0x12, 0x01, 0x00,
0x18, 0xdd, 0x94, 0x88, 0x8b, 0x05, 0x22, 0x8e,
0x03, 0x30, 0x82, 0x01, 0x8a, 0x02, 0x82, 0x01,