Replacing NULL with nullptr in core/

[ Merge of http://go/wvgerrit/84647 ]
[ Merge of http://go/wvgerrit/84648 ]

Replacing most instances of C's NULL with C++'s nullptr.  Also changed
how a NULL check is performed on smart pointers.  They provided an
implicit boolean operator for null checks, meaning the underlying
pointer does not need to be compared directly (as it was in some places
before).

Note that clang-format has performed additional changes to some of the
test files that have not yet been formatted.

Bug: 120602075
Test: Linux and Android unittests
Change-Id: I06ddebe34b0ea6dfecedb5527e7e808e32f5269a
This commit is contained in:
Alex Dale
2019-08-19 14:18:25 -07:00
parent f4360552b7
commit ee995d5fae
27 changed files with 432 additions and 408 deletions

View File

@@ -10,7 +10,7 @@
namespace wvcdm {
bool BufferReader::Read1(uint8_t* v) {
if (v == NULL) {
if (v == nullptr) {
LOGE("Parse failure: Null output parameter when expecting non-null");
return false;
}
@@ -27,7 +27,7 @@ bool BufferReader::Read1(uint8_t* v) {
// Internal implementation of multi-byte reads
template <typename T>
bool BufferReader::Read(T* v) {
if (v == NULL) {
if (v == nullptr) {
LOGE("Parse failure: Null output parameter when expecting non-null (%s)",
__PRETTY_FUNCTION__);
return false;
@@ -55,7 +55,7 @@ bool BufferReader::Read8(uint64_t* v) { return Read(v); }
bool BufferReader::Read8s(int64_t* v) { return Read(v); }
bool BufferReader::ReadString(std::string* str, size_t count) {
if (str == NULL) {
if (str == nullptr) {
LOGE("Parse failure: Null output parameter when expecting non-null");
return false;
}
@@ -71,7 +71,7 @@ bool BufferReader::ReadString(std::string* str, size_t count) {
}
bool BufferReader::ReadVec(std::vector<uint8_t>* vec, size_t count) {
if (vec == NULL) {
if (vec == nullptr) {
LOGE("Parse failure: Null output parameter when expecting non-null");
return false;
}
@@ -98,7 +98,7 @@ bool BufferReader::SkipBytes(size_t bytes) {
}
bool BufferReader::Read4Into8(uint64_t* v) {
if (v == NULL) {
if (v == nullptr) {
LOGE("Parse failure: Null output parameter when expecting non-null");
return false;
}
@@ -112,7 +112,7 @@ bool BufferReader::Read4Into8(uint64_t* v) {
}
bool BufferReader::Read4sInto8s(int64_t* v) {
if (v == NULL) {
if (v == nullptr) {
LOGE("Parse failure: Null output parameter when expecting non-null");
return false;
}

View File

@@ -101,14 +101,14 @@ CdmResponseType CdmEngine::OpenSession(const CdmKeySystem& key_system,
const CdmSessionId& forced_session_id,
WvCdmEventListener* event_listener) {
return OpenSession(key_system, property_set, event_listener,
&forced_session_id, NULL);
&forced_session_id, nullptr);
}
CdmResponseType CdmEngine::OpenSession(const CdmKeySystem& key_system,
CdmClientPropertySet* property_set,
WvCdmEventListener* event_listener,
CdmSessionId* session_id) {
return OpenSession(key_system, property_set, event_listener, NULL,
return OpenSession(key_system, property_set, event_listener, nullptr,
session_id);
}
@@ -182,8 +182,9 @@ CdmResponseType CdmEngine::OpenKeySetSession(
if (key_set_in_use) CloseKeySetSession(key_set_id);
CdmSessionId session_id;
CdmResponseType sts = OpenSession(KEY_SYSTEM, property_set, event_listener,
NULL /* forced_session_id */, &session_id);
CdmResponseType sts =
OpenSession(KEY_SYSTEM, property_set, event_listener,
nullptr /* forced_session_id */, &session_id);
if (sts != NO_ERROR) return sts;
@@ -882,7 +883,7 @@ CdmResponseType CdmEngine::GetProvisioningRequest(
DeleteAllUsageReportsUponFactoryReset();
if (NULL == cert_provisioning_.get()) {
if (!cert_provisioning_) {
cert_provisioning_.reset(
new CertificateProvisioning(metrics_->GetCryptoMetrics()));
CdmResponseType status = cert_provisioning_->Init(service_certificate);
@@ -892,7 +893,7 @@ CdmResponseType CdmEngine::GetProvisioningRequest(
cert_provisioning_requested_security_level_, cert_type, cert_authority,
file_system_->origin(), spoid_, request, default_url);
if (ret != NO_ERROR) {
cert_provisioning_.reset(NULL); // Release resources.
cert_provisioning_.reset(); // Release resources.
}
return ret;
}
@@ -910,20 +911,20 @@ CdmResponseType CdmEngine::HandleProvisioningResponse(
LOGI("Handling provision request");
if (response.empty()) {
LOGE("Empty provisioning response");
cert_provisioning_.reset(NULL);
cert_provisioning_.reset();
return EMPTY_PROVISIONING_RESPONSE;
}
if (cert == NULL) {
if (cert == nullptr) {
LOGE("Invalid certificate destination");
cert_provisioning_.reset(NULL);
cert_provisioning_.reset();
return INVALID_PROVISIONING_PARAMETERS_1;
}
if (wrapped_key == NULL) {
if (wrapped_key == nullptr) {
LOGE("Invalid wrapped key destination");
cert_provisioning_.reset(NULL);
cert_provisioning_.reset();
return INVALID_PROVISIONING_PARAMETERS_2;
}
if (NULL == cert_provisioning_.get()) {
if (!cert_provisioning_) {
// Certificate provisioning object has been released. Check if a concurrent
// provisioning attempt has succeeded before declaring failure.
std::unique_ptr<CryptoSession> crypto_session(
@@ -951,7 +952,7 @@ CdmResponseType CdmEngine::HandleProvisioningResponse(
// attempt was made after this one was requested but before the response was
// received, which will cause this attempt to fail. Not releasing will
// allow for the possibility that the later attempt succeeds.
if (NO_ERROR == ret) cert_provisioning_.reset(NULL);
if (NO_ERROR == ret) cert_provisioning_.reset();
return ret;
}
@@ -1184,7 +1185,7 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
CdmUsageInfo* usage_info) {
LOGI("Getting usage info: app_id = %s, ssid = %s", app_id.c_str(),
ssid.c_str());
if (NULL == usage_property_set_.get()) {
if (!usage_property_set_) {
usage_property_set_.reset(new UsagePropertySet());
}
if (!usage_info) {
@@ -1289,7 +1290,7 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
CdmUsageInfo* usage_info) {
LOGI("Getting usage info: app_id = %s, security_level = %d", app_id.c_str(),
static_cast<int>(requested_security_level));
if (NULL == usage_property_set_.get()) {
if (!usage_property_set_) {
usage_property_set_.reset(new UsagePropertySet());
}
usage_property_set_->set_security_level(requested_security_level);
@@ -1362,7 +1363,7 @@ CdmResponseType CdmEngine::RemoveAllUsageInfo(
const std::string& app_id, CdmSecurityLevel cdm_security_level) {
LOGI("Removing all usage info: app_id = %s, security_level = %d",
app_id.c_str(), static_cast<int>(cdm_security_level));
if (usage_property_set_.get() == nullptr) {
if (!usage_property_set_) {
usage_property_set_.reset(new UsagePropertySet());
}
usage_property_set_->set_app_id(app_id);
@@ -1436,7 +1437,7 @@ CdmResponseType CdmEngine::RemoveAllUsageInfo(
break;
}
}
usage_session_.reset(NULL);
usage_session_.reset();
return status;
}
@@ -1453,7 +1454,7 @@ CdmResponseType CdmEngine::RemoveUsageInfo(
const std::string& app_id, const CdmSecureStopId& provider_session_token) {
LOGI("Removing usage info: app_id = %s, pst = %s", app_id.c_str(),
provider_session_token.c_str());
if (NULL == usage_property_set_.get()) {
if (!usage_property_set_) {
usage_property_set_.reset(new UsagePropertySet());
}
usage_property_set_->set_app_id(app_id);
@@ -1492,7 +1493,7 @@ CdmResponseType CdmEngine::RemoveUsageInfo(
provider_session_token)) {
status = REMOVE_USAGE_INFO_ERROR_1;
}
usage_session_.reset(NULL);
usage_session_.reset();
return status;
}
case kUsageTableSupport: {
@@ -1522,20 +1523,20 @@ CdmResponseType CdmEngine::RemoveUsageInfo(
status = REMOVE_USAGE_INFO_ERROR_2;
}
}
usage_session_.reset(NULL);
usage_session_.reset();
return REMOVE_USAGE_INFO_ERROR_3;
}
CdmResponseType CdmEngine::ReleaseUsageInfo(
const CdmUsageInfoReleaseMessage& message) {
LOGI("Releasing usage info");
if (NULL == usage_session_.get()) {
if (!usage_session_) {
LOGE("CDM session not initialized");
return RELEASE_USAGE_INFO_ERROR;
}
CdmResponseType status = usage_session_->ReleaseKey(message);
usage_session_.reset(NULL);
usage_session_.reset();
if (NO_ERROR != status) {
LOGE("ReleaseKey failed: status = %d", status);
}
@@ -1617,22 +1618,22 @@ CdmResponseType CdmEngine::LoadUsageSession(const CdmKeySetId& key_set_id,
CdmResponseType CdmEngine::Decrypt(const CdmSessionId& session_id,
const CdmDecryptionParameters& parameters) {
if (parameters.key_id == NULL) {
if (parameters.key_id == nullptr) {
LOGE("No key ID");
return INVALID_DECRYPT_PARAMETERS_ENG_1;
}
if (parameters.encrypt_buffer == NULL) {
if (parameters.encrypt_buffer == nullptr) {
LOGE("No src encrypt buffer");
return INVALID_DECRYPT_PARAMETERS_ENG_2;
}
if (parameters.iv == NULL) {
if (parameters.iv == nullptr) {
LOGE("No IV");
return INVALID_DECRYPT_PARAMETERS_ENG_3;
}
if (parameters.decrypt_buffer == NULL) {
if (parameters.decrypt_buffer == nullptr) {
if (!parameters.is_secure &&
!Properties::Properties::oem_crypto_use_fifo()) {
LOGE("No dest decrypt buffer");
@@ -1660,7 +1661,7 @@ CdmResponseType CdmEngine::Decrypt(const CdmSessionId& session_id,
}
}
}
if (session.get() == NULL) {
if (!session) {
LOGE("Session not found: Empty session ID");
return SESSION_NOT_FOUND_FOR_DECRYPT;
}
@@ -1680,7 +1681,7 @@ CdmResponseType CdmEngine::GenericEncrypt(const std::string& session_id,
const std::string& iv,
CdmEncryptionAlgorithm algorithm,
std::string* out_buffer) {
if (out_buffer == NULL) {
if (out_buffer == nullptr) {
LOGE("No out buffer provided");
return PARAMETER_NULL;
}
@@ -1698,7 +1699,7 @@ CdmResponseType CdmEngine::GenericDecrypt(const std::string& session_id,
const std::string& iv,
CdmEncryptionAlgorithm algorithm,
std::string* out_buffer) {
if (out_buffer == NULL) {
if (out_buffer == nullptr) {
LOGE("No out buffer provided");
return PARAMETER_NULL;
}
@@ -1715,7 +1716,7 @@ CdmResponseType CdmEngine::GenericSign(const std::string& session_id,
const std::string& key_id,
CdmSigningAlgorithm algorithm,
std::string* signature) {
if (signature == NULL) {
if (signature == nullptr) {
LOGE("No signature buffer provided");
return PARAMETER_NULL;
}
@@ -1833,7 +1834,7 @@ bool CdmEngine::IsKeyLoaded(const KeyId& key_id) {
bool CdmEngine::FindSessionForKey(const KeyId& key_id,
CdmSessionId* session_id) {
if (NULL == session_id) {
if (session_id == nullptr) {
LOGE("No session ID destination provided");
return false;
}

View File

@@ -51,11 +51,11 @@ CdmSession::CdmSession(FileSystem* file_system,
is_initial_usage_update_(true),
is_usage_update_needed_(false),
usage_support_type_(kNonSecureUsageSupport),
usage_table_header_(NULL),
usage_table_header_(nullptr),
usage_entry_number_(0),
mock_license_parser_in_use_(false),
mock_policy_engine_in_use_(false) {
assert(metrics_.get()); // metrics_ must not be null.
assert(metrics_); // metrics_ must not be null.
crypto_metrics_ = metrics_->GetCryptoMetrics();
crypto_session_.reset(CryptoSession::MakeCryptoSession(crypto_metrics_));
life_span_.Start();
@@ -63,7 +63,7 @@ CdmSession::CdmSession(FileSystem* file_system,
CdmSession::~CdmSession() {
if (usage_support_type_ == kUsageEntrySupport &&
has_provider_session_token() && usage_table_header_ != NULL &&
has_provider_session_token() && usage_table_header_ != nullptr &&
!is_release_) {
UpdateUsageEntryInformation();
}
@@ -74,7 +74,7 @@ CdmSession::~CdmSession() {
}
Properties::RemoveSessionPropertySet(session_id_);
if (metrics_.get()) {
if (metrics_) {
M_RECORD(metrics_.get(), cdm_session_life_span_, life_span_.AsMs());
metrics_->SetCompleted();
}
@@ -82,7 +82,7 @@ CdmSession::~CdmSession() {
CdmResponseType CdmSession::Init(
CdmClientPropertySet* cdm_client_property_set) {
return Init(cdm_client_property_set, NULL, NULL);
return Init(cdm_client_property_set, nullptr, nullptr);
}
CdmResponseType CdmSession::Init(CdmClientPropertySet* cdm_client_property_set,
@@ -142,7 +142,7 @@ CdmResponseType CdmSession::Init(CdmClientPropertySet* cdm_client_property_set,
// indicate that provisioning is needed. Get token from stored certificate
std::string wrapped_key;
if (!file_handle_->RetrieveCertificate(&client_token, &wrapped_key,
&serial_number, NULL)) {
&serial_number, nullptr)) {
return NEED_PROVISIONING;
}
CdmResponseType load_cert_sts;
@@ -260,7 +260,7 @@ CdmResponseType CdmSession::RestoreOfflineSession(const CdmKeySetId& key_set_id,
if (usage_support_type_ == kUsageEntrySupport) {
if (!license_parser_->ExtractProviderSessionToken(
key_response_, &provider_session_token) ||
usage_table_header_ == NULL) {
usage_table_header_ == nullptr) {
provider_session_token.clear();
} else {
CdmResponseType sts = usage_table_header_->LoadEntry(
@@ -293,7 +293,7 @@ CdmResponseType CdmSession::RestoreOfflineSession(const CdmKeySetId& key_set_id,
}
if (usage_support_type_ == kUsageEntrySupport &&
!provider_session_token.empty() && usage_table_header_ != NULL) {
!provider_session_token.empty() && usage_table_header_ != nullptr) {
CdmResponseType sts =
usage_table_header_->UpdateEntry(crypto_session_.get(), &usage_entry_);
if (sts != NO_ERROR) {
@@ -329,7 +329,7 @@ CdmResponseType CdmSession::RestoreUsageSession(
CdmResponseType sts = NO_ERROR;
if (usage_support_type_ == kUsageEntrySupport &&
usage_table_header_ != NULL) {
usage_table_header_ != nullptr) {
sts = usage_table_header_->LoadEntry(crypto_session_.get(), usage_entry_,
usage_entry_number_);
crypto_metrics_->usage_table_header_load_entry_.Increment(sts);
@@ -347,7 +347,7 @@ CdmResponseType CdmSession::RestoreUsageSession(
}
if (usage_support_type_ == kUsageEntrySupport &&
usage_table_header_ != NULL) {
usage_table_header_ != nullptr) {
sts =
usage_table_header_->UpdateEntry(crypto_session_.get(), &usage_entry_);
if (sts != NO_ERROR) {
@@ -490,7 +490,7 @@ CdmResponseType CdmSession::AddKeyInternal(const CdmKeyResponse& key_response) {
CdmResponseType sts;
std::string provider_session_token;
if (usage_support_type_ == kUsageEntrySupport &&
usage_table_header_ != NULL) {
usage_table_header_ != nullptr) {
if (license_parser_->ExtractProviderSessionToken(
key_response, &provider_session_token) &&
!provider_session_token.empty()) {
@@ -513,7 +513,7 @@ CdmResponseType CdmSession::AddKeyInternal(const CdmKeyResponse& key_response) {
// Update or delete entry if usage table header+entries are supported
if (usage_support_type_ == kUsageEntrySupport &&
!provider_session_token.empty() && usage_table_header_ != NULL) {
!provider_session_token.empty() && usage_table_header_ != nullptr) {
if (sts != KEY_ADDED) {
CdmResponseType delete_sts = usage_table_header_->DeleteEntry(
usage_entry_number_, file_handle_.get(), crypto_metrics_);
@@ -537,7 +537,7 @@ CdmResponseType CdmSession::AddKeyInternal(const CdmKeyResponse& key_response) {
if (is_offline_ || has_provider_session_token()) {
if (has_provider_session_token() &&
usage_support_type_ == kUsageEntrySupport &&
usage_table_header_ != NULL) {
usage_table_header_ != nullptr) {
usage_table_header_->UpdateEntry(crypto_session_.get(), &usage_entry_);
}
@@ -656,7 +656,7 @@ CdmResponseType CdmSession::GenerateRenewalRequest(CdmKeyRequest* key_request) {
return NOT_INITIALIZED_ERROR;
}
CdmResponseType status = license_parser_->PrepareKeyUpdateRequest(
true, app_parameters_, NULL, &key_request->message, &key_request->url);
true, app_parameters_, nullptr, &key_request->message, &key_request->url);
key_request->type = kKeyRequestTypeRenewal;
@@ -701,7 +701,7 @@ CdmResponseType CdmSession::GenerateReleaseRequest(CdmKeyRequest* key_request) {
is_release_ = true;
license_request_latency_.Clear();
CdmResponseType status = license_parser_->PrepareKeyUpdateRequest(
false, app_parameters_, usage_table_header_ == NULL ? NULL : this,
false, app_parameters_, usage_table_header_ == nullptr ? nullptr : this,
&key_request->message, &key_request->url);
key_request->type = kKeyRequestTypeRelease;
@@ -771,7 +771,7 @@ CdmResponseType CdmSession::DeleteUsageEntry(uint32_t usage_entry_number) {
crypto_metrics_, crypto_session_open_, sts, requested_security_level_);
if (sts != NO_ERROR) return sts;
usage_table_header_ = NULL;
usage_table_header_ = nullptr;
if (crypto_session_->GetUsageSupportType(&usage_support_type_) == NO_ERROR) {
if (usage_support_type_ == kUsageEntrySupport)
usage_table_header_ = crypto_session_->GetUsageTableHeader();
@@ -779,7 +779,7 @@ CdmResponseType CdmSession::DeleteUsageEntry(uint32_t usage_entry_number) {
usage_support_type_ = kNonSecureUsageSupport;
}
if (usage_table_header_ == NULL) {
if (usage_table_header_ == nullptr) {
LOGE("Usage table header unavailable");
return INCORRECT_USAGE_SUPPORT_TYPE_1;
}
@@ -915,7 +915,7 @@ CdmResponseType CdmSession::RemoveKeys() {
M_TIME(sts = crypto_session_->Open(requested_security_level_),
crypto_metrics_, crypto_session_open_, sts, requested_security_level_);
policy_engine_.reset(
new PolicyEngine(session_id_, NULL, crypto_session_.get()));
new PolicyEngine(session_id_, nullptr, crypto_session_.get()));
return NO_ERROR;
}
@@ -1009,13 +1009,13 @@ CdmResponseType CdmSession::UpdateUsageTableInformation() {
CdmResponseType CdmSession::UpdateUsageEntryInformation() {
if (usage_support_type_ != kUsageEntrySupport ||
!has_provider_session_token() || usage_table_header_ == NULL) {
!has_provider_session_token() || usage_table_header_ == nullptr) {
LOGE(
"Unexpected state: usage support type = %d, PST present = %s, "
"usage table header available = %s",
static_cast<int>(usage_support_type_),
has_provider_session_token() ? "yes" : "no",
usage_table_header_ == NULL ? "no" : "yes");
usage_table_header_ == nullptr ? "no" : "yes");
return INCORRECT_USAGE_SUPPORT_TYPE_2;
}

View File

@@ -51,7 +51,7 @@ bool CdmSessionMap::FindSessionNoLock(const CdmSessionId& session_id,
return false;
}
*session = iter->second;
assert(session->get() != NULL);
assert(*session);
return true;
}

View File

@@ -164,9 +164,9 @@ OEMCryptoResult ContentKeySession::LoadKeysAsLicenseType(
LOGV("session_id = %u", oec_session_id_);
OEMCryptoResult sts;
OEMCrypto_KeyObject* key_array_ptr = NULL;
OEMCrypto_KeyObject* key_array_ptr = nullptr;
if (keys.size() > 0) key_array_ptr = &load_keys[0];
OEMCryptoCipherMode* cipher_mode_ptr = NULL;
OEMCryptoCipherMode* cipher_mode_ptr = nullptr;
if (keys.size() > 0) cipher_mode_ptr = &cipher_modes[0];
M_TIME(sts = ::OEMCrypto_LoadKeys_Back_Compat(
oec_session_id_, msg, message.length(),

View File

@@ -68,8 +68,8 @@ shared_mutex CryptoSession::static_field_mutex_;
shared_mutex CryptoSession::oem_crypto_mutex_;
bool CryptoSession::initialized_ = false;
int CryptoSession::session_count_ = 0;
UsageTableHeader* CryptoSession::usage_table_header_l1_ = NULL;
UsageTableHeader* CryptoSession::usage_table_header_l3_ = NULL;
UsageTableHeader* CryptoSession::usage_table_header_l1_ = nullptr;
UsageTableHeader* CryptoSession::usage_table_header_l3_ = nullptr;
std::atomic<uint64_t> CryptoSession::request_id_index_source_(0);
size_t GetOffset(std::string message, std::string field) {
@@ -184,7 +184,7 @@ CryptoSession::CryptoSession(metrics::CryptoMetrics* metrics)
requested_security_level_(kLevelDefault),
is_usage_support_type_valid_(false),
usage_support_type_(kUnknownUsageSupport),
usage_table_header_(NULL),
usage_table_header_(nullptr),
cipher_mode_(kCipherModeCtr),
api_version_(0) {
assert(metrics);
@@ -272,13 +272,13 @@ void CryptoSession::Terminate() {
LOGE("OEMCrypto_Terminate failed: status = %d", static_cast<int>(sts));
}
if (usage_table_header_l1_ != NULL) {
if (usage_table_header_l1_ != nullptr) {
delete usage_table_header_l1_;
usage_table_header_l1_ = NULL;
usage_table_header_l1_ = nullptr;
}
if (usage_table_header_l3_ != NULL) {
if (usage_table_header_l3_ != nullptr) {
delete usage_table_header_l3_;
usage_table_header_l3_ = NULL;
usage_table_header_l3_ = nullptr;
}
initialized_ = false;
@@ -472,7 +472,7 @@ CdmResponseType CryptoSession::GetExternalDeviceUniqueId(
size_t id_length = 0;
OEMCryptoResult sts;
WithOecReadLock("GetExternalDeviceUniqueId", [&] {
sts = OEMCrypto_GetDeviceID(NULL, &id_length, requested_security_level_);
sts = OEMCrypto_GetDeviceID(nullptr, &id_length, requested_security_level_);
});
metrics_->oemcrypto_get_device_id_.Increment(sts);
@@ -710,7 +710,7 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
UsageTableHeader** header = security_level == kSecurityLevelL1
? &usage_table_header_l1_
: &usage_table_header_l3_;
if (*header == NULL) {
if (*header == nullptr) {
*header = new UsageTableHeader();
// Ignore errors since we do not know when a session is opened,
// if it is intended to be used for offline/usage session related
@@ -721,8 +721,8 @@ CdmResponseType CryptoSession::Open(SecurityLevel requested_security_level) {
auto_lock.lock();
if (!is_usage_table_header_inited) {
delete *header;
*header = NULL;
usage_table_header_ = NULL;
*header = nullptr;
usage_table_header_ = nullptr;
return NO_ERROR;
}
}
@@ -1279,7 +1279,7 @@ CdmResponseType CryptoSession::GenerateUsageReport(
OEMCryptoResult status;
WithOecWriteLock("GenerateUsageReport Attempt 1", [&] {
status = OEMCrypto_ReportUsage(oec_session_id_, pst,
provider_session_token.length(), NULL,
provider_session_token.length(), nullptr,
&usage_length);
});
metrics_->oemcrypto_report_usage_.Increment(status);
@@ -1514,9 +1514,9 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey(
LOGV("Rewrapping device RSA key: id = %u", oec_session_id_);
const uint8_t* signed_msg = reinterpret_cast<const uint8_t*>(message.data());
const uint8_t* msg_rsa_key = NULL;
const uint8_t* msg_rsa_key_iv = NULL;
const uint32_t* msg_nonce = NULL;
const uint8_t* msg_rsa_key = nullptr;
const uint8_t* msg_rsa_key_iv = nullptr;
const uint32_t* msg_nonce = nullptr;
if (enc_rsa_key.size() >= MAC_KEY_SIZE && rsa_key_iv.size() >= KEY_IV_SIZE) {
msg_rsa_key = signed_msg + GetOffset(message, enc_rsa_key);
msg_rsa_key_iv = signed_msg + GetOffset(message, rsa_key_iv);
@@ -1524,7 +1524,7 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey(
GetOffset(message, nonce));
}
// Gets wrapped_rsa_key_length by passing NULL as uint8_t* wrapped_rsa_key
// Gets wrapped_rsa_key_length by passing nullptr as uint8_t* wrapped_rsa_key
// and 0 as wrapped_rsa_key_length.
size_t wrapped_rsa_key_length = 0;
OEMCryptoResult status;
@@ -1533,7 +1533,7 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey(
oec_session_id_, signed_msg, message.size(),
reinterpret_cast<const uint8_t*>(signature.data()),
signature.size(), msg_nonce, msg_rsa_key, enc_rsa_key.size(),
msg_rsa_key_iv, NULL, &wrapped_rsa_key_length),
msg_rsa_key_iv, nullptr, &wrapped_rsa_key_length),
metrics_, oemcrypto_rewrap_device_rsa_key_, status);
});
@@ -1567,10 +1567,10 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey30(
LOGV("Rewrapping Device RSA key 30: id = %u", oec_session_id_);
const uint8_t* signed_msg = reinterpret_cast<const uint8_t*>(message.data());
const uint8_t* msg_private_key = NULL;
const uint8_t* msg_iv = NULL;
const uint32_t* msg_nonce = NULL;
const uint8_t* msg_wrapping_key = NULL;
const uint8_t* msg_private_key = nullptr;
const uint8_t* msg_iv = nullptr;
const uint32_t* msg_nonce = nullptr;
const uint8_t* msg_wrapping_key = nullptr;
if (private_key.size() >= MAC_KEY_SIZE && iv.size() >= KEY_IV_SIZE) {
msg_private_key = signed_msg + GetOffset(message, private_key);
msg_iv = signed_msg + GetOffset(message, iv);
@@ -1579,7 +1579,7 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey30(
msg_wrapping_key = signed_msg + GetOffset(message, wrapping_key);
}
// Gets wrapped_rsa_key_length by passing NULL as uint8_t* wrapped_rsa_key
// Gets wrapped_rsa_key_length by passing nullptr as uint8_t* wrapped_rsa_key
// and 0 as wrapped_rsa_key_length.
size_t wrapped_private_key_length = 0;
OEMCryptoResult status;
@@ -1587,7 +1587,7 @@ CdmResponseType CryptoSession::RewrapDeviceRSAKey30(
M_TIME(status = OEMCrypto_RewrapDeviceRSAKey30(
oec_session_id_, msg_nonce, msg_wrapping_key,
wrapping_key.size(), msg_private_key, private_key.size(), msg_iv,
NULL, &wrapped_private_key_length),
nullptr, &wrapped_private_key_length),
metrics_, oemcrypto_rewrap_device_rsa_key_30_, status);
});
@@ -2374,8 +2374,9 @@ CdmResponseType CryptoSession::UpdateUsageEntry(
size_t usage_entry_len = 0;
OEMCryptoResult result;
WithOecWriteLock("UpdateUsageEntry Attempt 1", [&] {
result = OEMCrypto_UpdateUsageEntry(
oec_session_id_, NULL, &usage_table_header_len, NULL, &usage_entry_len);
result = OEMCrypto_UpdateUsageEntry(oec_session_id_, nullptr,
&usage_table_header_len, nullptr,
&usage_entry_len);
});
metrics_->oemcrypto_update_usage_entry_.Increment(result);
@@ -2417,7 +2418,7 @@ CdmResponseType CryptoSession::ShrinkUsageTableHeader(
OEMCryptoResult result;
WithOecWriteLock("ShrinkUsageTableHeader Attempt 1", [&] {
result = OEMCrypto_ShrinkUsageTableHeader(requested_security_level_,
new_entry_count, NULL,
new_entry_count, nullptr,
&usage_table_header_len);
metrics_->oemcrypto_shrink_usage_table_header_.Increment(result);
});
@@ -2726,7 +2727,7 @@ OEMCryptoResult CryptoSession::DecryptInChunks(
const uint8_t* const buffer_end =
params.encrypt_buffer + additional_offset + chunk_size;
const uint8_t* block_end = NULL;
const uint8_t* block_end = nullptr;
if (pattern_length_in_bytes == 0) {
// For cbc1, the last encrypted block is the last block of the
// subsample.
@@ -2814,7 +2815,7 @@ CryptoSession* CryptoSession::MakeCryptoSession(
metrics::CryptoMetrics* crypto_metrics) {
std::unique_lock<std::mutex> auto_lock(factory_mutex_);
// If the factory_ has not been set, then use a default factory.
if (factory_.get() == NULL) factory_.reset(new CryptoSessionFactory());
if (!factory_) factory_.reset(new CryptoSessionFactory());
return factory_->MakeCryptoSession(crypto_metrics);
}

View File

@@ -192,10 +192,10 @@ bool DeviceFiles::ExtractDeviceInfo(const std::string& device_certificate,
LOGE("Failed to parse DRM device certificate message");
return false;
}
if (serial_number != NULL) {
if (serial_number != nullptr) {
*serial_number = drm_device_certificate.serial_number();
}
if (system_id != NULL) {
if (system_id != nullptr) {
*system_id = drm_device_certificate.system_id();
}
return true;
@@ -283,7 +283,7 @@ bool DeviceFiles::RetrieveLicense(
CdmAppParameterMap* app_parameters, CdmUsageEntry* usage_entry,
uint32_t* usage_entry_number, ResponseType* result) {
// This check must be made first as the RETURN_FALSE_IF_NULL() macro
// will assign NULL_PARAMETER to |result|.
// will assign kParameterNull to |result|.
if (result == nullptr) {
LOGE("Output parameter |result| not provided");
return false;

View File

@@ -205,7 +205,7 @@ bool CdmLicense::Init(const std::string& client_token,
const std::string& device_id, bool use_privacy_mode,
const std::string& signed_service_certificate,
CryptoSession* session, PolicyEngine* policy_engine) {
if (clock_.get() == nullptr) {
if (!clock_) {
LOGE("Clock parameter not provided");
return false;
}
@@ -256,7 +256,7 @@ CdmResponseType CdmLicense::PrepareKeyRequest(
LOGE("CdmLicense not initialized");
return LICENSE_PARSER_NOT_INITIALIZED_4;
}
if (init_data.IsEmpty() && stored_init_data_.get()) {
if (init_data.IsEmpty() && stored_init_data_) {
InitializationData restored_init_data = *stored_init_data_;
stored_init_data_.reset();
return PrepareKeyRequest(restored_init_data, license_type, app_parameters,

File diff suppressed because it is too large Load Diff

View File

@@ -62,6 +62,7 @@ class boringssl_ptr {
T& operator*() const { return *ptr_; }
T* operator->() const { return ptr_; }
T* get() const { return ptr_; }
explicit operator bool() const { return ptr_ != nullptr; }
private:
T* ptr_;
@@ -328,7 +329,7 @@ bool ExtractExtensionValueFromCertificate(const std::string& cert,
// Load the certificate chain into a BoringSSL X509 Stack
const boringssl_ptr<STACK_OF(X509), DeleteX509Stack> x509_stack(
sk_X509_new_null());
if (x509_stack.get() == nullptr) {
if (!x509_stack) {
LOGE("Unable to allocate X509 stack");
return false;
}

View File

@@ -25,7 +25,7 @@ std::unique_ptr<CdmClientPropertySetMap> Properties::session_property_set_;
bool Properties::AddSessionPropertySet(const CdmSessionId& session_id,
CdmClientPropertySet* property_set) {
if (NULL == session_property_set_.get()) {
if (!session_property_set_) {
return false;
}
std::pair<CdmClientPropertySetMap::iterator, bool> result =
@@ -36,7 +36,7 @@ bool Properties::AddSessionPropertySet(const CdmSessionId& session_id,
}
bool Properties::RemoveSessionPropertySet(const CdmSessionId& session_id) {
if (NULL == session_property_set_.get()) {
if (!session_property_set_) {
return false;
}
return (1 == session_property_set_->erase(session_id));
@@ -44,21 +44,21 @@ bool Properties::RemoveSessionPropertySet(const CdmSessionId& session_id) {
CdmClientPropertySet* Properties::GetCdmClientPropertySet(
const CdmSessionId& session_id) {
if (NULL != session_property_set_.get()) {
if (session_property_set_) {
CdmClientPropertySetMap::iterator it =
session_property_set_->find(session_id);
if (it != session_property_set_->end()) {
return it->second;
}
}
return NULL;
return nullptr;
}
bool Properties::GetApplicationId(const CdmSessionId& session_id,
std::string* app_id) {
const CdmClientPropertySet* property_set =
GetCdmClientPropertySet(session_id);
if (NULL == property_set) {
if (property_set == nullptr) {
return false;
}
*app_id = property_set->app_id();
@@ -69,7 +69,7 @@ bool Properties::GetServiceCertificate(const CdmSessionId& session_id,
std::string* service_certificate) {
const CdmClientPropertySet* property_set =
GetCdmClientPropertySet(session_id);
if (property_set == NULL) {
if (property_set == nullptr) {
return false;
}
*service_certificate = property_set->service_certificate();
@@ -79,7 +79,7 @@ bool Properties::GetServiceCertificate(const CdmSessionId& session_id,
bool Properties::SetServiceCertificate(const CdmSessionId& session_id,
const std::string& service_certificate) {
CdmClientPropertySet* property_set = GetCdmClientPropertySet(session_id);
if (property_set == NULL) {
if (property_set == nullptr) {
return false;
}
property_set->set_service_certificate(service_certificate);
@@ -89,7 +89,7 @@ bool Properties::SetServiceCertificate(const CdmSessionId& session_id,
bool Properties::UsePrivacyMode(const CdmSessionId& session_id) {
const CdmClientPropertySet* property_set =
GetCdmClientPropertySet(session_id);
if (NULL == property_set) {
if (property_set == nullptr) {
return false;
}
return property_set->use_privacy_mode();
@@ -98,7 +98,7 @@ bool Properties::UsePrivacyMode(const CdmSessionId& session_id) {
uint32_t Properties::GetSessionSharingId(const CdmSessionId& session_id) {
const CdmClientPropertySet* property_set =
GetCdmClientPropertySet(session_id);
if (NULL == property_set) {
if (property_set == nullptr) {
return 0;
}
return property_set->session_sharing_id();

View File

@@ -203,7 +203,7 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
CdmResponseType ServiceCertificate::VerifySignedMessage(
const std::string& message, const std::string& signature) {
if (public_key_.get() == nullptr) {
if (!public_key_) {
LOGE("Service certificate not set");
return DEVICE_CERTIFICATE_ERROR_4;
}
@@ -216,7 +216,7 @@ CdmResponseType ServiceCertificate::VerifySignedMessage(
CdmResponseType ServiceCertificate::EncryptRsaOaep(const std::string& plaintext,
std::string* ciphertext) {
if (public_key_.get() == nullptr) {
if (!public_key_) {
LOGE("Service certificate not set");
return DEVICE_CERTIFICATE_ERROR_4;
}