diff --git a/libwvdrmengine/cdm/core/include/buffer_reader.h b/libwvdrmengine/cdm/core/include/buffer_reader.h index 38ccfcaf..e9bcfb60 100644 --- a/libwvdrmengine/cdm/core/include/buffer_reader.h +++ b/libwvdrmengine/cdm/core/include/buffer_reader.h @@ -27,7 +27,7 @@ namespace wvcdm { class BufferReader { public: BufferReader(const uint8_t* buf, size_t size) - : buf_(buf), size_(buf != NULL ? size : 0), pos_(0) {} + : buf_(buf), size_(buf != nullptr ? size : 0), pos_(0) {} bool HasBytes(size_t count) const { return pos_ + count <= size_; } bool IsEOF() const { return pos_ >= size_; } diff --git a/libwvdrmengine/cdm/core/include/cdm_session.h b/libwvdrmengine/cdm/core/include/cdm_session.h index 11d8eee6..5ed5fe2b 100644 --- a/libwvdrmengine/cdm/core/include/cdm_session.h +++ b/libwvdrmengine/cdm/core/include/cdm_session.h @@ -151,7 +151,7 @@ class CdmSession { virtual bool is_temporary() { return is_temporary_; } virtual bool license_received() { return license_received_; } virtual bool has_provider_session_token() { - return (license_parser_.get() != NULL && + return (license_parser_ && license_parser_->provider_session_token().size() > 0); } diff --git a/libwvdrmengine/cdm/core/include/license.h b/libwvdrmengine/cdm/core/include/license.h index 91b9708d..25e5c2a6 100644 --- a/libwvdrmengine/cdm/core/include/license.h +++ b/libwvdrmengine/cdm/core/include/license.h @@ -68,7 +68,7 @@ class CdmLicense { virtual CdmResponseType RestoreLicenseForRelease( const CdmKeyMessage& license_request, const CdmKeyResponse& license_response); - virtual bool HasInitData() { return stored_init_data_.get(); } + virtual bool HasInitData() { return static_cast(stored_init_data_); } virtual bool IsKeyLoaded(const KeyId& key_id); virtual std::string provider_session_token() { diff --git a/libwvdrmengine/cdm/core/include/wv_cdm_types.h b/libwvdrmengine/cdm/core/include/wv_cdm_types.h index 88c26046..4e563e3c 100644 --- a/libwvdrmengine/cdm/core/include/wv_cdm_types.h +++ b/libwvdrmengine/cdm/core/include/wv_cdm_types.h @@ -592,12 +592,12 @@ struct CdmDecryptionParameters { : is_encrypted(true), is_secure(true), cipher_mode(kCipherModeCtr), - key_id(NULL), - encrypt_buffer(NULL), + key_id(nullptr), + encrypt_buffer(nullptr), encrypt_length(0), - iv(NULL), + iv(nullptr), block_offset(0), - decrypt_buffer(NULL), + decrypt_buffer(nullptr), decrypt_buffer_length(0), decrypt_buffer_offset(0), subsample_flags(0), diff --git a/libwvdrmengine/cdm/core/src/buffer_reader.cpp b/libwvdrmengine/cdm/core/src/buffer_reader.cpp index 875e0f5d..df648eb3 100644 --- a/libwvdrmengine/cdm/core/src/buffer_reader.cpp +++ b/libwvdrmengine/cdm/core/src/buffer_reader.cpp @@ -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 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* 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; } diff --git a/libwvdrmengine/cdm/core/src/cdm_engine.cpp b/libwvdrmengine/cdm/core/src/cdm_engine.cpp index 51a9398b..098c9e9f 100644 --- a/libwvdrmengine/cdm/core/src/cdm_engine.cpp +++ b/libwvdrmengine/cdm/core/src/cdm_engine.cpp @@ -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 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(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(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; } diff --git a/libwvdrmengine/cdm/core/src/cdm_session.cpp b/libwvdrmengine/cdm/core/src/cdm_session.cpp index 1cb558f7..b9763d52 100644 --- a/libwvdrmengine/cdm/core/src/cdm_session.cpp +++ b/libwvdrmengine/cdm/core/src/cdm_session.cpp @@ -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(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; } diff --git a/libwvdrmengine/cdm/core/src/cdm_session_map.cpp b/libwvdrmengine/cdm/core/src/cdm_session_map.cpp index 3faf273f..f7b107bf 100644 --- a/libwvdrmengine/cdm/core/src/cdm_session_map.cpp +++ b/libwvdrmengine/cdm/core/src/cdm_session_map.cpp @@ -51,7 +51,7 @@ bool CdmSessionMap::FindSessionNoLock(const CdmSessionId& session_id, return false; } *session = iter->second; - assert(session->get() != NULL); + assert(*session); return true; } diff --git a/libwvdrmengine/cdm/core/src/content_key_session.cpp b/libwvdrmengine/cdm/core/src/content_key_session.cpp index 2051e3df..0f2940fe 100644 --- a/libwvdrmengine/cdm/core/src/content_key_session.cpp +++ b/libwvdrmengine/cdm/core/src/content_key_session.cpp @@ -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(), diff --git a/libwvdrmengine/cdm/core/src/crypto_session.cpp b/libwvdrmengine/cdm/core/src/crypto_session.cpp index 0ec821b5..9f21fb63 100644 --- a/libwvdrmengine/cdm/core/src/crypto_session.cpp +++ b/libwvdrmengine/cdm/core/src/crypto_session.cpp @@ -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 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(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(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(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(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 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); } diff --git a/libwvdrmengine/cdm/core/src/device_files.cpp b/libwvdrmengine/cdm/core/src/device_files.cpp index c3911035..f519c528 100644 --- a/libwvdrmengine/cdm/core/src/device_files.cpp +++ b/libwvdrmengine/cdm/core/src/device_files.cpp @@ -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; diff --git a/libwvdrmengine/cdm/core/src/license.cpp b/libwvdrmengine/cdm/core/src/license.cpp index c0b7cbd3..36d8c01a 100644 --- a/libwvdrmengine/cdm/core/src/license.cpp +++ b/libwvdrmengine/cdm/core/src/license.cpp @@ -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, diff --git a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp index 9dfce039..94e19c74 100644 --- a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp +++ b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp @@ -427,7 +427,7 @@ class WatchDog { file_system.Remove(filename); if (size == size_read && flag) { LOGE("Previous L3 Init failed."); - if (metrics == NULL) return; + if (metrics == nullptr) return; metrics ->OemCryptoDynamicAdapterMetrics::SetPreviousInitializationFailure( wvcdm::metrics::OEMCrypto_INITIALIZED_L3_INITIALIZATION_FAILED); @@ -492,7 +492,7 @@ class WatchDog { // By saving information to the file system, above, we can still track // metrics. abort(); - } else if (metrics != NULL) { + } else if (metrics != nullptr) { // Even if we succeeded in calling initialize, there might be failures // in the initialize process that we want to record. wvoec3::Level3InitializationState state = @@ -592,14 +592,14 @@ class Adapter { public: using map_iterator = std::map::iterator; - Adapter() : level1_valid_(false), level1_library_(NULL) {} + Adapter() : level1_valid_(false), level1_library_(nullptr) {} // The adapter is only destroyed on certain errors, or when the process // dies. It is NOT deleted after each OEMCrypto_Terminate. ~Adapter() { if (level1_library_) { dlclose(level1_library_); - level1_library_ = NULL; + level1_library_ = nullptr; } } @@ -646,9 +646,9 @@ class Adapter { wvcdm::metrics::OEMCrypto_INITIALIZED_USING_L3_NO_L1_LIBRARY_PATH); return result; } - if (level1_library_ == NULL) { + if (level1_library_ == nullptr) { level1_library_ = dlopen(library_name.c_str(), RTLD_NOW); - if (level1_library_ == NULL) { + if (level1_library_ == nullptr) { LOGW("Could not load %s. Falling back to L3. %s", library_name.c_str(), dlerror()); metrics.OemCryptoDynamicAdapterMetrics::SetInitializationMode( @@ -675,7 +675,7 @@ class Adapter { } bool LoadLevel1(wvcdm::metrics::OemCryptoDynamicAdapterMetrics* metrics) { - if (metrics == NULL) { + if (metrics == nullptr) { return false; } level1_valid_ = true; @@ -693,7 +693,7 @@ class Adapter { if (!sandbox_id_.empty()) { level1_.SetSandbox = (L1_SetSandbox_t)dlsym(level1_library_, QUOTE(OEMCrypto_SetSandbox)); - if (level1_.SetSandbox != NULL) { + if (level1_.SetSandbox != nullptr) { level1_.SetSandbox(&sandbox_id_[0], sandbox_id_.size()); } } @@ -1040,95 +1040,95 @@ namespace wvcdm { OEMCryptoResult OEMCrypto_OpenSession(OEMCrypto_SESSION* session, SecurityLevel level) { - if (!gAdapter.get()) return OEMCrypto_ERROR_OPEN_SESSION_FAILED; + if (!gAdapter) return OEMCrypto_ERROR_OPEN_SESSION_FAILED; return gAdapter->OpenSession(session, level); } OEMCryptoResult OEMCrypto_InstallKeyboxOrOEMCert(const uint8_t* keybox, size_t keyBoxLength, SecurityLevel level) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (fcn->InstallKeyboxOrOEMCert == NULL) + if (fcn->InstallKeyboxOrOEMCert == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->InstallKeyboxOrOEMCert(keybox, keyBoxLength); } OEMCrypto_ProvisioningMethod OEMCrypto_GetProvisioningMethod( SecurityLevel level) { - if (!gAdapter.get()) return OEMCrypto_ProvisioningError; + if (!gAdapter) return OEMCrypto_ProvisioningError; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ProvisioningError; if (fcn->version < 12) return OEMCrypto_Keybox; - if (fcn->GetProvisioningMethod == NULL) return OEMCrypto_Keybox; + if (fcn->GetProvisioningMethod == nullptr) return OEMCrypto_Keybox; return fcn->GetProvisioningMethod(); } OEMCryptoResult OEMCrypto_IsKeyboxOrOEMCertValid(SecurityLevel level) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (fcn->IsKeyboxOrOEMCertValid == NULL) + if (fcn->IsKeyboxOrOEMCertValid == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->IsKeyboxOrOEMCertValid(); } OEMCryptoResult OEMCrypto_GetDeviceID(uint8_t* deviceID, size_t* idLength, SecurityLevel level) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (fcn->GetDeviceID == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->GetDeviceID == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->GetDeviceID(deviceID, idLength); } OEMCryptoResult OEMCrypto_GetKeyData(uint8_t* keyData, size_t* keyDataLength, SecurityLevel level) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (fcn->GetKeyData == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->GetKeyData == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->GetKeyData(keyData, keyDataLength); } uint32_t OEMCrypto_APIVersion(SecurityLevel level) { - if (!gAdapter.get()) return 0; + if (!gAdapter) return 0; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return 0; - if (fcn->APIVersion == NULL) return 0; + if (fcn->APIVersion == nullptr) return 0; return fcn->APIVersion(); } uint8_t OEMCrypto_Security_Patch_Level(SecurityLevel level) { - if (!gAdapter.get()) return 0; + if (!gAdapter) return 0; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return 0; if (fcn->version < 11) return 0; - if (fcn->SecurityPatchLevel == NULL) return 0; + if (fcn->SecurityPatchLevel == nullptr) return 0; return fcn->SecurityPatchLevel(); } const char* OEMCrypto_SecurityLevel(SecurityLevel level) { - if (!gAdapter.get()) return ""; + if (!gAdapter) return ""; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return ""; - if (fcn->SecurityLevel == NULL) return ""; + if (fcn->SecurityLevel == nullptr) return ""; return fcn->SecurityLevel(); } OEMCryptoResult OEMCrypto_GetHDCPCapability( SecurityLevel level, OEMCrypto_HDCP_Capability* current, OEMCrypto_HDCP_Capability* maximum) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_NOT_IMPLEMENTED; if (fcn->version == 8) return OEMCrypto_ERROR_NOT_IMPLEMENTED; if (fcn->version == 9) { - if (current == NULL) return OEMCrypto_ERROR_UNKNOWN_FAILURE; - if (maximum == NULL) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (current == nullptr) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (maximum == nullptr) return OEMCrypto_ERROR_UNKNOWN_FAILURE; uint8_t current_byte, maximum_byte; - if (fcn->GetHDCPCapability_V9 == NULL) + if (fcn->GetHDCPCapability_V9 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; OEMCryptoResult sts = fcn->GetHDCPCapability_V9(¤t_byte, &maximum_byte); @@ -1136,68 +1136,70 @@ OEMCryptoResult OEMCrypto_GetHDCPCapability( *maximum = static_cast(maximum_byte); return sts; } else { - if (fcn->GetHDCPCapability == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->GetHDCPCapability == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->GetHDCPCapability(current, maximum); } } uint32_t OEMCrypto_GetAnalogOutputFlags(SecurityLevel level) { - if (!gAdapter.get()) return OEMCrypto_Unknown_Analog_Output; + if (!gAdapter) return OEMCrypto_Unknown_Analog_Output; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_Unknown_Analog_Output; if (fcn->version < 14) return OEMCrypto_Unknown_Analog_Output; - if (fcn->GetAnalogOutputFlags == NULL) return OEMCrypto_Unknown_Analog_Output; + if (fcn->GetAnalogOutputFlags == nullptr) + return OEMCrypto_Unknown_Analog_Output; return fcn->GetAnalogOutputFlags(); } const char* OEMCrypto_BuildInformation(SecurityLevel level) { - if (!gAdapter.get()) return ""; + if (!gAdapter) return ""; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return ""; if (fcn->version < 14) return "pre v15"; - if (fcn->BuildInformation == NULL) return "unknown"; + if (fcn->BuildInformation == nullptr) return "unknown"; return fcn->BuildInformation(); } uint32_t OEMCrypto_ResourceRatingTier(SecurityLevel level) { - if (!gAdapter.get()) return 0; + if (!gAdapter) return 0; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return 0; if (fcn->version <= 14) return 0; - if (fcn->ResourceRatingTier == NULL) return 0; + if (fcn->ResourceRatingTier == nullptr) return 0; return fcn->ResourceRatingTier(); } uint32_t OEMCrypto_SupportsDecryptHash(SecurityLevel level) { - if (!gAdapter.get()) return OEMCrypto_Hash_Not_Supported; + if (!gAdapter) return OEMCrypto_Hash_Not_Supported; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_Hash_Not_Supported; if (fcn->version < 15) return OEMCrypto_Hash_Not_Supported; - if (fcn->BuildInformation == NULL) return OEMCrypto_Hash_Not_Supported; + if (fcn->BuildInformation == nullptr) return OEMCrypto_Hash_Not_Supported; return fcn->SupportsDecryptHash(); } bool OEMCrypto_SupportsUsageTable(SecurityLevel level) { - if (!gAdapter.get()) return false; + if (!gAdapter) return false; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return false; if (fcn->version == 8) return false; - if (fcn->SupportsUsageTable == NULL) return false; + if (fcn->SupportsUsageTable == nullptr) return false; return fcn->SupportsUsageTable(); } bool OEMCrypto_IsAntiRollbackHwPresent(SecurityLevel level) { - if (!gAdapter.get()) return false; + if (!gAdapter) return false; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return false; if (fcn->version < 10) return false; - if (fcn->IsAntiRollbackHwPresent == NULL) return false; + if (fcn->IsAntiRollbackHwPresent == nullptr) return false; return fcn->IsAntiRollbackHwPresent(); } OEMCryptoResult OEMCrypto_GetNumberOfOpenSessions(SecurityLevel level, size_t* count) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (fcn->version < 10) return OEMCrypto_ERROR_NOT_IMPLEMENTED; @@ -1206,33 +1208,34 @@ OEMCryptoResult OEMCrypto_GetNumberOfOpenSessions(SecurityLevel level, OEMCryptoResult OEMCrypto_GetMaxNumberOfSessions(SecurityLevel level, size_t* maximum) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (fcn->version < 10) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->GetMaxNumberOfSessions == NULL) + if (fcn->GetMaxNumberOfSessions == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->GetMaxNumberOfSessions(maximum); } uint32_t OEMCrypto_SupportedCertificates(SecurityLevel level) { - if (!gAdapter.get()) return 0; + if (!gAdapter) return 0; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return 0; // Default is to support 2048 bit RSA keys. if (fcn->version < 13) return OEMCrypto_Supports_RSA_2048bit; - if (fcn->SupportedCertificates == NULL) return OEMCrypto_Supports_RSA_2048bit; + if (fcn->SupportedCertificates == nullptr) + return OEMCrypto_Supports_RSA_2048bit; return fcn->SupportedCertificates(); } OEMCryptoResult OEMCrypto_CreateUsageTableHeader(SecurityLevel level, uint8_t* header_buffer, size_t* header_buffer_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->CreateUsageTableHeader == NULL) + if (fcn->CreateUsageTableHeader == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->CreateUsageTableHeader(header_buffer, header_buffer_length); } @@ -1240,11 +1243,12 @@ OEMCryptoResult OEMCrypto_CreateUsageTableHeader(SecurityLevel level, OEMCryptoResult OEMCrypto_LoadUsageTableHeader(SecurityLevel level, const uint8_t* buffer, size_t buffer_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->LoadUsageTableHeader == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->LoadUsageTableHeader == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->LoadUsageTableHeader(buffer, buffer_length); } @@ -1252,11 +1256,11 @@ OEMCryptoResult OEMCrypto_ShrinkUsageTableHeader(SecurityLevel level, uint32_t new_table_size, uint8_t* header_buffer, size_t* header_buffer_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->ShrinkUsageTableHeader == NULL) + if (fcn->ShrinkUsageTableHeader == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->ShrinkUsageTableHeader(new_table_size, header_buffer, header_buffer_length); @@ -1267,11 +1271,12 @@ OEMCryptoResult OEMCrypto_CreateOldUsageEntry( uint64_t time_since_first_decrypt, uint64_t time_since_last_decrypt, OEMCrypto_Usage_Entry_Status status, uint8_t* server_mac_key, uint8_t* client_mac_key, const uint8_t* pst, size_t pst_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(level); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->CreateOldUsageEntry == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->CreateOldUsageEntry == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->CreateOldUsageEntry( time_since_license_received, time_since_first_decrypt, time_since_last_decrypt, status, server_mac_key, client_mac_key, pst, @@ -1281,7 +1286,7 @@ OEMCryptoResult OEMCrypto_CreateOldUsageEntry( extern "C" OEMCryptoResult OEMCrypto_SetSandbox(const uint8_t* sandbox_id, size_t sandbox_id_length) { - if (!gAdapter.get()) { + if (!gAdapter) { gAdapter.reset(new Adapter()); } gAdapter->SetSandbox(sandbox_id, sandbox_id_length); @@ -1289,7 +1294,7 @@ extern "C" OEMCryptoResult OEMCrypto_SetSandbox(const uint8_t* sandbox_id, } extern "C" OEMCryptoResult OEMCrypto_Initialize(void) { - if (!gAdapter.get()) { + if (!gAdapter) { gAdapter.reset(new Adapter()); } return gAdapter->Initialize(); @@ -1297,7 +1302,7 @@ extern "C" OEMCryptoResult OEMCrypto_Initialize(void) { extern "C" OEMCryptoResult OEMCrypto_Terminate(void) { OEMCryptoResult result = OEMCrypto_SUCCESS; - if (gAdapter.get()) { + if (gAdapter) { result = gAdapter->Terminate(); } return result; @@ -1308,7 +1313,7 @@ extern "C" OEMCryptoResult OEMCrypto_OpenSession(OEMCrypto_SESSION* session) { } extern "C" OEMCryptoResult OEMCrypto_CloseSession(OEMCrypto_SESSION session) { - if (!gAdapter.get()) return OEMCrypto_ERROR_CLOSE_SESSION_FAILED; + if (!gAdapter) return OEMCrypto_ERROR_CLOSE_SESSION_FAILED; return gAdapter->CloseSession(session); } @@ -1316,10 +1321,10 @@ extern "C" OEMCryptoResult OEMCrypto_GenerateDerivedKeys( OEMCrypto_SESSION session, const uint8_t* mac_key_context, uint32_t mac_key_context_length, const uint8_t* enc_key_context, uint32_t enc_key_context_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->GenerateDerivedKeys == NULL) + if (pair.fcn->GenerateDerivedKeys == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->GenerateDerivedKeys(pair.session, mac_key_context, mac_key_context_length, enc_key_context, @@ -1328,20 +1333,21 @@ extern "C" OEMCryptoResult OEMCrypto_GenerateDerivedKeys( extern "C" OEMCryptoResult OEMCrypto_GenerateNonce(OEMCrypto_SESSION session, uint32_t* nonce) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->GenerateNonce == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->GenerateNonce == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->GenerateNonce(pair.session, nonce); } extern "C" OEMCryptoResult OEMCrypto_GenerateSignature( OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, uint8_t* signature, size_t* signature_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->GenerateSignature == NULL) + if (pair.fcn->GenerateSignature == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->GenerateSignature(pair.session, message, message_length, signature, signature_length); @@ -1362,7 +1368,7 @@ extern "C" uint32_t OEMCrypto_ResourceRatingTier() { // Used for backwards compatibility. If the length is 0, this denotes a NULL // pointer for OEMCrypto v15. const uint8_t* PointerOrNull(const uint8_t* pointer, size_t length) { - return length ? pointer : NULL; + return length ? pointer : nullptr; } extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( @@ -1372,7 +1378,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( size_t num_keys, const OEMCrypto_KeyObject* key_array, OEMCrypto_Substring pst, OEMCrypto_Substring srm_restriction_data, OEMCrypto_LicenseType license_type, OEMCryptoCipherMode* cipher_modes) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 11) { @@ -1400,10 +1406,11 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( return OEMCrypto_ERROR_NOT_IMPLEMENTED; } } - OEMCrypto_KeyObject_V10* key_array_v10_ptr = NULL; + OEMCrypto_KeyObject_V10* key_array_v10_ptr = nullptr; if (num_keys > 0) key_array_v10_ptr = &key_array_v10[0]; if (pair.fcn->version == 8) { - if (pair.fcn->LoadKeys_V8 == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->LoadKeys_V8 == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->LoadKeys_V8( pair.session, message, message_length, signature, signature_length, PointerOrNull(message + enc_mac_keys_iv.offset, @@ -1411,7 +1418,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( PointerOrNull(message + enc_mac_keys.offset, enc_mac_keys.length), num_keys, key_array_v10_ptr); } else { - if (pair.fcn->LoadKeys_V9_or_V10 == NULL) + if (pair.fcn->LoadKeys_V9_or_V10 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; OEMCryptoResult result = pair.fcn->LoadKeys_V9_or_V10( pair.session, message, message_length, signature, signature_length, @@ -1447,10 +1454,10 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( key_array[i].key_control.length); key_array_v13[i].cipher_mode = cipher_modes[i]; } - OEMCrypto_KeyObject_V13* key_array_v13_ptr = NULL; + OEMCrypto_KeyObject_V13* key_array_v13_ptr = nullptr; if (num_keys > 0) key_array_v13_ptr = &key_array_v13[0]; if (pair.fcn->version < 13) { - if (pair.fcn->LoadKeys_V11_or_V12 == NULL) + if (pair.fcn->LoadKeys_V11_or_V12 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; OEMCryptoResult result = pair.fcn->LoadKeys_V11_or_V12( pair.session, message, message_length, signature, signature_length, @@ -1464,7 +1471,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( result = OEMCrypto_ERROR_USAGE_TABLE_UNRECOVERABLE; return result; } else { - if (pair.fcn->LoadKeys_V13 == NULL) + if (pair.fcn->LoadKeys_V13 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->LoadKeys_V13( pair.session, message, message_length, signature, signature_length, @@ -1477,7 +1484,8 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( srm_restriction_data.length)); } } else if (pair.fcn->version < 15) { - if (pair.fcn->LoadKeys_V14 == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->LoadKeys_V14 == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; std::vector key_array_v14(num_keys); for (size_t i = 0; i < num_keys; i++) { key_array_v14[i].key_id = PointerOrNull( @@ -1496,7 +1504,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( PointerOrNull(message + key_array[i].key_control.offset, key_array[i].key_control.length); } - OEMCrypto_KeyObject_V14* key_array_v14_ptr = NULL; + OEMCrypto_KeyObject_V14* key_array_v14_ptr = nullptr; if (num_keys > 0) key_array_v14_ptr = &key_array_v14[0]; return pair.fcn->LoadKeys_V14( pair.session, message, message_length, signature, signature_length, @@ -1508,7 +1516,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys_Back_Compat( srm_restriction_data.length), license_type); } else { - if (pair.fcn->LoadKeys == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->LoadKeys == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->LoadKeys(pair.session, message, message_length, signature, signature_length, enc_mac_keys_iv, enc_mac_keys, num_keys, key_array, pst, srm_restriction_data, @@ -1527,7 +1535,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( size_t num_keys, const OEMCrypto_KeyObject* key_array, OEMCrypto_Substring pst, OEMCrypto_Substring srm_restriction_data, OEMCrypto_LicenseType license_type) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 11) { @@ -1551,10 +1559,11 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( PointerOrNull(message + key_array[i].key_control.offset, key_array[i].key_control.length); } - OEMCrypto_KeyObject_V10* key_array_v10_ptr = NULL; + OEMCrypto_KeyObject_V10* key_array_v10_ptr = nullptr; if (num_keys > 0) key_array_v10_ptr = &key_array_v10[0]; if (pair.fcn->version == 8) { - if (pair.fcn->LoadKeys_V8 == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->LoadKeys_V8 == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->LoadKeys_V8( pair.session, message, message_length, signature, signature_length, PointerOrNull(message + enc_mac_keys_iv.offset, @@ -1562,7 +1571,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( PointerOrNull(message + enc_mac_keys.offset, enc_mac_keys.length), num_keys, key_array_v10_ptr); } else { - if (pair.fcn->LoadKeys_V9_or_V10 == NULL) + if (pair.fcn->LoadKeys_V9_or_V10 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; OEMCryptoResult result = pair.fcn->LoadKeys_V9_or_V10( pair.session, message, message_length, signature, signature_length, @@ -1598,10 +1607,10 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( key_array[i].key_control.length); key_array_v13[i].cipher_mode = OEMCrypto_CipherMode_CTR; } - OEMCrypto_KeyObject_V13* key_array_v13_ptr = NULL; + OEMCrypto_KeyObject_V13* key_array_v13_ptr = nullptr; if (num_keys > 0) key_array_v13_ptr = &key_array_v13[0]; if (pair.fcn->version < 13) { - if (pair.fcn->LoadKeys_V11_or_V12 == NULL) + if (pair.fcn->LoadKeys_V11_or_V12 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; OEMCryptoResult result = pair.fcn->LoadKeys_V11_or_V12( pair.session, message, message_length, signature, signature_length, @@ -1615,7 +1624,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( result = OEMCrypto_ERROR_USAGE_TABLE_UNRECOVERABLE; return result; } else { - if (pair.fcn->LoadKeys_V13 == NULL) + if (pair.fcn->LoadKeys_V13 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->LoadKeys_V13( pair.session, message, message_length, signature, signature_length, @@ -1628,7 +1637,8 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( srm_restriction_data.length)); } } else if (pair.fcn->version < 15) { - if (pair.fcn->LoadKeys_V14 == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->LoadKeys_V14 == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; std::vector key_array_v14(num_keys); for (size_t i = 0; i < num_keys; i++) { key_array_v14[i].key_id = PointerOrNull( @@ -1647,7 +1657,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( PointerOrNull(message + key_array[i].key_control.offset, key_array[i].key_control.length); } - OEMCrypto_KeyObject_V14* key_array_v14_ptr = NULL; + OEMCrypto_KeyObject_V14* key_array_v14_ptr = nullptr; if (num_keys > 0) key_array_v14_ptr = &key_array_v14[0]; return pair.fcn->LoadKeys_V14( pair.session, message, message_length, signature, signature_length, @@ -1659,7 +1669,7 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( srm_restriction_data.length), license_type); } else { - if (pair.fcn->LoadKeys == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->LoadKeys == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->LoadKeys(pair.session, message, message_length, signature, signature_length, enc_mac_keys_iv, enc_mac_keys, num_keys, key_array, pst, srm_restriction_data, @@ -1670,13 +1680,13 @@ extern "C" OEMCryptoResult OEMCrypto_LoadKeys( extern "C" OEMCryptoResult OEMCrypto_LoadEntitledContentKeys( OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, size_t num_keys, const OEMCrypto_EntitledContentKeyObject* key_array) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 14) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } else if (pair.fcn->version < 15) { - if (pair.fcn->LoadEntitledContentKeys_V14 == NULL) + if (pair.fcn->LoadEntitledContentKeys_V14 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; std::vector ecko_array_v14( num_keys); @@ -1700,12 +1710,12 @@ extern "C" OEMCryptoResult OEMCrypto_LoadEntitledContentKeys( ecko_array_v14[i].content_key_data_length = key_array[i].content_key_data.length; } - OEMCrypto_EntitledContentKeyObject_V14* ecko_array_v14_ptr = NULL; + OEMCrypto_EntitledContentKeyObject_V14* ecko_array_v14_ptr = nullptr; if (num_keys > 0) ecko_array_v14_ptr = &ecko_array_v14[0]; return pair.fcn->LoadEntitledContentKeys_V14(pair.session, num_keys, ecko_array_v14_ptr); } else { - if (pair.fcn->LoadEntitledContentKeys == NULL) + if (pair.fcn->LoadEntitledContentKeys == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->LoadEntitledContentKeys( pair.session, message, message_length, num_keys, key_array); @@ -1716,11 +1726,11 @@ extern "C" OEMCryptoResult OEMCrypto_RefreshKeys( OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, const uint8_t* signature, size_t signature_length, size_t num_keys, const OEMCrypto_KeyRefreshObject* key_array) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 15) { - if (pair.fcn->RefreshKeys_V14 == NULL) + if (pair.fcn->RefreshKeys_V14 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; std::vector kro_array_v14(num_keys); for (size_t i = 0; i < num_keys; i++) { @@ -1734,13 +1744,13 @@ extern "C" OEMCryptoResult OEMCrypto_RefreshKeys( PointerOrNull(message + key_array[i].key_control.offset, key_array[i].key_control.length); } - OEMCrypto_KeyRefreshObject_V14* kro_array_v14_ptr = NULL; + OEMCrypto_KeyRefreshObject_V14* kro_array_v14_ptr = nullptr; if (num_keys > 0) kro_array_v14_ptr = &kro_array_v14[0]; return pair.fcn->RefreshKeys_V14(pair.session, message, message_length, signature, signature_length, num_keys, kro_array_v14_ptr); } - if (pair.fcn->RefreshKeys == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->RefreshKeys == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->RefreshKeys(pair.session, message, message_length, signature, signature_length, num_keys, key_array); } @@ -1748,11 +1758,12 @@ extern "C" OEMCryptoResult OEMCrypto_RefreshKeys( extern "C" OEMCryptoResult OEMCrypto_QueryKeyControl( OEMCrypto_SESSION session, const uint8_t* key_id, size_t key_id_length, uint8_t* key_control_block, size_t* key_control_block_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 10) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (pair.fcn->QueryKeyControl == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->QueryKeyControl == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->QueryKeyControl(pair.session, key_id, key_id_length, key_control_block, key_control_block_length); } @@ -1760,14 +1771,15 @@ extern "C" OEMCryptoResult OEMCrypto_QueryKeyControl( extern "C" OEMCryptoResult OEMCrypto_SelectKey( const OEMCrypto_SESSION session, const uint8_t* key_id, size_t key_id_length, OEMCryptoCipherMode cipher_mode) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 14) { - if (pair.fcn->SelectKey_V13 == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->SelectKey_V13 == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->SelectKey_V13(pair.session, key_id, key_id_length); } else { - if (pair.fcn->SelectKey == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->SelectKey == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->SelectKey(pair.session, key_id, key_id_length, cipher_mode); } @@ -1778,17 +1790,18 @@ extern "C" OEMCryptoResult OEMCrypto_DecryptCENC( bool is_encrypted, const uint8_t* iv, size_t offset, OEMCrypto_DestBufferDesc* out_buffer, const OEMCrypto_CENCEncryptPatternDesc* pattern, uint8_t subsample_flags) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 11) { - if (pair.fcn->DecryptCTR_V10 == NULL) + if (pair.fcn->DecryptCTR_V10 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->DecryptCTR_V10(pair.session, data_addr, data_length, is_encrypted, iv, offset, out_buffer, subsample_flags); } else { - if (pair.fcn->DecryptCENC == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->DecryptCENC == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->DecryptCENC(pair.session, data_addr, data_length, is_encrypted, iv, offset, out_buffer, pattern, subsample_flags); @@ -1798,16 +1811,16 @@ extern "C" OEMCryptoResult OEMCrypto_DecryptCENC( extern "C" OEMCryptoResult OEMCrypto_CopyBuffer( OEMCrypto_SESSION session, const uint8_t* data_addr, size_t data_length, OEMCrypto_DestBufferDesc* out_buffer, uint8_t subsample_flags) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 15) { - if (pair.fcn->CopyBuffer_V14 == NULL) + if (pair.fcn->CopyBuffer_V14 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->CopyBuffer_V14(data_addr, data_length, out_buffer, subsample_flags); } - if (pair.fcn->CopyBuffer == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->CopyBuffer == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->CopyBuffer(session, data_addr, data_length, out_buffer, subsample_flags); } @@ -1818,10 +1831,10 @@ extern "C" OEMCryptoResult OEMCrypto_WrapKeybox(const uint8_t* keybox, size_t* wrappedKeyBoxLength, const uint8_t* transportKey, size_t transportKeyLength) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(kLevelDefault); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (fcn->WrapKeybox == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->WrapKeybox == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->WrapKeybox(keybox, keyBoxLength, wrappedKeybox, wrappedKeyBoxLength, transportKey, transportKeyLength); } @@ -1833,15 +1846,15 @@ extern "C" OEMCryptoResult OEMCrypto_InstallKeyboxOrOEMCert( extern "C" OEMCryptoResult OEMCrypto_LoadTestKeybox(const uint8_t* buffer, size_t length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(kLevelDefault); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (fcn->version < 10) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->LoadTestKeybox_V13 != NULL) { + if (fcn->LoadTestKeybox_V13 != nullptr) { // Old versions might use wrong keybox, but this is the best we can do. return fcn->LoadTestKeybox_V13(); } - if (fcn->LoadTestKeybox == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->LoadTestKeybox == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->LoadTestKeybox(buffer, length); } @@ -1856,11 +1869,11 @@ extern "C" OEMCrypto_ProvisioningMethod OEMCrypto_GetProvisioningMethod() { extern "C" OEMCryptoResult OEMCrypto_GetOEMPublicCertificate( OEMCrypto_SESSION session, uint8_t* public_cert, size_t* public_cert_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 12) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (pair.fcn->GetOEMPublicCertificate == NULL) + if (pair.fcn->GetOEMPublicCertificate == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->GetOEMPublicCertificate(pair.session, public_cert, public_cert_length); @@ -1878,10 +1891,10 @@ extern "C" OEMCryptoResult OEMCrypto_GetKeyData(uint8_t* keyData, extern "C" OEMCryptoResult OEMCrypto_GetRandom(uint8_t* randomData, size_t dataLength) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(kLevelDefault); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (fcn->GetRandom == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->GetRandom == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->GetRandom(randomData, dataLength); } @@ -1891,11 +1904,11 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey30( const uint8_t* enc_rsa_key, size_t enc_rsa_key_length, const uint8_t* enc_rsa_key_iv, uint8_t* wrapped_rsa_key, size_t* wrapped_rsa_key_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 12) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (pair.fcn->RewrapDeviceRSAKey30 == NULL) + if (pair.fcn->RewrapDeviceRSAKey30 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->RewrapDeviceRSAKey30( pair.session, nonce, encrypted_message_key, encrypted_message_key_length, @@ -1909,10 +1922,10 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey( const uint8_t* enc_rsa_key, size_t enc_rsa_key_length, const uint8_t* enc_rsa_key_iv, uint8_t* wrapped_rsa_key, size_t* wrapped_rsa_key_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->RewrapDeviceRSAKey == NULL) + if (pair.fcn->RewrapDeviceRSAKey == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->RewrapDeviceRSAKey( pair.session, message, message_length, signature, signature_length, nonce, @@ -1923,21 +1936,21 @@ extern "C" OEMCryptoResult OEMCrypto_RewrapDeviceRSAKey( extern "C" OEMCryptoResult OEMCrypto_LoadDeviceRSAKey( OEMCrypto_SESSION session, const uint8_t* wrapped_rsa_key, size_t wrapped_rsa_key_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->LoadDeviceRSAKey == NULL) + if (pair.fcn->LoadDeviceRSAKey == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->LoadDeviceRSAKey(pair.session, wrapped_rsa_key, wrapped_rsa_key_length); } extern "C" OEMCryptoResult OEMCrypto_LoadTestRSAKey() { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn = gAdapter->GetFunctionPointers(kLevelDefault); if (!fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (fcn->version < 10) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->LoadTestRSAKey == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->LoadTestRSAKey == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->LoadTestRSAKey(); } @@ -1945,16 +1958,16 @@ extern "C" OEMCryptoResult OEMCrypto_GenerateRSASignature( OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, uint8_t* signature, size_t* signature_length, RSA_Padding_Scheme padding_scheme) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version == 8) { - if (pair.fcn->GenerateRSASignature_V8 == NULL) + if (pair.fcn->GenerateRSASignature_V8 == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->GenerateRSASignature_V8( pair.session, message, message_length, signature, signature_length); } else { - if (pair.fcn->GenerateRSASignature == NULL) + if (pair.fcn->GenerateRSASignature == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->GenerateRSASignature(pair.session, message, message_length, signature, signature_length, @@ -1967,10 +1980,10 @@ extern "C" OEMCryptoResult OEMCrypto_DeriveKeysFromSessionKey( size_t enc_session_key_length, const uint8_t* mac_key_context, size_t mac_key_context_length, const uint8_t* enc_key_context, size_t enc_key_context_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->DeriveKeysFromSessionKey == NULL) + if (pair.fcn->DeriveKeysFromSessionKey == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->DeriveKeysFromSessionKey( pair.session, enc_session_key, enc_session_key_length, mac_key_context, @@ -2017,10 +2030,11 @@ extern "C" uint32_t OEMCrypto_SupportedCertificates() { extern "C" OEMCryptoResult OEMCrypto_Generic_Encrypt( OEMCrypto_SESSION session, const uint8_t* in_buffer, size_t buffer_length, const uint8_t* iv, OEMCrypto_Algorithm algorithm, uint8_t* out_buffer) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->Generic_Encrypt == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->Generic_Encrypt == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; OEMCryptoResult status = OEMCrypto_SUCCESS; std::vector current_iv(iv, iv + wvcdm::KEY_IV_SIZE); while (buffer_length > 0 && status == OEMCrypto_SUCCESS) { @@ -2041,10 +2055,11 @@ extern "C" OEMCryptoResult OEMCrypto_Generic_Encrypt( extern "C" OEMCryptoResult OEMCrypto_Generic_Decrypt( OEMCrypto_SESSION session, const uint8_t* in_buffer, size_t buffer_length, const uint8_t* iv, OEMCrypto_Algorithm algorithm, uint8_t* out_buffer) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->Generic_Decrypt == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->Generic_Decrypt == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; OEMCryptoResult status = OEMCrypto_SUCCESS; std::vector current_iv(iv, iv + wvcdm::KEY_IV_SIZE); while (buffer_length > 0 && status == OEMCrypto_SUCCESS) { @@ -2068,7 +2083,7 @@ extern "C" OEMCryptoResult OEMCrypto_Generic_Sign(OEMCrypto_SESSION session, OEMCrypto_Algorithm algorithm, uint8_t* signature, size_t* signature_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; return pair.fcn->Generic_Sign(pair.session, in_buffer, buffer_length, @@ -2079,19 +2094,20 @@ extern "C" OEMCryptoResult OEMCrypto_Generic_Verify( OEMCrypto_SESSION session, const uint8_t* in_buffer, size_t buffer_length, OEMCrypto_Algorithm algorithm, const uint8_t* signature, size_t signature_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->Generic_Verify == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->Generic_Verify == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->Generic_Verify(pair.session, in_buffer, buffer_length, algorithm, signature, signature_length); } extern "C" OEMCryptoResult OEMCrypto_UpdateUsageTable() { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn1 = gAdapter->GetFunctionPointers(kLevelDefault); OEMCryptoResult sts = OEMCrypto_ERROR_NOT_IMPLEMENTED; - if ((fcn1 != NULL) && (fcn1->UpdateUsageTable != NULL) && + if ((fcn1 != nullptr) && (fcn1->UpdateUsageTable != nullptr) && (fcn1->version > 8) && (fcn1->version < 13)) { sts = fcn1->UpdateUsageTable(); } @@ -2100,7 +2116,7 @@ extern "C" OEMCryptoResult OEMCrypto_UpdateUsageTable() { extern "C" OEMCryptoResult OEMCrypto_DeactivateUsageEntry( OEMCrypto_SESSION session, const uint8_t* pst, size_t pst_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) { const FunctionPointers* fcn1 = gAdapter->GetFunctionPointers(kLevelDefault); @@ -2157,11 +2173,12 @@ extern "C" OEMCryptoResult OEMCrypto_ReportUsage(OEMCrypto_SESSION session, size_t pst_length, uint8_t* buffer, size_t* buffer_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version > 8) { - if (pair.fcn->ReportUsage == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->ReportUsage == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->ReportUsage(pair.session, pst, pst_length, buffer, buffer_length); } else { @@ -2173,7 +2190,7 @@ extern "C" OEMCryptoResult OEMCrypto_DeleteUsageEntry( OEMCrypto_SESSION session, const uint8_t* pst, size_t pst_length, const uint8_t* message, size_t message_length, const uint8_t* signature, size_t signature_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version > 8 && pair.fcn->version < 13) { @@ -2187,16 +2204,16 @@ extern "C" OEMCryptoResult OEMCrypto_DeleteUsageEntry( extern "C" OEMCryptoResult OEMCrypto_ForceDeleteUsageEntry(const uint8_t* pst, size_t pst_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn1 = gAdapter->GetFunctionPointers(kLevelDefault); const FunctionPointers* fcn3 = gAdapter->GetFunctionPointers(kLevel3); OEMCryptoResult sts = OEMCrypto_ERROR_NOT_IMPLEMENTED; if (fcn3 && (fcn3->version > 9) && (fcn3->version < 13) && - fcn3->ForceDeleteUsageEntry != NULL) { + fcn3->ForceDeleteUsageEntry != nullptr) { sts = fcn3->ForceDeleteUsageEntry(pst, pst_length); } if (fcn1 && fcn1 != fcn3 && (fcn1->version > 9) && (fcn1->version < 13) && - (fcn1->ForceDeleteUsageEntry != NULL)) { + (fcn1->ForceDeleteUsageEntry != nullptr)) { OEMCryptoResult sts1 = fcn1->ForceDeleteUsageEntry(pst, pst_length); if ((sts != OEMCrypto_SUCCESS) && (sts1 == OEMCrypto_SUCCESS)) { sts = sts1; @@ -2206,58 +2223,59 @@ extern "C" OEMCryptoResult OEMCrypto_ForceDeleteUsageEntry(const uint8_t* pst, } extern "C" OEMCryptoResult OEMCrypto_DeleteOldUsageTable() { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; const FunctionPointers* fcn1 = gAdapter->GetFunctionPointers(kLevelDefault); const FunctionPointers* fcn3 = gAdapter->GetFunctionPointers(kLevel3); OEMCryptoResult sts = OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn3 && (fcn3->version > 8) && (fcn3->DeleteOldUsageTable != NULL)) { + if (fcn3 && (fcn3->version > 8) && (fcn3->DeleteOldUsageTable != nullptr)) { sts = fcn3->DeleteOldUsageTable(); } if (fcn1 && fcn1 != fcn3 && (fcn1->version > 8) && - (fcn1->DeleteOldUsageTable != NULL)) { + (fcn1->DeleteOldUsageTable != nullptr)) { sts = fcn1->DeleteOldUsageTable(); } return sts; } extern "C" bool OEMCrypto_IsSRMUpdateSupported() { - if (!gAdapter.get()) return false; + if (!gAdapter) return false; // Level 3 can't load an SRM, so this just checkes Level 1. const FunctionPointers* fcn = gAdapter->GetFunctionPointers(kLevelDefault); if (!fcn) return false; if (fcn->version < 13) return false; - if (fcn->IsSRMUpdateSupported == NULL) return false; + if (fcn->IsSRMUpdateSupported == nullptr) return false; return fcn->IsSRMUpdateSupported(); } extern "C" OEMCryptoResult OEMCrypto_GetCurrentSRMVersion(uint16_t* version) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; // Level 3 can't load an SRM, so this just checkes Level 1. const FunctionPointers* fcn = gAdapter->GetFunctionPointers(kLevelDefault); if (!fcn) return OEMCrypto_ERROR_NOT_IMPLEMENTED; if (fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->GetCurrentSRMVersion == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->GetCurrentSRMVersion == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->GetCurrentSRMVersion(version); } extern "C" OEMCryptoResult OEMCrypto_LoadSRM(const uint8_t* buffer, size_t buffer_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; // Level 3 can't load an SRM, so this just checkes Level 1. const FunctionPointers* fcn = gAdapter->GetFunctionPointers(kLevelDefault); if (!fcn) return OEMCrypto_ERROR_NOT_IMPLEMENTED; if (fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->LoadSRM == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->LoadSRM == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->LoadSRM(buffer, buffer_length); } extern "C" OEMCryptoResult OEMCrypto_RemoveSRM() { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; // Level 3 can't load an SRM, so this just checkes Level 1. const FunctionPointers* fcn = gAdapter->GetFunctionPointers(kLevelDefault); if (!fcn) return OEMCrypto_ERROR_NOT_IMPLEMENTED; if (fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (fcn->RemoveSRM == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (fcn->RemoveSRM == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return fcn->RemoveSRM(); } @@ -2274,11 +2292,11 @@ extern "C" OEMCryptoResult OEMCrypto_LoadUsageTableHeader( extern "C" OEMCryptoResult OEMCrypto_CreateNewUsageEntry( OEMCrypto_SESSION session, uint32_t* usage_entry_number) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (pair.fcn->CreateNewUsageEntry == NULL) + if (pair.fcn->CreateNewUsageEntry == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->CreateNewUsageEntry(pair.session, usage_entry_number); } @@ -2287,11 +2305,12 @@ extern "C" OEMCryptoResult OEMCrypto_LoadUsageEntry(OEMCrypto_SESSION session, uint32_t index, const uint8_t* buffer, size_t buffer_size) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (pair.fcn->LoadUsageEntry == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->LoadUsageEntry == nullptr) + return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->LoadUsageEntry(pair.session, index, buffer, buffer_size); } @@ -2299,11 +2318,11 @@ extern "C" OEMCryptoResult OEMCrypto_UpdateUsageEntry( OEMCrypto_SESSION session, uint8_t* header_buffer, size_t* header_buffer_length, uint8_t* entry_buffer, size_t* entry_buffer_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (pair.fcn->UpdateUsageEntry == NULL) + if (pair.fcn->UpdateUsageEntry == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->UpdateUsageEntry(pair.session, header_buffer, header_buffer_length, entry_buffer, @@ -2319,21 +2338,21 @@ extern "C" OEMCryptoResult OEMCrypto_ShrinkUsageTableHeader( extern "C" OEMCryptoResult OEMCrypto_MoveEntry(OEMCrypto_SESSION session, uint32_t new_index) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (pair.fcn->MoveEntry == NULL) return OEMCrypto_ERROR_NOT_IMPLEMENTED; + if (pair.fcn->MoveEntry == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->MoveEntry(pair.session, new_index); } extern "C" OEMCryptoResult OEMCrypto_CopyOldUsageEntry( OEMCrypto_SESSION session, const uint8_t* pst, size_t pst_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; if (pair.fcn->version < 13) return OEMCrypto_ERROR_NOT_IMPLEMENTED; - if (pair.fcn->CopyOldUsageEntry == NULL) + if (pair.fcn->CopyOldUsageEntry == nullptr) return OEMCrypto_ERROR_NOT_IMPLEMENTED; return pair.fcn->CopyOldUsageEntry(pair.session, pst, pst_length); } @@ -2357,10 +2376,10 @@ extern "C" OEMCryptoResult OEMCrypto_SetDecryptHash(OEMCrypto_SESSION session, uint32_t frame_number, const uint8_t* hash, size_t hash_length) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->SetDecryptHash == NULL) { + if (pair.fcn->SetDecryptHash == nullptr) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } return pair.fcn->SetDecryptHash(pair.session, frame_number, hash, @@ -2369,10 +2388,10 @@ extern "C" OEMCryptoResult OEMCrypto_SetDecryptHash(OEMCrypto_SESSION session, extern "C" OEMCryptoResult OEMCrypto_GetHashErrorCode( OEMCrypto_SESSION session, uint32_t* failed_frame_number) { - if (!gAdapter.get()) return OEMCrypto_ERROR_UNKNOWN_FAILURE; + if (!gAdapter) return OEMCrypto_ERROR_UNKNOWN_FAILURE; LevelSession pair = gAdapter->GetSession(session); if (!pair.fcn) return OEMCrypto_ERROR_INVALID_SESSION; - if (pair.fcn->GetHashErrorCode == NULL) { + if (pair.fcn->GetHashErrorCode == nullptr) { return OEMCrypto_ERROR_NOT_IMPLEMENTED; } return pair.fcn->GetHashErrorCode(pair.session, failed_frame_number); diff --git a/libwvdrmengine/cdm/core/src/privacy_crypto_boringssl.cpp b/libwvdrmengine/cdm/core/src/privacy_crypto_boringssl.cpp index e7635d26..fca33c71 100644 --- a/libwvdrmengine/cdm/core/src/privacy_crypto_boringssl.cpp +++ b/libwvdrmengine/cdm/core/src/privacy_crypto_boringssl.cpp @@ -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 x509_stack( sk_X509_new_null()); - if (x509_stack.get() == nullptr) { + if (!x509_stack) { LOGE("Unable to allocate X509 stack"); return false; } diff --git a/libwvdrmengine/cdm/core/src/properties.cpp b/libwvdrmengine/cdm/core/src/properties.cpp index 336fb6bd..2e424c9e 100644 --- a/libwvdrmengine/cdm/core/src/properties.cpp +++ b/libwvdrmengine/cdm/core/src/properties.cpp @@ -25,7 +25,7 @@ std::unique_ptr 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 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(); diff --git a/libwvdrmengine/cdm/core/src/service_certificate.cpp b/libwvdrmengine/cdm/core/src/service_certificate.cpp index ff7c8ba9..4dc17288 100644 --- a/libwvdrmengine/cdm/core/src/service_certificate.cpp +++ b/libwvdrmengine/cdm/core/src/service_certificate.cpp @@ -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; } diff --git a/libwvdrmengine/cdm/core/test/buffer_reader_test.cpp b/libwvdrmengine/cdm/core/test/buffer_reader_test.cpp index e54e1805..60968415 100644 --- a/libwvdrmengine/cdm/core/test/buffer_reader_test.cpp +++ b/libwvdrmengine/cdm/core/test/buffer_reader_test.cpp @@ -176,16 +176,16 @@ TEST_F(BufferReaderTest, InitializeGoodDataAndNoSize) { } TEST_F(BufferReaderTest, InitializeNoDataNoSize) { - BufferReader reader(NULL, 0); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + BufferReader reader(nullptr, 0); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, InitializeNoDataBadSize) { - BufferReader reader(NULL, 16); + BufferReader reader(nullptr, 16); // Buffer reader should default to a size of 0 when given // NULL data to ensure no reading of bad data - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, HasBytesWithBytes) { @@ -219,12 +219,12 @@ TEST_F(BufferReaderTest, HasBytesWithEmptyBuffer) { } TEST_F(BufferReaderTest, HasBytesWithNullBuffer) { - BufferReader reader(NULL, 8); + BufferReader reader(nullptr, 8); ASSERT_FALSE(reader.HasBytes(1)); ASSERT_TRUE(reader.HasBytes(0)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, HasBytesAfterAllRead) { @@ -266,12 +266,12 @@ TEST_F(BufferReaderTest, Read1WithNoData) { } TEST_F(BufferReaderTest, Read1WithNullBuffer) { - BufferReader reader(NULL, 16); + BufferReader reader(nullptr, 16); uint8_t read; ASSERT_FALSE(reader.Read1(&read)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, Read1WithNullReturn) { @@ -280,7 +280,7 @@ TEST_F(BufferReaderTest, Read1WithNullReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.Read1(NULL)); + ASSERT_FALSE(reader.Read1(nullptr)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -306,12 +306,12 @@ TEST_F(BufferReaderTest, Read2WithNoData) { } TEST_F(BufferReaderTest, Read2WithNullBuffer) { - BufferReader reader(NULL, 16); + BufferReader reader(nullptr, 16); uint16_t read; ASSERT_FALSE(reader.Read2(&read)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, Read2WithNullReturn) { @@ -320,7 +320,7 @@ TEST_F(BufferReaderTest, Read2WithNullReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.Read2(NULL)); + ASSERT_FALSE(reader.Read2(nullptr)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -354,12 +354,12 @@ TEST_F(BufferReaderTest, Read2sWithNoData) { } TEST_F(BufferReaderTest, Read2sWithNullBuffer) { - BufferReader reader(NULL, 16); + BufferReader reader(nullptr, 16); int16_t read; ASSERT_FALSE(reader.Read2s(&read)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, Read2sWithNullReturn) { @@ -368,7 +368,7 @@ TEST_F(BufferReaderTest, Read2sWithNullReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.Read2s(NULL)); + ASSERT_FALSE(reader.Read2s(nullptr)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -397,12 +397,12 @@ TEST_F(BufferReaderTest, Read4WithNoData) { } TEST_F(BufferReaderTest, Read4WithNullBuffer) { - BufferReader reader(NULL, 16); + BufferReader reader(nullptr, 16); uint32_t read; ASSERT_FALSE(reader.Read4(&read)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, Read4WithNullReturn) { @@ -411,7 +411,7 @@ TEST_F(BufferReaderTest, Read4WithNullReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.Read4(NULL)); + ASSERT_FALSE(reader.Read4(nullptr)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -447,12 +447,12 @@ TEST_F(BufferReaderTest, Read4sWithNoData) { } TEST_F(BufferReaderTest, Read4sWithNullBuffer) { - BufferReader reader(NULL, 16); + BufferReader reader(nullptr, 16); int32_t read; ASSERT_FALSE(reader.Read4s(&read)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, Read4sWithNullReturn) { @@ -461,7 +461,7 @@ TEST_F(BufferReaderTest, Read4sWithNullReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.Read4s(NULL)); + ASSERT_FALSE(reader.Read4s(nullptr)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -490,12 +490,12 @@ TEST_F(BufferReaderTest, Read8WithNoData) { } TEST_F(BufferReaderTest, Read8WithNullBuffer) { - BufferReader reader(NULL, 16); + BufferReader reader(nullptr, 16); uint64_t read; ASSERT_FALSE(reader.Read8(&read)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, Read8WithNullReturn) { @@ -504,7 +504,7 @@ TEST_F(BufferReaderTest, Read8WithNullReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.Read8(NULL)); + ASSERT_FALSE(reader.Read8(nullptr)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -540,12 +540,12 @@ TEST_F(BufferReaderTest, Read8sWithNoData) { } TEST_F(BufferReaderTest, Read8sWithNullBuffer) { - BufferReader reader(NULL, 16); + BufferReader reader(nullptr, 16); int64_t read; ASSERT_FALSE(reader.Read8s(&read)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, Read8sWithNullReturn) { @@ -554,7 +554,7 @@ TEST_F(BufferReaderTest, Read8sWithNullReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.Read8s(NULL)); + ASSERT_FALSE(reader.Read8s(nullptr)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -578,12 +578,12 @@ TEST_F(BufferReaderTest, ReadString) { } TEST_F(BufferReaderTest, ReadStringNullSource) { - BufferReader reader(NULL, 5); + BufferReader reader(nullptr, 5); std::string read; ASSERT_FALSE(reader.ReadString(&read, 5)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, ReadStringNullReturn) { @@ -592,7 +592,7 @@ TEST_F(BufferReaderTest, ReadStringNullReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.ReadString(NULL, 5)); + ASSERT_FALSE(reader.ReadString(nullptr, 5)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -662,13 +662,13 @@ TEST_F(BufferReaderTest, ReadVectorTooLarge) { } TEST_F(BufferReaderTest, ReadVectorNullSource) { - BufferReader reader(NULL, 16); + BufferReader reader(nullptr, 16); std::vector read; ASSERT_FALSE(reader.ReadVec(&read, 4)); ASSERT_TRUE(0 == read.size()); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, ReadVectorNullReturn) { @@ -677,7 +677,7 @@ TEST_F(BufferReaderTest, ReadVectorNullReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.ReadVec(NULL, 4)); + ASSERT_FALSE(reader.ReadVec(nullptr, 4)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -712,12 +712,12 @@ TEST_F(BufferReaderTest, Read4Into82Bytes) { TEST_F(BufferReaderTest, Read4Into8Zero) { ASSERT_TRUE(CheckRead4Into8(0)); } TEST_F(BufferReaderTest, Read4Into8NullSource) { - BufferReader reader(NULL, 4); + BufferReader reader(nullptr, 4); uint64_t read; ASSERT_FALSE(reader.Read4Into8(&read)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, Read4Into8TooLittleData) { @@ -739,7 +739,7 @@ TEST_F(BufferReaderTest, Read4Into8NoReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.Read4Into8(NULL)); + ASSERT_FALSE(reader.Read4Into8(nullptr)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); @@ -770,12 +770,12 @@ TEST_F(BufferReaderTest, Read4sInto8sNegative) { } TEST_F(BufferReaderTest, Read4sInto8sNullSource) { - BufferReader reader(NULL, 4); + BufferReader reader(nullptr, 4); int64_t read; ASSERT_FALSE(reader.Read4sInto8s(&read)); - ASSERT_TRUE(ValidateReader(reader, NULL, 0, 0)); + ASSERT_TRUE(ValidateReader(reader, nullptr, 0, 0)); } TEST_F(BufferReaderTest, Read4sInto8sTooLittleData) { @@ -797,7 +797,7 @@ TEST_F(BufferReaderTest, Read4sInto8sNoReturn) { BufferReader reader(raw_data, sizeof(raw_data)); - ASSERT_FALSE(reader.Read4sInto8s(NULL)); + ASSERT_FALSE(reader.Read4sInto8s(nullptr)); ASSERT_TRUE(ValidateData(raw_data, sizeof(raw_data))); ASSERT_TRUE(ValidateReader(reader, raw_data, sizeof(raw_data), 0)); diff --git a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp index 87b09f5c..4a2423d2 100644 --- a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp +++ b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp @@ -61,11 +61,11 @@ class WvCdmEnginePreProvTest : public WvCdmTestBase { } virtual void OpenSession() { - CdmResponseType status = - cdm_engine_.OpenSession(config_.key_system(), NULL, NULL, &session_id_); + CdmResponseType status = cdm_engine_.OpenSession( + config_.key_system(), nullptr, nullptr, &session_id_); if (status == NEED_PROVISIONING) { Provision(); - status = cdm_engine_.OpenSession(config_.key_system(), NULL, NULL, + status = cdm_engine_.OpenSession(config_.key_system(), nullptr, nullptr, &session_id_); } ASSERT_EQ(status, NO_ERROR); diff --git a/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp b/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp index 23efa9e6..ada49f9f 100644 --- a/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp @@ -111,7 +111,7 @@ const std::string kWrappedKey = a2bs_hex( class MockDeviceFiles : public DeviceFiles { public: - MockDeviceFiles() : DeviceFiles(NULL) {} + MockDeviceFiles() : DeviceFiles(nullptr) {} MOCK_METHOD1(Init, bool(CdmSecurityLevel)); MOCK_METHOD4(RetrieveCertificate, bool(std::string*, std::string*, @@ -154,7 +154,7 @@ class MockCryptoSession : public TestCryptoSession { class MockPolicyEngine : public PolicyEngine { public: MockPolicyEngine(CryptoSession* crypto_session) - : PolicyEngine("mock_session_id", NULL, crypto_session) {} + : PolicyEngine("mock_session_id", nullptr, crypto_session) {} // Leaving a place-holder for when PolicyEngine methods need to be mocked }; @@ -177,7 +177,7 @@ class CdmSessionTest : public WvCdmTestBase { void SetUp() override { WvCdmTestBase::SetUp(); metrics_.reset(new metrics::SessionMetrics); - cdm_session_.reset(new CdmSession(NULL, metrics_)); + cdm_session_.reset(new CdmSession(nullptr, metrics_)); // Inject testing mocks. license_parser_ = new MockCdmLicense(cdm_session_->session_id()); cdm_session_->set_license_parser(license_parser_); @@ -230,7 +230,7 @@ TEST_F(CdmSessionTest, InitWithBuiltInCertificate) { Eq(policy_engine_))) .WillOnce(Return(true)); - ASSERT_EQ(NO_ERROR, cdm_session_->Init(NULL)); + ASSERT_EQ(NO_ERROR, cdm_session_->Init(nullptr)); } TEST_F(CdmSessionTest, InitWithCertificate) { @@ -258,7 +258,7 @@ TEST_F(CdmSessionTest, InitWithCertificate) { Eq(policy_engine_))) .WillOnce(Return(true)); - ASSERT_EQ(NO_ERROR, cdm_session_->Init(NULL)); + ASSERT_EQ(NO_ERROR, cdm_session_->Init(nullptr)); } TEST_F(CdmSessionTest, ReInitFail) { @@ -285,15 +285,15 @@ TEST_F(CdmSessionTest, ReInitFail) { Eq(kEmptyString), Eq(crypto_session_), Eq(policy_engine_))) .WillOnce(Return(true)); - ASSERT_EQ(NO_ERROR, cdm_session_->Init(NULL)); - ASSERT_NE(NO_ERROR, cdm_session_->Init(NULL)); + ASSERT_EQ(NO_ERROR, cdm_session_->Init(nullptr)); + ASSERT_NE(NO_ERROR, cdm_session_->Init(nullptr)); } TEST_F(CdmSessionTest, InitFailCryptoError) { EXPECT_CALL(*crypto_session_, Open(Eq(kLevelDefault))) .WillOnce(Return(UNKNOWN_ERROR)); - ASSERT_EQ(UNKNOWN_ERROR, cdm_session_->Init(NULL)); + ASSERT_EQ(UNKNOWN_ERROR, cdm_session_->Init(nullptr)); } TEST_F(CdmSessionTest, InitNeedsProvisioning) { @@ -312,7 +312,7 @@ TEST_F(CdmSessionTest, InitNeedsProvisioning) { NotNull(), _)) .WillOnce(Return(false)); - ASSERT_EQ(NEED_PROVISIONING, cdm_session_->Init(NULL)); + ASSERT_EQ(NEED_PROVISIONING, cdm_session_->Init(nullptr)); } TEST_F(CdmSessionTest, UpdateUsageEntry) { @@ -352,7 +352,7 @@ TEST_F(CdmSessionTest, UpdateUsageEntry) { EXPECT_CALL(usage_table_header_, UpdateEntry(NotNull(), NotNull())) .WillRepeatedly(Return(NO_ERROR)); - EXPECT_EQ(NO_ERROR, cdm_session_->Init(NULL)); + EXPECT_EQ(NO_ERROR, cdm_session_->Init(nullptr)); EXPECT_EQ(kUsageEntrySupport, cdm_session_->get_usage_support_type()) << "Usage support type: " << cdm_session_->get_usage_support_type(); EXPECT_EQ(NO_ERROR, cdm_session_->UpdateUsageEntryInformation()); diff --git a/libwvdrmengine/cdm/core/test/device_files_unittest.cpp b/libwvdrmengine/cdm/core/test/device_files_unittest.cpp index e19e3775..b2e3f1b2 100644 --- a/libwvdrmengine/cdm/core/test/device_files_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/device_files_unittest.cpp @@ -2637,7 +2637,7 @@ TEST_F(DeviceFilesUsageInfoTest, ListNullParam) { DeviceFiles device_files(&file_system); EXPECT_TRUE(device_files.Init(kSecurityLevelL1)); - EXPECT_FALSE(device_files.ListUsageInfoFiles(NULL)); + EXPECT_FALSE(device_files.ListUsageInfoFiles(nullptr)); } TEST_F(DeviceFilesUsageInfoTest, ListIdsNull) { @@ -2647,7 +2647,7 @@ TEST_F(DeviceFilesUsageInfoTest, ListIdsNull) { DeviceFiles device_files(&file_system); EXPECT_TRUE(device_files.Init(kSecurityLevelL1)); - EXPECT_FALSE(device_files.ListUsageIds(app_id, NULL, NULL)); + EXPECT_FALSE(device_files.ListUsageIds(app_id, nullptr, nullptr)); } TEST_F(DeviceFilesUsageInfoTest, ListUsageIds) { @@ -2873,7 +2873,7 @@ TEST_P(DeviceFilesUsageInfoTest, ListKeySetIds) { EXPECT_TRUE(device_files.Init(kSecurityLevelL1)); std::vector key_set_ids; - EXPECT_TRUE(device_files.ListUsageIds(app_id, &key_set_ids, NULL)); + EXPECT_TRUE(device_files.ListUsageIds(app_id, &key_set_ids, nullptr)); if (index >= 0) { for (size_t i = 0; i < key_set_ids.size(); ++i) { @@ -2925,7 +2925,7 @@ TEST_P(DeviceFilesUsageInfoTest, ListProviderSessionTokenIds) { std::vector provider_session_tokens; EXPECT_TRUE( - device_files.ListUsageIds(app_id, NULL, &provider_session_tokens)); + device_files.ListUsageIds(app_id, nullptr, &provider_session_tokens)); if (index >= 0) { for (size_t i = 0; i < provider_session_tokens.size(); ++i) { diff --git a/libwvdrmengine/cdm/core/test/http_socket.cpp b/libwvdrmengine/cdm/core/test/http_socket.cpp index 762830ab..74d1a6be 100644 --- a/libwvdrmengine/cdm/core/test/http_socket.cpp +++ b/libwvdrmengine/cdm/core/test/http_socket.cpp @@ -105,15 +105,15 @@ bool SocketWait(int fd, bool for_read, int timeout_in_ms) { tv.tv_sec = timeout_in_ms / 1000; tv.tv_usec = (timeout_in_ms % 1000) * 1000; - fd_set* read_fds = NULL; - fd_set* write_fds = NULL; + fd_set* read_fds = nullptr; + fd_set* write_fds = nullptr; if (for_read) { read_fds = &fds; } else { write_fds = &fds; } - int ret = select(fd + 1, read_fds, write_fds, NULL, &tv); + int ret = select(fd + 1, read_fds, write_fds, nullptr, &tv); if (ret == 0) { LOGE("socket timed out"); return false; @@ -209,7 +209,7 @@ bool HttpSocket::ParseUrl(const std::string& url, std::string* scheme, } HttpSocket::HttpSocket(const std::string& url) - : socket_fd_(-1), ssl_(NULL), ssl_ctx_(NULL) { + : socket_fd_(-1), ssl_(nullptr), ssl_ctx_(nullptr) { valid_url_ = ParseUrl(url, &scheme_, &secure_connect_, &domain_name_, &port_, &resource_path_); SSL_library_init(); @@ -228,11 +228,11 @@ void HttpSocket::CloseSocket() { } if (ssl_) { SSL_free(ssl_); - ssl_ = NULL; + ssl_ = nullptr; } if (ssl_ctx_) { SSL_CTX_free(ssl_ctx_); - ssl_ctx_ = NULL; + ssl_ctx_ = nullptr; } } @@ -261,7 +261,7 @@ bool HttpSocket::Connect(int timeout_in_ms) { hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG; - struct addrinfo* addr_info = NULL; + struct addrinfo* addr_info = nullptr; int ret = getaddrinfo(domain_name_.c_str(), port_.c_str(), &hints, &addr_info); if (ret != 0) { @@ -413,7 +413,7 @@ int HttpSocket::Read(char* data, int len, int timeout_in_ms) { if (ssl_error == SSL_ERROR_SYSCALL) { LOGE(" errno = %d = %s", GetError(), GetErrorString()); } - ERR_print_errors_cb(LogBoringSslError, NULL); + ERR_print_errors_cb(LogBoringSslError, nullptr); return -1; } } else { diff --git a/libwvdrmengine/cdm/core/test/http_socket_test.cpp b/libwvdrmengine/cdm/core/test/http_socket_test.cpp index d089dcbc..f4f99601 100644 --- a/libwvdrmengine/cdm/core/test/http_socket_test.cpp +++ b/libwvdrmengine/cdm/core/test/http_socket_test.cpp @@ -108,62 +108,62 @@ struct ParseUrlTests { ParseUrlTests parse_url_tests[] = { { - "https://code.google.com/p/googletest/wiki/Primer", // url - "https", // scheme - true, // secure_connect - "code.google.com", // domain_name - "443", // port - "/p/googletest/wiki/Primer", // path + "https://code.google.com/p/googletest/wiki/Primer", // url + "https", // scheme + true, // secure_connect + "code.google.com", // domain_name + "443", // port + "/p/googletest/wiki/Primer", // path }, { - "http://code.google.com/p/googletest/wiki/Primer/", // url - "http", // scheme - false, // secure_connect - "code.google.com", // domain_name - "80", // port - "/p/googletest/wiki/Primer/", // path + "http://code.google.com/p/googletest/wiki/Primer/", // url + "http", // scheme + false, // secure_connect + "code.google.com", // domain_name + "80", // port + "/p/googletest/wiki/Primer/", // path }, { - "http://code.google.com/", // url - "http", // scheme - false, // secure_connect - "code.google.com", // domain_name - "80", // port - "/", // path + "http://code.google.com/", // url + "http", // scheme + false, // secure_connect + "code.google.com", // domain_name + "80", // port + "/", // path }, { - "http://code.google.com", // url - "http", // scheme - false, // secure_connect - "code.google.com", // domain_name - "80", // port - "/", // path + "http://code.google.com", // url + "http", // scheme + false, // secure_connect + "code.google.com", // domain_name + "80", // port + "/", // path }, { - "http://10.11.12.13:8888/drm", // url - "http", // scheme - false, // secure_connect - "10.11.12.13", // domain_name - "8888", // port - "/drm", // path + "http://10.11.12.13:8888/drm", // url + "http", // scheme + false, // secure_connect + "10.11.12.13", // domain_name + "8888", // port + "/drm", // path }, { - "http://10.11.12.13:8888", // url - "http", // scheme - false, // secure_connect - "10.11.12.13", // domain_name - "8888", // port - "/", // path + "http://10.11.12.13:8888", // url + "http", // scheme + false, // secure_connect + "10.11.12.13", // domain_name + "8888", // port + "/", // path }, { - "https://10.11.12.13:8888", // url - "https", // scheme - true, // secure_connect - "10.11.12.13", // domain_name - "8888", // port - "/", // path + "https://10.11.12.13:8888", // url + "https", // scheme + true, // secure_connect + "10.11.12.13", // domain_name + "8888", // port + "/", // path }, - {NULL, NULL, false, NULL, 0, NULL} // list terminator + {nullptr, nullptr, false, nullptr, 0, nullptr} // list terminator }; TEST_F(HttpSocketTest, ParseUrlTest) { @@ -172,9 +172,9 @@ TEST_F(HttpSocketTest, ParseUrlTest) { std::string domain_name; std::string port; std::string path; - ParseUrlTests* test = NULL; + ParseUrlTests* test = nullptr; - for (test = &parse_url_tests[0]; test->url != NULL; ++test) { + for (test = &parse_url_tests[0]; test->url != nullptr; ++test) { bool ok = HttpSocket::ParseUrl(test->url, &scheme, &secure_connect, &domain_name, &port, &path); EXPECT_TRUE(ok); diff --git a/libwvdrmengine/cdm/core/test/license_keys_unittest.cpp b/libwvdrmengine/cdm/core/test/license_keys_unittest.cpp index dcb7ca0e..b2e66d99 100644 --- a/libwvdrmengine/cdm/core/test/license_keys_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/license_keys_unittest.cpp @@ -107,10 +107,11 @@ class LicenseKeysTest : public ::testing::Test { virtual void AddContentKey( const KeyId& key_id, bool set_level = false, KeyContainer::SecurityLevel level = KeyContainer::SW_SECURE_CRYPTO, - bool set_hdcp = false, KeyContainer::OutputProtection::HDCP hdcp_value = + bool set_hdcp = false, + KeyContainer::OutputProtection::HDCP hdcp_value = KeyContainer::OutputProtection::HDCP_NONE, bool set_constraints = false, - std::vector* constraints = NULL) { + std::vector* constraints = nullptr) { KeyContainer* key = license_.add_key(); key->set_type(KeyContainer::CONTENT); if (set_level) { @@ -141,7 +142,7 @@ class LicenseKeysTest : public ::testing::Test { KeyContainer::OutputProtection::HDCP hdcp_value = KeyContainer::OutputProtection::HDCP_NONE, bool set_constraints = false, - std::vector* constraints = NULL) { + std::vector* constraints = nullptr) { AddContentKey(key_id, set_level, level, set_hdcp, hdcp_value, set_constraints, constraints); license_.mutable_key(license_.key_size() - 1) diff --git a/libwvdrmengine/cdm/core/test/license_unittest.cpp b/libwvdrmengine/cdm/core/test/license_unittest.cpp index ea387fb1..ba671cb1 100644 --- a/libwvdrmengine/cdm/core/test/license_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/license_unittest.cpp @@ -155,7 +155,7 @@ class MockCryptoSession : public TestCryptoSession { class MockPolicyEngine : public PolicyEngine { public: MockPolicyEngine(CryptoSession* crypto) - : PolicyEngine("mock_session_id", NULL, crypto) {} + : PolicyEngine("mock_session_id", nullptr, crypto) {} MOCK_METHOD1(SetEntitledLicenseKeys, void(const std::vector&)); }; @@ -234,7 +234,7 @@ class CdmLicenseTest : public WvCdmTestBase { virtual void CreateCdmLicense() { cdm_license_ = new CdmLicenseTestPeer(kCdmSessionId, clock_); - clock_ = NULL; + clock_ = nullptr; } CdmLicenseTestPeer* cdm_license_; @@ -265,7 +265,7 @@ TEST_F(CdmLicenseTest, InitFail_EmptyToken) { TEST_F(CdmLicenseTest, InitFail_CryptoSessionNull) { CreateCdmLicense(); EXPECT_FALSE(cdm_license_->Init(kToken, kClientTokenDrmCert, "", false, - kEmptyServiceCertificate, NULL, + kEmptyServiceCertificate, nullptr, policy_engine_)); } @@ -275,7 +275,7 @@ TEST_F(CdmLicenseTest, InitFail_PolicyEngineNull) { CreateCdmLicense(); EXPECT_FALSE(cdm_license_->Init(kToken, kClientTokenDrmCert, "", false, kEmptyServiceCertificate, crypto_session_, - NULL)); + nullptr)); } TEST_F(CdmLicenseTest, InitWithEmptyServiceCert) { diff --git a/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp b/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp index 99eccea1..8c14a457 100644 --- a/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp @@ -1974,7 +1974,8 @@ class PolicyEngineQueryTest : public PolicyEngineTest { protected: void SetUp() override { PolicyEngineTest::SetUp(); - policy_engine_.reset(new PolicyEngine(kSessionId, NULL, &crypto_session_)); + policy_engine_.reset( + new PolicyEngine(kSessionId, nullptr, &crypto_session_)); InjectMockClock(); // Use a STREAMING license policy. diff --git a/libwvdrmengine/cdm/core/test/test_base.cpp b/libwvdrmengine/cdm/core/test/test_base.cpp index 570bed46..2f240265 100644 --- a/libwvdrmengine/cdm/core/test/test_base.cpp +++ b/libwvdrmengine/cdm/core/test/test_base.cpp @@ -330,12 +330,12 @@ void WvCdmTestBase::EnsureProvisioned() { FileSystem file_system; CdmEngine cdm_engine(&file_system, std::shared_ptr(new EngineMetrics)); - CdmResponseType status = - cdm_engine.OpenSession(config_.key_system(), NULL, NULL, &session_id); + CdmResponseType status = cdm_engine.OpenSession(config_.key_system(), nullptr, + nullptr, &session_id); if (status == NEED_PROVISIONING) { Provision(); - status = - cdm_engine.OpenSession(config_.key_system(), NULL, NULL, &session_id); + status = cdm_engine.OpenSession(config_.key_system(), nullptr, nullptr, + &session_id); } ASSERT_EQ(NO_ERROR, status); ASSERT_NE("", session_id) << "Could not open CDM session."; @@ -445,7 +445,7 @@ TestLicenseHolder::~TestLicenseHolder() { void TestLicenseHolder::OpenSession(const std::string& key_system) { CdmResponseType status = - cdm_engine_->OpenSession(key_system, NULL, NULL, &session_id_); + cdm_engine_->OpenSession(key_system, nullptr, nullptr, &session_id_); ASSERT_EQ(status, NO_ERROR); ASSERT_NE("", session_id_) << "Could not open CDM session."; ASSERT_TRUE(cdm_engine_->IsOpenSession(session_id_)); @@ -624,7 +624,7 @@ void TestLicenseHolder::DeriveKeysFromSessionKey() { bool TestLicenseHolder::DeriveKey(const std::vector& key, const std::vector& context, int counter, std::vector* out) { - if (key.empty() || counter > 4 || context.empty() || out == NULL) { + if (key.empty() || counter > 4 || context.empty() || out == nullptr) { LOGE("DeriveKey(): bad context"); return false; } diff --git a/libwvdrmengine/cdm/core/test/usage_table_header_unittest.cpp b/libwvdrmengine/cdm/core/test/usage_table_header_unittest.cpp index 424ac36b..9631f38a 100644 --- a/libwvdrmengine/cdm/core/test/usage_table_header_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/usage_table_header_unittest.cpp @@ -333,9 +333,9 @@ class UsageTableHeaderTest : public WvCdmTestBase { // UsageTableHeaderTest maintains ownership of returned pointer MockUsageTableHeader* SetUpMock() { // Release non-mocked usage table header - if (usage_table_header_ != NULL) { + if (usage_table_header_ != nullptr) { delete usage_table_header_; - usage_table_header_ = NULL; + usage_table_header_ = nullptr; } // Create new mock objects if using MockUsageTableHeader @@ -352,7 +352,7 @@ class UsageTableHeaderTest : public WvCdmTestBase { } void TearDown() override { - if (usage_table_header_ != NULL) delete usage_table_header_; + if (usage_table_header_ != nullptr) delete usage_table_header_; } void Init(CdmSecurityLevel security_level, @@ -379,8 +379,8 @@ TEST_F(UsageTableHeaderTest, InitError) { EXPECT_FALSE(usage_table_header_->Init(kSecurityLevelL2, crypto_session_)); EXPECT_FALSE( usage_table_header_->Init(kSecurityLevelUnknown, crypto_session_)); - EXPECT_FALSE(usage_table_header_->Init(kSecurityLevelL1, NULL)); - EXPECT_FALSE(usage_table_header_->Init(kSecurityLevelL2, NULL)); + EXPECT_FALSE(usage_table_header_->Init(kSecurityLevelL1, nullptr)); + EXPECT_FALSE(usage_table_header_->Init(kSecurityLevelL2, nullptr)); } class UsageTableHeaderInitializationTest