Do not reference internal header files within wv_cas_ecm.h
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=218363187
This commit is contained in:
@@ -32,15 +32,24 @@ namespace {
|
|||||||
static constexpr size_t kCryptoModeCbc = 0;
|
static constexpr size_t kCryptoModeCbc = 0;
|
||||||
static constexpr size_t kCryptoModeCtr = 1;
|
static constexpr size_t kCryptoModeCtr = 1;
|
||||||
|
|
||||||
int EcmIvSizeToInt(EcmIvSize iv_size) {
|
EcmInitParameters CreateEcmInitParameters(int content_iv_size,
|
||||||
if (iv_size == kIvSize8) {
|
bool key_rotation_enabled,
|
||||||
return 8;
|
int crypto_mode) {
|
||||||
} else if (iv_size == kIvSize16) {
|
EcmInitParameters params;
|
||||||
return 16;
|
if (content_iv_size == 8) {
|
||||||
|
params.content_iv_size = kIvSize8;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
params.content_iv_size = kIvSize16;
|
||||||
}
|
}
|
||||||
|
params.key_rotation_enabled = key_rotation_enabled;
|
||||||
|
params.crypto_mode = CasCryptoMode::CTR;
|
||||||
|
// Internal ECM class can hold entitlement keys for multiple tracks.
|
||||||
|
// So we need to set a default track type here to be associated with
|
||||||
|
// the entitlement keys set later.
|
||||||
|
params.track_types.push_back(kDefaultTrackTypeSd);
|
||||||
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
util::Status WvCasEcm::Initialize(int content_iv_size,
|
util::Status WvCasEcm::Initialize(int content_iv_size,
|
||||||
@@ -50,25 +59,18 @@ util::Status WvCasEcm::Initialize(int content_iv_size,
|
|||||||
util::error::INTERNAL,
|
util::error::INTERNAL,
|
||||||
"Cannot initialize an instance of WvCasEcm more than once");
|
"Cannot initialize an instance of WvCasEcm more than once");
|
||||||
}
|
}
|
||||||
if (content_iv_size == 8) {
|
if (content_iv_size != 8 && content_iv_size != 16) {
|
||||||
ecm_init_params_.content_iv_size = kIvSize8;
|
|
||||||
} else if (content_iv_size == 16) {
|
|
||||||
ecm_init_params_.content_iv_size = kIvSize16;
|
|
||||||
} else {
|
|
||||||
return util::Status(util::error::INVALID_ARGUMENT,
|
return util::Status(util::error::INVALID_ARGUMENT,
|
||||||
"Only support content_iv_size being 8 now");
|
"Only support content_iv_size being 8 now");
|
||||||
}
|
}
|
||||||
ecm_init_params_.key_rotation_enabled = key_rotation_enabled;
|
content_iv_size_ = content_iv_size;
|
||||||
|
key_rotation_enabled_ = key_rotation_enabled;
|
||||||
if (crypto_mode != kCryptoModeCtr) {
|
if (crypto_mode != kCryptoModeCtr) {
|
||||||
return util::Status(util::error::INVALID_ARGUMENT,
|
return util::Status(util::error::INVALID_ARGUMENT,
|
||||||
"Only CTR crypto mode is supported by Widevine plugin "
|
"Only CTR crypto mode is supported by Widevine plugin "
|
||||||
"for content encryption");
|
"for content encryption");
|
||||||
}
|
}
|
||||||
ecm_init_params_.crypto_mode = CasCryptoMode::CTR;
|
crypto_mode_ = crypto_mode;
|
||||||
// Internal ECM class can hold entitlement keys for multiple tracks.
|
|
||||||
// So we need to set a default track type here to be associated with
|
|
||||||
// the entitlement keys set later.
|
|
||||||
ecm_init_params_.track_types.push_back(kDefaultTrackTypeSd);
|
|
||||||
|
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
|
|
||||||
@@ -87,15 +89,13 @@ util::Status WvCasEcm::GenerateEcm(const std::string& even_key,
|
|||||||
return util::Status(util::error::INTERNAL,
|
return util::Status(util::error::INTERNAL,
|
||||||
"WvCasEcm has not been properly initialized");
|
"WvCasEcm has not been properly initialized");
|
||||||
}
|
}
|
||||||
if (!ecm_init_params_.key_rotation_enabled) {
|
if (!key_rotation_enabled_) {
|
||||||
return util::Status(util::error::INTERNAL,
|
return util::Status(util::error::INTERNAL,
|
||||||
"Please call GenerateSingleKeyEcm() instead when key "
|
"Please call GenerateSingleKeyEcm() instead when key "
|
||||||
"rotation is disabled");
|
"rotation is disabled");
|
||||||
}
|
}
|
||||||
if (even_content_iv.size() !=
|
if (even_content_iv.size() != content_iv_size_ ||
|
||||||
EcmIvSizeToInt(ecm_init_params_.content_iv_size) ||
|
odd_content_iv.size() != content_iv_size_) {
|
||||||
odd_content_iv.size() !=
|
|
||||||
EcmIvSizeToInt(ecm_init_params_.content_iv_size)) {
|
|
||||||
return util::Status(util::error::INVALID_ARGUMENT,
|
return util::Status(util::error::INVALID_ARGUMENT,
|
||||||
"Size of content IV is incorrect");
|
"Size of content IV is incorrect");
|
||||||
}
|
}
|
||||||
@@ -104,6 +104,8 @@ util::Status WvCasEcm::GenerateEcm(const std::string& even_key,
|
|||||||
std::unique_ptr<CasEcm> cas_ecm = absl::make_unique<CasEcm>();
|
std::unique_ptr<CasEcm> cas_ecm = absl::make_unique<CasEcm>();
|
||||||
std::string entitlement_request;
|
std::string entitlement_request;
|
||||||
std::string entitlement_response;
|
std::string entitlement_response;
|
||||||
|
EcmInitParameters ecm_init_params = CreateEcmInitParameters(
|
||||||
|
content_iv_size_, key_rotation_enabled_, crypto_mode_);
|
||||||
// 'content_id' and 'provider' are used in entitlement key request/response
|
// 'content_id' and 'provider' are used in entitlement key request/response
|
||||||
// only, NOT needed for constructing the ECM. So we just use hardcoded value
|
// only, NOT needed for constructing the ECM. So we just use hardcoded value
|
||||||
// here for now.
|
// here for now.
|
||||||
@@ -112,7 +114,7 @@ util::Status WvCasEcm::GenerateEcm(const std::string& even_key,
|
|||||||
// to this function here.
|
// to this function here.
|
||||||
util::Status status;
|
util::Status status;
|
||||||
if (!(status = cas_ecm->Initialize(kDefaultContentId, kDefaultProvider,
|
if (!(status = cas_ecm->Initialize(kDefaultContentId, kDefaultProvider,
|
||||||
ecm_init_params_, &entitlement_request))
|
ecm_init_params, &entitlement_request))
|
||||||
.ok()) {
|
.ok()) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -135,7 +137,7 @@ util::Status WvCasEcm::GenerateEcm(const std::string& even_key,
|
|||||||
CasEcmGenerator ecm_generator;
|
CasEcmGenerator ecm_generator;
|
||||||
ecm_generator.set_ecm(std::move(cas_ecm));
|
ecm_generator.set_ecm(std::move(cas_ecm));
|
||||||
EcmParameters ecm_param;
|
EcmParameters ecm_param;
|
||||||
ecm_param.rotation_enabled = ecm_init_params_.key_rotation_enabled;
|
ecm_param.rotation_enabled = key_rotation_enabled_;
|
||||||
// Add even entitlement key.
|
// Add even entitlement key.
|
||||||
ecm_param.key_params.emplace_back();
|
ecm_param.key_params.emplace_back();
|
||||||
ecm_param.key_params[0].key_data = even_key;
|
ecm_param.key_params[0].key_data = even_key;
|
||||||
@@ -163,13 +165,12 @@ util::Status WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
|
|||||||
return util::Status(util::error::INTERNAL,
|
return util::Status(util::error::INTERNAL,
|
||||||
"WvCasEcm has not been properly initialized");
|
"WvCasEcm has not been properly initialized");
|
||||||
}
|
}
|
||||||
if (ecm_init_params_.key_rotation_enabled) {
|
if (key_rotation_enabled_) {
|
||||||
return util::Status(
|
return util::Status(
|
||||||
util::error::INTERNAL,
|
util::error::INTERNAL,
|
||||||
"Please call GenerateEcm() instead when key rotation is enabled");
|
"Please call GenerateEcm() instead when key rotation is enabled");
|
||||||
}
|
}
|
||||||
if (even_content_iv.size() !=
|
if (even_content_iv.size() != content_iv_size_) {
|
||||||
EcmIvSizeToInt(ecm_init_params_.content_iv_size)) {
|
|
||||||
return util::Status(util::error::INVALID_ARGUMENT,
|
return util::Status(util::error::INVALID_ARGUMENT,
|
||||||
"Size of content IV is incorrect");
|
"Size of content IV is incorrect");
|
||||||
}
|
}
|
||||||
@@ -178,6 +179,8 @@ util::Status WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
|
|||||||
std::unique_ptr<CasEcm> cas_ecm = absl::make_unique<CasEcm>();
|
std::unique_ptr<CasEcm> cas_ecm = absl::make_unique<CasEcm>();
|
||||||
std::string entitlement_request;
|
std::string entitlement_request;
|
||||||
std::string entitlement_response;
|
std::string entitlement_response;
|
||||||
|
EcmInitParameters ecm_init_params = CreateEcmInitParameters(
|
||||||
|
content_iv_size_, key_rotation_enabled_, crypto_mode_);
|
||||||
// 'content_id' and 'provider' are used in entitlement key request/response
|
// 'content_id' and 'provider' are used in entitlement key request/response
|
||||||
// only, NOT needed for constructing the ECM. So we just use hardcoded value
|
// only, NOT needed for constructing the ECM. So we just use hardcoded value
|
||||||
// here for now.
|
// here for now.
|
||||||
@@ -186,7 +189,7 @@ util::Status WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
|
|||||||
// to this function here.
|
// to this function here.
|
||||||
util::Status status;
|
util::Status status;
|
||||||
if (!(status = cas_ecm->Initialize(kDefaultContentId, kDefaultProvider,
|
if (!(status = cas_ecm->Initialize(kDefaultContentId, kDefaultProvider,
|
||||||
ecm_init_params_, &entitlement_request))
|
ecm_init_params, &entitlement_request))
|
||||||
.ok()) {
|
.ok()) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -209,7 +212,7 @@ util::Status WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
|
|||||||
CasEcmGenerator ecm_generator;
|
CasEcmGenerator ecm_generator;
|
||||||
ecm_generator.set_ecm(std::move(cas_ecm));
|
ecm_generator.set_ecm(std::move(cas_ecm));
|
||||||
EcmParameters ecm_param;
|
EcmParameters ecm_param;
|
||||||
ecm_param.rotation_enabled = ecm_init_params_.key_rotation_enabled;
|
ecm_param.rotation_enabled = key_rotation_enabled_;
|
||||||
// Add even entitlement key.
|
// Add even entitlement key.
|
||||||
ecm_param.key_params.emplace_back();
|
ecm_param.key_params.emplace_back();
|
||||||
ecm_param.key_params[0].key_data = even_key;
|
ecm_param.key_params[0].key_data = even_key;
|
||||||
|
|||||||
@@ -17,9 +17,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "util/status.h"
|
#include "util/status.h"
|
||||||
#include "media_cas_packager_sdk/internal/ecm.h"
|
|
||||||
#include "media_cas_packager_sdk/internal/ecm_generator.h"
|
|
||||||
#include "protos/public/media_cas.pb.h"
|
|
||||||
|
|
||||||
namespace widevine {
|
namespace widevine {
|
||||||
namespace cas {
|
namespace cas {
|
||||||
@@ -106,7 +103,9 @@ class WvCasEcm {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
EcmInitParameters ecm_init_params_;
|
int content_iv_size_;
|
||||||
|
bool key_rotation_enabled_;
|
||||||
|
int crypto_mode_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cas
|
} // namespace cas
|
||||||
|
|||||||
Reference in New Issue
Block a user