Merges to android Pi release (part 12)
These are a set of CLs merged from the wv cdm repo to the android repo. * Correct error logging Author: Rahul Frias <rfrias@google.com> [ Merge of http://go/wvgerrit/40000 ] In tests, we set the cipher list to avoid using insecure ciphers when connecting to the provisioning/license service. The result of setting the cipher list was being incorrectly validated. Bug: 64847919 * Move mips cache headers to clear_cache_function.h Author: Srujan Gaddam <srujzs@google.com> [ Merge of http://go/wvgerrit/39700 ] Since the clear_cache function has been moved away from the dynamic adapter, we need these conditional includes to be migrated as well for MIPS. * Comment out Level 3 debug call until merge Author: Srujan Gaddam <srujzs@google.com> [ Merge of http://go/wvgerrit/39761 ] This call was introduced in go/wvgerrit/34260/. Since the haystack tool in google3 still needs this merge, this should be commented out so the tool can still build until the merge has finished. * Add logging for MAC keys to mock Author: Srujan Gaddam <srujzs@google.com> [ Merge of http://go/wvgerrit/39740 ] Bug: 70637842 * Move external interfaces into level3.h + refactor Author: Srujan Gaddam <srujzs@google.com> [ Merge of http://go/wvgerrit/39673 ] As part of b/70523618, this CL moves interfaces that partners are responsible for in Level 3 to level3.h so they can be visible as part of the CDM release process. It also cleans up some of the names of the files and adds documentation. * Corrected close session logging level Author: Rahul Frias <rfrias@google.com> [ Merge of http://go/wvgerrit/39676 ] Bug: 69460963 * Remove Security Level Path Backward Compatibility Support Author: Rahul Frias <rfrias@google.com> [ Merge of http://go/wvgerrit/39505 ] From the android K release onwards certificates were stored in security level specific directories. If upgrading from previous releases persistent information needed to be moved to those directories. Since no device is likely to upgrade from J to Pi, comptibility support can be removed. Bug: 70160032 * Rename privacy_crypto_openssl To privacy_crypto_boringssl Author: John W. Bruce <juce@google.com> [ Merge of http://go/wvgerrit/37122 ] Now that we no longer support OpenSSL in the Shared Source CDM, the name of this file can be updated. Bug: 67907873 Test: build.py x86-64 Test: wv_ce_cdm_unittest Test: jenkins/linux_unit_tests * Remove Conditional Compilation from OpenSSL/BoringSSL Author: John W. Bruce <juce@google.com> [ Merge of http://go/wvgerrit/39460 ] This change removes the usages of conditional compilation to support both BoringSSL and OpenSSL, as well as to support multiple versions of the OpenSSL API. All code is now compiled against one of the two versions of BoringSSL in third_party/. Note that in some cases, the kit/ and legacy_kit/ versions of BoringSSL had different APIs, so when removing the OpenSSL version compatibility conditional compilation, sometimes the older branch was kept and sometimes the newer branch was kept. Bug: 67907873 Test: build.py x86-64 Test: wv_ce_cdm_unittest Test: jenkins/linux_unit_tests * Build CE & Jenkins CDMs With BoringSSL from third_party/ Author: John W. Bruce <juce@google.com> [ Merge of http://go/wvgerrit/37120 ] Up until now, integrators have been responsible for providing a compatible crypto library for use by the CE CDM. (either OpenSSL or BoringSSL) After this change, this decision will no longer be in their hands. The CE CDM build will always use the copy of BoringSSL in third_party/, which will be statically linked with our library with hidden visibility. This allows us to better control what crypto library we use and will prevent continuing problems with trying to support both OpenSSL and BoringSSL. Unfortunately, BoringSSL began using C++11 in mid-2017, and we can't support C++11 right now. Until we can, we need to use a C++11-free version of BoringSSL for libssl. The CDM itself will continue to use a recent BoringSSL, as it only needs libcrypto. But the unit tests that need libssl have to use the legacy version. Bug: 67907873 Test: build.py x86-64 Test: wv_ce_cdm_unittest Test: jenkins/linux_unit_tests * Modified RNG for Level3 to use more entropy Author: Srujan Gaddam <srujzs@google.com> [ Merge of http://go/wvgerrit/39220 ] Bug: 65165076 Modified seed generation to use an xor of clock_gettime and client-implemented code to supply random seeds to the RNG. Modified the RNG as well to use xoroshiro128+ instead of xorshift, since it uses more than one seed/state (which are 64-bit) and has higher "statistical quality". The default implementations for the seed generation use /dev/urandom. * Configure base path for Level3FileSystem Author: Srujan Gaddam <srujzs@google.com> [ Merge of http://go/wvgerrit/39506 ] This is in response to b/70354006. This change makes the Android Level3FileSystem use the existing properties method GetDevicesFilesBasePath for binderization. The same is done for the Linux implementation. * Add legacy_kit/ to BoringSSL Directory Author: John W. Bruce <juce@google.com> [ Merge of http://go/wvgerrit/38861 ] This adds a second copy of BoringSSL to the third_party/boringssl/ directory. This second copy is pinned to the last revision of BoringSSL not to require C++11 and is not updated by the UPDATE_BORINGSSL.sh script. This second copy will be used to provide libssl to the tests on devices that do not support C++11. Once we support C++11 in the CDM again, this weight should be removed and all targets should use the copy of BoringSSL in the kit/ directory. Bug: 67907873 * Use Shared Libraries for Unit Tests Author: John W. Bruce <juce@google.com> [ Merge of http://go/wvgerrit/38860 ] Some unit tests were using a statically-linked CDM instead of a dynamically-linked one. (Or, in one case, trying to link both ways into the same binary.) For now, we need to only link dynamically, so that the unit tests and the CDM can use different versions of BoringSSL. Long-term, we would like to test both kinds of linkage. (See b/69548115 for that.) Some unit tests were also using a dynamicaly-linked CDM that was named such that it appeared to be statically-linked. This patch renames some targets to make the linkage clearer. Bug: 67907873 * Change CDM_Backwards_Compatiblity_Tests to dedicated brances Author: Fred Gylys-Colwell <fredgc@google.com> [ Merge of http://go/wvgerrit/39003 ] The build scripts used by CDM_Backwards_Compatiblity_Tests now pull old versions of oemcrypto from the dedicated branches oemcrypto-v*, which [will eventually] contain old oemcrypto versions, that build with the current build system with a current boringssl version. bug: 67907873 * Fix spacing on level3 header Author: Srujan Gaddam <srujzs@google.com> [ Merge of http://go/wvgerrit/38760 ] * Correct Query status calls Author: Rahul Frias <rfrias@google.com> [ Merge of http://go/wvgerrit/38640 ] Bug: 70160032 * Refactoring to allow encryption of client ID Author: Rahul Frias <rfrias@google.com> [ Merge of http://go/wvgerrit/37460 ] The code has been restructured to allow encryption of client identification in provisioning requests. This will be enabled when server side changes have been made (b/69427217). * Additional information is included in the Client Identification portion of the provisioning request. * Client identification will be encrypted with a service certificate provided by the app/client. Platform changes to enable passing this to core are needed. If a service certificate is not provided, a default one associated with the production Keysmith will be used. * Switched APIs in CdmEngine to take a service certificate for provisioning rather than licensing. Service certificates for licensing are session based and passed as properties from platform code. Bug: 30737060 * Allow some CDM errors to be reported from multiple locations Author: Rahul Frias <rfrias@google.com> [ Merge of http://go/wvgerrit/38360 ] This creates some CdmResponseType errors which may be reused PARAMETER_NULL, NOT_INITIALIZED_ERROR, REINIT_ERROR. I have made changes to a few classes to report these errors. Will work on additional classes in a separate CL. Bug: 69864404 BUG: 71650075 Test: WV Unit/integration tests Change-Id: Icc048770d424ac537d11ff327cda2cb142da802d
This commit is contained in:
@@ -39,15 +39,14 @@ class CdmEngine {
|
||||
CdmEngine(FileSystem* file_system, const std::string& spoid = EMPTY_SPOID);
|
||||
virtual ~CdmEngine();
|
||||
|
||||
// Set service certificate for all sessions under this CDM/CdmEngine.
|
||||
// Setting to the empty string is OK. If the License Service certificate is
|
||||
// empty and privacy mode is true, the certificate will be fetched from
|
||||
// the server before the first license request.
|
||||
virtual CdmResponseType SetServiceCertificate(
|
||||
// Set service certificate used when provisioning under this CDM/CdmEngine.
|
||||
// If no valid service certificate is set, a default one associated with
|
||||
// the WV production provisioning server will be used.
|
||||
virtual CdmResponseType SetProvisioningServiceCertificate(
|
||||
const std::string& certificate);
|
||||
|
||||
// Report whether the service certificate has been set.
|
||||
virtual bool HasServiceCertificate();
|
||||
virtual bool HasProvisioningServiceCertificate();
|
||||
|
||||
// Session related methods
|
||||
virtual CdmResponseType OpenSession(
|
||||
@@ -323,11 +322,8 @@ class CdmEngine {
|
||||
|
||||
static bool seeded_;
|
||||
|
||||
// Service certificate for license server and provisioning server.
|
||||
// It is initially empty. If left empty, the operations that
|
||||
// require them (getting provider_id, encrypting ClientIdentification)
|
||||
// are not performed.
|
||||
ServiceCertificate service_certificate_;
|
||||
// Service certificate for the provisioning server.
|
||||
ServiceCertificate provisioning_service_certificate_;
|
||||
|
||||
// usage related variables
|
||||
scoped_ptr<CdmSession> usage_session_;
|
||||
|
||||
52
libwvdrmengine/cdm/core/include/cdm_session_map.h
Normal file
52
libwvdrmengine/cdm/core/include/cdm_session_map.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2017 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef WVCDM_CORE_CDM_SESSION_MAP_H_
|
||||
#define WVCDM_CORE_CDM_SESSION_MAP_H_
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "cdm_session.h"
|
||||
#include "lock.h"
|
||||
#include "shared_ptr.h"
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
typedef std::list<shared_ptr<CdmSession> > CdmSessionList;
|
||||
|
||||
class CdmSessionMap {
|
||||
public:
|
||||
CdmSessionMap() {}
|
||||
virtual ~CdmSessionMap();
|
||||
|
||||
void Add(const std::string& id, CdmSession* session);
|
||||
|
||||
bool CloseSession(const std::string& id);
|
||||
|
||||
bool Exists(const std::string& id);
|
||||
|
||||
size_t Size() const { return sessions_.size(); }
|
||||
|
||||
bool FindSession(const CdmSessionId& id,
|
||||
shared_ptr<CdmSession>* session);
|
||||
|
||||
void GetSessionList(CdmSessionList& sessions);
|
||||
|
||||
private:
|
||||
typedef std::map<CdmSessionId, shared_ptr<CdmSession> >
|
||||
CdmIdToSessionMap;
|
||||
|
||||
bool FindSessionNoLock(const CdmSessionId& session_id,
|
||||
shared_ptr<CdmSession>* session);
|
||||
|
||||
Lock lock_;
|
||||
CdmIdToSessionMap sessions_;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(CdmSessionMap);
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // WVCDM_CORE_CDM_SESSION_MAP_H_
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "metrics_collections.h"
|
||||
#include "oemcrypto_adapter.h"
|
||||
#include "scoped_ptr.h"
|
||||
#include "service_certificate.h"
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
namespace wvcdm {
|
||||
@@ -21,13 +22,13 @@ class ServiceCertificate;
|
||||
|
||||
class CertificateProvisioning {
|
||||
public:
|
||||
CertificateProvisioning(metrics::CryptoMetrics* metrics,
|
||||
ServiceCertificate* service_certificate) :
|
||||
CertificateProvisioning(metrics::CryptoMetrics* metrics) :
|
||||
crypto_session_(metrics),
|
||||
cert_type_(kCertificateWidevine),
|
||||
service_certificate_(service_certificate) {}
|
||||
service_certificate_(new ServiceCertificate()) {}
|
||||
~CertificateProvisioning() {}
|
||||
|
||||
~CertificateProvisioning() {};
|
||||
CdmResponseType Init(const std::string& service_certificate);
|
||||
|
||||
// Construct a valid provisioning request.
|
||||
// The request will be sent to the provisioning server.
|
||||
@@ -43,9 +44,6 @@ class CertificateProvisioning {
|
||||
std::string* cert, std::string* wrapped_key);
|
||||
|
||||
private:
|
||||
bool GetProvisioningTokenType(
|
||||
video_widevine::ClientIdentification::TokenType* token_type);
|
||||
|
||||
bool SetSpoidParameter(const std::string& origin, const std::string& spoid,
|
||||
video_widevine::ProvisioningRequest* request);
|
||||
|
||||
@@ -54,7 +52,7 @@ class CertificateProvisioning {
|
||||
|
||||
CryptoSession crypto_session_;
|
||||
CdmCertificateType cert_type_;
|
||||
ServiceCertificate* service_certificate_;
|
||||
scoped_ptr<ServiceCertificate> service_certificate_;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(CertificateProvisioning);
|
||||
};
|
||||
|
||||
57
libwvdrmengine/cdm/core/include/client_identification.h
Normal file
57
libwvdrmengine/cdm/core/include/client_identification.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2017 Google Inc. All Rights Reserved.
|
||||
|
||||
#ifndef WVCDM_CORE_CLIENT_IDENTIFICATION_H_
|
||||
#define WVCDM_CORE_CLIENT_IDENTIFICATION_H_
|
||||
|
||||
// ClientIdentification fills in the ClientIdentification portion
|
||||
// of the License or Provisioning request messages.
|
||||
|
||||
#include "license_protocol.pb.h"
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class CryptoSession;
|
||||
|
||||
class ClientIdentification {
|
||||
public:
|
||||
ClientIdentification() : is_license_request_(true) {}
|
||||
virtual ~ClientIdentification() {}
|
||||
|
||||
// Call this method when used with provisioning requests
|
||||
CdmResponseType Init(CryptoSession* crypto_session);
|
||||
|
||||
// Use in conjunction with license requests
|
||||
// |client_token| must be provided
|
||||
// |device_id| optional
|
||||
// |crypto_session| input parameter, mandatory
|
||||
CdmResponseType Init(const std::string& client_token,
|
||||
const std::string& device_id,
|
||||
CryptoSession* crypto_session);
|
||||
|
||||
// Fill the ClientIdentification portion of the license or provisioning
|
||||
// request
|
||||
// |app_parameters| parameters provided by client/app to be included in
|
||||
// provisioning/license request. optional, only used
|
||||
// if |is_license_request| is true
|
||||
// |client_id| Portion of license/provisioning request that needs to be
|
||||
// populated.
|
||||
virtual CdmResponseType Prepare(
|
||||
const CdmAppParameterMap& app_parameters,
|
||||
video_widevine::ClientIdentification* client_id);
|
||||
|
||||
private:
|
||||
bool GetProvisioningTokenType(
|
||||
video_widevine::ClientIdentification::TokenType* token_type);
|
||||
|
||||
bool is_license_request_;
|
||||
std::string client_token_;
|
||||
std::string device_id_;
|
||||
CryptoSession* crypto_session_;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(ClientIdentification);
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // WVCDM_CORE_CLIENT_IDENTIFICATION_H_
|
||||
@@ -77,9 +77,6 @@ class CdmLicense {
|
||||
CdmResponseType HandleKeyErrorResponse(
|
||||
const video_widevine::SignedMessage& signed_message);
|
||||
|
||||
bool GetClientTokenType(
|
||||
video_widevine::ClientIdentification::TokenType* token_type);
|
||||
|
||||
CdmResponseType PrepareClientId(
|
||||
const CdmAppParameterMap& app_parameters,
|
||||
video_widevine::LicenseRequest* license_request);
|
||||
|
||||
18
libwvdrmengine/cdm/core/include/override.h
Normal file
18
libwvdrmengine/cdm/core/include/override.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
// TODO: Import to core/, use everywhere.
|
||||
#ifndef WVCDM_CDM_OVERRIDE_H_
|
||||
#define WVCDM_CDM_OVERRIDE_H_
|
||||
|
||||
#define GCC_HAS_OVERRIDE ( \
|
||||
(__GNUC__ > 4) || \
|
||||
(__GNUC__ == 4 && __GNUC_MINOR__ >= 7) \
|
||||
)
|
||||
|
||||
#if !defined(DISABLE_OVERRIDE_KEYWORD) && \
|
||||
(defined(COMPILER_MSVC) || defined(__clang__) || GCC_HAS_OVERRIDE)
|
||||
#define OVERRIDE override
|
||||
#else
|
||||
#define OVERRIDE
|
||||
#endif
|
||||
|
||||
#endif // WVCDM_CDM_OVERRIDE_H_
|
||||
@@ -46,9 +46,6 @@ class Properties {
|
||||
static void set_provisioning_messages_are_binary(bool flag) {
|
||||
provisioning_messages_are_binary_ = flag;
|
||||
}
|
||||
static inline bool security_level_path_backward_compatibility_support() {
|
||||
return security_level_path_backward_compatibility_support_;
|
||||
}
|
||||
static bool GetCompanyName(std::string* company_name);
|
||||
static bool GetModelName(std::string* model_name);
|
||||
static bool GetArchitectureName(std::string* arch_name);
|
||||
@@ -96,10 +93,6 @@ class Properties {
|
||||
static void set_use_certificates_as_identification(bool flag) {
|
||||
use_certificates_as_identification_ = flag;
|
||||
}
|
||||
static void set_security_level_path_backward_compatibility_support(
|
||||
bool flag) {
|
||||
security_level_path_backward_compatibility_support_ = flag;
|
||||
}
|
||||
|
||||
#if defined(UNIT_TEST)
|
||||
FRIEND_TEST(CdmSessionTest, InitWithBuiltInCertificate);
|
||||
@@ -117,7 +110,6 @@ class Properties {
|
||||
static bool oem_crypto_use_fifo_;
|
||||
static bool oem_crypto_use_userspace_buffers_;
|
||||
static bool use_certificates_as_identification_;
|
||||
static bool security_level_path_backward_compatibility_support_;
|
||||
static bool provisioning_messages_are_binary_;
|
||||
static bool allow_service_certificate_requests_;
|
||||
static scoped_ptr<CdmClientPropertySetMap> session_property_set_;
|
||||
|
||||
222
libwvdrmengine/cdm/core/include/shared_ptr.h
Normal file
222
libwvdrmengine/cdm/core/include/shared_ptr.h
Normal file
@@ -0,0 +1,222 @@
|
||||
// Copyright 2017 Google Inc. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// from google3/util/gtl/shared_ptr.h
|
||||
// from protobuf/src/google/protobuf/stubs/shared_ptr.h
|
||||
|
||||
#ifndef WVCDM_CORE_SHARED_PTR_H__
|
||||
#define WVCDM_CORE_SHARED_PTR_H__
|
||||
|
||||
#include <algorithm> // for swap
|
||||
#include <stddef.h>
|
||||
#include <memory>
|
||||
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
namespace {
|
||||
bool Barrier_AtomicIncrement(volatile uint32_t* ptr, uint32_t value) {
|
||||
*ptr += value;
|
||||
return *ptr;
|
||||
}
|
||||
bool NoBarrier_AtomicIncrement(volatile uint32_t* ptr, uint32_t value) {
|
||||
*ptr += value;
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
inline bool RefCountDec(volatile uint32_t *ptr) {
|
||||
return Barrier_AtomicIncrement(ptr, -1) != 0;
|
||||
}
|
||||
|
||||
inline void RefCountInc(volatile uint32_t *ptr) {
|
||||
NoBarrier_AtomicIncrement(ptr, 1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
template <typename T> class shared_ptr;
|
||||
|
||||
// This class is an internal implementation detail for shared_ptr. If two
|
||||
// shared_ptrs point to the same object, they also share a control block.
|
||||
// An "empty" shared_pointer refers to NULL and also has a NULL control block.
|
||||
// It contains all of the state that's needed for reference counting or any
|
||||
// other kind of resource management. In this implementation the control block
|
||||
// consists of a single reference count (the number of shared_ptrs that
|
||||
// share ownership of the object).
|
||||
class SharedPtrControlBlock {
|
||||
template <typename T> friend class shared_ptr;
|
||||
private:
|
||||
SharedPtrControlBlock() : refcount_(1) {}
|
||||
uint32_t refcount_;
|
||||
};
|
||||
|
||||
// Forward declaration. The class is defined below.
|
||||
template <typename T> class enable_shared_from_this;
|
||||
|
||||
template <typename T>
|
||||
class shared_ptr {
|
||||
public:
|
||||
typedef T element_type;
|
||||
|
||||
shared_ptr() : ptr_(NULL), control_block_(NULL) {}
|
||||
|
||||
explicit shared_ptr(T* ptr)
|
||||
: ptr_(ptr),
|
||||
control_block_(ptr != NULL ? new SharedPtrControlBlock : NULL) {
|
||||
}
|
||||
|
||||
// Copy constructor: makes this object a copy of ptr, and increments
|
||||
// the reference count.
|
||||
template <typename U>
|
||||
shared_ptr(const shared_ptr<U>& ptr)
|
||||
: ptr_(NULL),
|
||||
control_block_(NULL) {
|
||||
Initialize(ptr);
|
||||
}
|
||||
// Need non-templated version to prevent the compiler-generated default
|
||||
shared_ptr(const shared_ptr<T>& ptr)
|
||||
: ptr_(NULL),
|
||||
control_block_(NULL) {
|
||||
Initialize(ptr);
|
||||
}
|
||||
|
||||
// Assignment operator. Replaces the existing shared_ptr with ptr.
|
||||
// Increment ptr's reference count and decrement the one being replaced.
|
||||
template <typename U>
|
||||
shared_ptr<T>& operator=(const shared_ptr<U>& ptr) {
|
||||
if (ptr_ != ptr.ptr_) {
|
||||
shared_ptr<T> me(ptr); // will hold our previous state to be destroyed.
|
||||
swap(me);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Need non-templated version to prevent the compiler-generated default
|
||||
shared_ptr<T>& operator=(const shared_ptr<T>& ptr) {
|
||||
if (ptr_ != ptr.ptr_) {
|
||||
shared_ptr<T> me(ptr); // will hold our previous state to be destroyed.
|
||||
swap(me);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~shared_ptr() {
|
||||
if (ptr_ != NULL) {
|
||||
if (!RefCountDec(&control_block_->refcount_)) {
|
||||
delete ptr_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Replaces underlying raw pointer with the one passed in. The reference
|
||||
// count is set to one (or zero if the pointer is NULL) for the pointer
|
||||
// being passed in and decremented for the one being replaced.
|
||||
//
|
||||
// If you have a compilation error with this code, make sure you aren't
|
||||
// passing NULL, nullptr, or 0 to this function. Call reset without an
|
||||
// argument to reset to a null ptr.
|
||||
template <typename Y>
|
||||
void reset(Y* p) {
|
||||
if (p != ptr_) {
|
||||
shared_ptr<T> tmp(p);
|
||||
tmp.swap(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
reset(static_cast<T*>(NULL));
|
||||
}
|
||||
|
||||
// Exchanges the contents of this with the contents of r. This function
|
||||
// supports more efficient swapping since it eliminates the need for a
|
||||
// temporary shared_ptr object.
|
||||
void swap(shared_ptr<T>& r) {
|
||||
using std::swap; // http://go/using-std-swap
|
||||
swap(ptr_, r.ptr_);
|
||||
swap(control_block_, r.control_block_);
|
||||
}
|
||||
|
||||
// The following function is useful for gaining access to the underlying
|
||||
// pointer when a shared_ptr remains in scope so the reference-count is
|
||||
// known to be > 0 (e.g. for parameter passing).
|
||||
T* get() const {
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
T& operator*() const {
|
||||
return *ptr_;
|
||||
}
|
||||
|
||||
T* operator->() const {
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
long use_count() const {
|
||||
return control_block_ ? control_block_->refcount_ : 1;
|
||||
}
|
||||
|
||||
bool unique() const {
|
||||
return use_count() == 1;
|
||||
}
|
||||
|
||||
private:
|
||||
// If r is non-empty, initialize *this to share ownership with r,
|
||||
// increasing the underlying reference count.
|
||||
// If r is empty, *this remains empty.
|
||||
// Requires: this is empty, namely this->ptr_ == NULL.
|
||||
template <typename U>
|
||||
void Initialize(const shared_ptr<U>& r) {
|
||||
// This performs a static_cast on r.ptr_ to U*, which is a no-op since it
|
||||
// is already a U*. So initialization here requires that r.ptr_ is
|
||||
// implicitly convertible to T*.
|
||||
InitializeWithStaticCast<U>(r);
|
||||
}
|
||||
|
||||
// Initializes *this as described in Initialize, but additionally performs a
|
||||
// static_cast from r.ptr_ (V*) to U*.
|
||||
// NOTE(gfc): We'd need a more general form to support const_pointer_cast and
|
||||
// dynamic_pointer_cast, but those operations are sufficiently discouraged
|
||||
// that supporting static_pointer_cast is sufficient.
|
||||
template <typename U, typename V>
|
||||
void InitializeWithStaticCast(const shared_ptr<V>& r) {
|
||||
if (r.control_block_ != NULL) {
|
||||
RefCountInc(&r.control_block_->refcount_);
|
||||
|
||||
ptr_ = static_cast<U*>(r.ptr_);
|
||||
control_block_ = r.control_block_;
|
||||
}
|
||||
}
|
||||
|
||||
T* ptr_;
|
||||
SharedPtrControlBlock* control_block_;
|
||||
};
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // WVCDM_CORE_SHARED_PTR_H__
|
||||
@@ -64,11 +64,11 @@ enum CdmResponseType {
|
||||
CERT_PROVISIONING_RESPONSE_ERROR_6 = 23,
|
||||
CERT_PROVISIONING_RESPONSE_ERROR_7 = 24,
|
||||
CERT_PROVISIONING_RESPONSE_ERROR_8 = 25,
|
||||
CRYPTO_SESSION_OPEN_ERROR_1 = 26,
|
||||
CRYPTO_SESSION_OPEN_ERROR_2 = 27,
|
||||
CRYPTO_SESSION_OPEN_ERROR_3 = 28,
|
||||
CRYPTO_SESSION_OPEN_ERROR_4 = 29,
|
||||
CRYPTO_SESSION_OPEN_ERROR_5 = 30,
|
||||
/* previously CRYPTO_SESSION_OPEN_ERROR_1 = 26 */
|
||||
/* previously CRYPTO_SESSION_OPEN_ERROR_2 = 27 */
|
||||
/* previously CRYPTO_SESSION_OPEN_ERROR_3 = 28 */
|
||||
/* previously CRYPTO_SESSION_OPEN_ERROR_4 = 29 */
|
||||
/* previously CRYPTO_SESSION_OPEN_ERROR_5 = 30 */
|
||||
DECRYPT_NOT_READY = 31,
|
||||
DEVICE_CERTIFICATE_ERROR_1 = 32,
|
||||
DEVICE_CERTIFICATE_ERROR_2 = 33,
|
||||
@@ -97,11 +97,11 @@ enum CdmResponseType {
|
||||
GET_USAGE_INFO_ERROR_3 = 56,
|
||||
GET_USAGE_INFO_ERROR_4 = 57,
|
||||
INIT_DATA_NOT_FOUND = 58,
|
||||
INVALID_CRYPTO_SESSION_1 = 59,
|
||||
INVALID_CRYPTO_SESSION_2 = 60,
|
||||
INVALID_CRYPTO_SESSION_3 = 61,
|
||||
INVALID_CRYPTO_SESSION_4 = 62,
|
||||
INVALID_CRYPTO_SESSION_5 = 63,
|
||||
/* previously INVALID_CRYPTO_SESSION_1 = 59 */
|
||||
/* previously INVALID_CRYPTO_SESSION_2 = 60 */
|
||||
/* previously INVALID_CRYPTO_SESSION_3 = 61 */
|
||||
/* previously INVALID_CRYPTO_SESSION_4 = 62 */
|
||||
/* previously INVALID_CRYPTO_SESSION_5 = 63 */
|
||||
INVALID_DECRYPT_PARAMETERS_ENG_1 = 64,
|
||||
INVALID_DECRYPT_PARAMETERS_ENG_2 = 65,
|
||||
INVALID_DECRYPT_PARAMETERS_ENG_3 = 66,
|
||||
@@ -110,10 +110,10 @@ enum CdmResponseType {
|
||||
INVALID_KEY_SYSTEM = 69,
|
||||
INVALID_LICENSE_RESPONSE = 70,
|
||||
INVALID_LICENSE_TYPE = 71,
|
||||
INVALID_PARAMETERS_ENG_1 = 72,
|
||||
INVALID_PARAMETERS_ENG_2 = 73,
|
||||
INVALID_PARAMETERS_ENG_3 = 74,
|
||||
INVALID_PARAMETERS_ENG_4 = 75,
|
||||
PARAMETER_NULL = 72, /* prior to pi, INVALID_PARAMETERS_ENG_1 = 72 */
|
||||
/* previously INVALID_PARAMETERS_ENG_2 = 73 */
|
||||
/* previously INVALID_PARAMETERS_ENG_3 = 74 */
|
||||
/* previously INVALID_PARAMETERS_ENG_4 = 75 */
|
||||
INVALID_PARAMETERS_LIC_1 = 76,
|
||||
INVALID_PARAMETERS_LIC_2 = 77,
|
||||
INVALID_PROVISIONING_PARAMETERS_1 = 78,
|
||||
@@ -152,8 +152,8 @@ enum CdmResponseType {
|
||||
LICENSE_RENEWAL_SIGNING_ERROR = 111,
|
||||
/* previously RESTORE_OFFLINE_LICENSE_ERROR_1 = 112 */
|
||||
RESTORE_OFFLINE_LICENSE_ERROR_2 = 113,
|
||||
SESSION_INIT_ERROR_1 = 114,
|
||||
SESSION_INIT_ERROR_2 = 115,
|
||||
NOT_INITIALIZED_ERROR = 114, /* prior to pi, SESSION_INIT_ERROR_1 = 114 */
|
||||
REINIT_ERROR = 115, /* prior to pi, SESSION_INIT_ERROR_2 = 115 */
|
||||
/* previously SESSION_INIT_GET_KEYBOX_ERROR = 116 */
|
||||
SESSION_NOT_FOUND_1 = 117,
|
||||
SESSION_NOT_FOUND_2 = 118,
|
||||
@@ -223,13 +223,13 @@ enum CdmResponseType {
|
||||
KEY_NOT_FOUND_1 = 181,
|
||||
KEY_NOT_FOUND_2 = 182,
|
||||
KEY_CONFLICT_1 = 183,
|
||||
INVALID_PARAMETERS_ENG_6 = 184,
|
||||
INVALID_PARAMETERS_ENG_7 = 185,
|
||||
INVALID_PARAMETERS_ENG_8 = 186,
|
||||
INVALID_PARAMETERS_ENG_9 = 187,
|
||||
INVALID_PARAMETERS_ENG_10 = 188,
|
||||
INVALID_PARAMETERS_ENG_11 = 189,
|
||||
INVALID_PARAMETERS_ENG_12 = 190,
|
||||
/* previously INVALID_PARAMETERS_ENG_6 = 184 */
|
||||
/* previously INVALID_PARAMETERS_ENG_7 = 185 */
|
||||
/* previously INVALID_PARAMETERS_ENG_8 = 186 */
|
||||
/* previously INVALID_PARAMETERS_ENG_9 = 187 */
|
||||
/* previously INVALID_PARAMETERS_ENG_10 = 188 */
|
||||
/* previously INVALID_PARAMETERS_ENG_11 = 189 */
|
||||
/* previously INVALID_PARAMETERS_ENG_12 = 190 */
|
||||
SESSION_NOT_FOUND_13 = 191,
|
||||
SESSION_NOT_FOUND_14 = 192,
|
||||
SESSION_NOT_FOUND_15 = 193,
|
||||
@@ -247,9 +247,9 @@ enum CdmResponseType {
|
||||
INVALID_PARAMETERS_ENG_15 = 205,
|
||||
INVALID_PARAMETERS_ENG_16 = 206,
|
||||
/* previously DEVICE_CERTIFICATE_ERROR_5 = 207 */
|
||||
CERT_PROVISIONING_CLIENT_TOKEN_ERROR_1 = 208,
|
||||
CERT_PROVISIONING_CLIENT_TOKEN_ERROR_2 = 209,
|
||||
LICENSING_CLIENT_TOKEN_ERROR_1 = 210,
|
||||
CLIENT_IDENTIFICATION_TOKEN_ERROR_1 = 208,
|
||||
CLIENT_IDENTIFICATION_TOKEN_ERROR_2 = 209,
|
||||
/* previously LICENSING_CLIENT_TOKEN_ERROR_1 = 210 */
|
||||
ANALOG_OUTPUT_ERROR = 211,
|
||||
UNKNOWN_SELECT_KEY_ERROR_1 = 212,
|
||||
UNKNOWN_SELECT_KEY_ERROR_2 = 213,
|
||||
@@ -317,6 +317,7 @@ enum CdmResponseType {
|
||||
RELEASE_ALL_USAGE_INFO_ERROR_6 = 275,
|
||||
RELEASE_ALL_USAGE_INFO_ERROR_7 = 276,
|
||||
LICENSE_REQUEST_INVALID_SUBLICENSE = 277,
|
||||
CERT_PROVISIONING_EMPTY_SERVICE_CERTIFICATE = 278,
|
||||
};
|
||||
|
||||
enum CdmKeyStatus {
|
||||
|
||||
Reference in New Issue
Block a user