(1) Return a boolean instead of util::Status for methods in wv_cas_ecm.h
(2) Update wv_cas_ecm_example to NOT depend on ABSL ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=218884631
This commit is contained in:
@@ -48,8 +48,6 @@ cc_binary(
|
|||||||
srcs = ["wv_cas_ecm_example.cc"],
|
srcs = ["wv_cas_ecm_example.cc"],
|
||||||
deps = [
|
deps = [
|
||||||
"//base",
|
"//base",
|
||||||
"@abseil_repo//absl/strings",
|
|
||||||
"//util:status",
|
|
||||||
"//media_cas_packager_sdk/public:wv_cas_ecm",
|
"//media_cas_packager_sdk/public:wv_cas_ecm",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,47 +8,43 @@
|
|||||||
|
|
||||||
// Example of how to use the wv_cas_ecm library.
|
// Example of how to use the wv_cas_ecm library.
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gflags/gflags.h"
|
|
||||||
#include "glog/logging.h"
|
|
||||||
#include "absl/strings/escaping.h"
|
|
||||||
#include "absl/strings/str_cat.h"
|
|
||||||
#include "util/status.h"
|
|
||||||
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
||||||
|
|
||||||
|
const int kContentIvSize = 16;
|
||||||
|
const bool kKeyRotationEnabled = true;
|
||||||
|
const int kCryptoMode = 1; // CTR
|
||||||
const char kEvenKey[] = "even_content_key"; // 16 bytes
|
const char kEvenKey[] = "even_content_key"; // 16 bytes
|
||||||
const char kEvenContentIv8Bytes[] = "evencont"; // 8 bytes
|
const char kEvenContentIv8Bytes[] = "evencont"; // 8 bytes
|
||||||
|
const char kEvenContentIv16Bytes[] = "evencontevencont"; // 16 bytes
|
||||||
const char kOddKey[] = "odd_content_key."; // 16 bytes
|
const char kOddKey[] = "odd_content_key."; // 16 bytes
|
||||||
const char kOddContentIv8Bytes[] = "oddcont."; // 8 bytes
|
const char kOddContentIv8Bytes[] = "oddcont."; // 8 bytes
|
||||||
|
const char kOddContentIv16Bytes[] = "oddcont.oddcont."; // 16 bytes
|
||||||
const char kEntitlementKeyId[] = "ent_key_id......"; // 16 bytes
|
const char kEntitlementKeyId[] = "ent_key_id......"; // 16 bytes
|
||||||
const char kEntitlementKey[] = "entitlement_key................."; // 32 bytes
|
const char kEntitlementKey[] = "entitlement_key................."; // 32 bytes
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
||||||
|
|
||||||
widevine::cas::WvCasEcm wv_cas_ecm;
|
widevine::cas::WvCasEcm wv_cas_ecm;
|
||||||
auto status = wv_cas_ecm.Initialize(/* content_iv_size= */ 16,
|
bool status =
|
||||||
/* key_rotation_enabled= */ true,
|
wv_cas_ecm.Initialize(kContentIvSize, kKeyRotationEnabled, kCryptoMode);
|
||||||
/* crypto_mode= */ 1);
|
if (!status) {
|
||||||
if (!status.ok()) {
|
std::cerr << "Failed to initialize WV CAS ECM, error." << std::endl;
|
||||||
LOG(FATAL) << "Failed to initialize WV CAS ECM, error: " << status;
|
|
||||||
}
|
}
|
||||||
std::string ecm;
|
std::string ecm;
|
||||||
status = wv_cas_ecm.GenerateEcm(
|
status = wv_cas_ecm.GenerateEcm(kEvenKey, kEvenContentIv16Bytes, kOddKey,
|
||||||
/* even_key= */ kEvenKey,
|
kOddContentIv16Bytes, kEntitlementKeyId,
|
||||||
/* even_content_iv= */
|
kEntitlementKey, &ecm);
|
||||||
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
|
if (!status) {
|
||||||
/* odd_key= */ kOddKey,
|
std::cerr << "Failed to generate WV CAS ECM, error" << std::endl;
|
||||||
/* odd_content_iv= */
|
|
||||||
absl::StrCat(kOddContentIv8Bytes, kOddContentIv8Bytes),
|
|
||||||
/* entitlement_key_id= */ kEntitlementKeyId,
|
|
||||||
/* entitlement_key= */ kEntitlementKey, &ecm);
|
|
||||||
if (!status.ok()) {
|
|
||||||
LOG(FATAL) << "Failed to generate WV CAS ECM, error: " << status;
|
|
||||||
} else {
|
} else {
|
||||||
LOG(INFO) << "Generated WV CAS ECM (in hex): "
|
std::cout << "ECM size: " << ecm.size() << std::endl;
|
||||||
<< absl::BytesToHexString(ecm);
|
std::cout << "ECM bytes: ";
|
||||||
|
for (size_t i = 0; i < ecm.size(); i++) {
|
||||||
|
printf("'\\x%x', ", static_cast<uint16_t>(ecm.at(i)));
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -52,53 +52,52 @@ EcmInitParameters CreateEcmInitParameters(int content_iv_size,
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
util::Status WvCasEcm::Initialize(int content_iv_size,
|
// TODO(user): Return a status class like
|
||||||
bool key_rotation_enabled, int crypto_mode) {
|
// instead of boolean.
|
||||||
|
|
||||||
|
bool WvCasEcm::Initialize(int content_iv_size, bool key_rotation_enabled,
|
||||||
|
int crypto_mode) {
|
||||||
if (initialized_) {
|
if (initialized_) {
|
||||||
return util::Status(
|
LOG(ERROR) << "Cannot initialize an instance of WvCasEcm more than once";
|
||||||
util::error::INTERNAL,
|
return false;
|
||||||
"Cannot initialize an instance of WvCasEcm more than once");
|
|
||||||
}
|
}
|
||||||
if (content_iv_size != 8 && content_iv_size != 16) {
|
if (content_iv_size != 8 && content_iv_size != 16) {
|
||||||
return util::Status(util::error::INVALID_ARGUMENT,
|
LOG(ERROR) << "Only support content_iv_size being 8 now";
|
||||||
"Only support content_iv_size being 8 now");
|
return false;
|
||||||
}
|
}
|
||||||
content_iv_size_ = content_iv_size;
|
content_iv_size_ = content_iv_size;
|
||||||
key_rotation_enabled_ = key_rotation_enabled;
|
key_rotation_enabled_ = key_rotation_enabled;
|
||||||
if (crypto_mode != kCryptoModeCtr) {
|
if (crypto_mode != kCryptoModeCtr) {
|
||||||
return util::Status(util::error::INVALID_ARGUMENT,
|
LOG(ERROR) << "Only CTR crypto mode is supported by Widevine plugin for "
|
||||||
"Only CTR crypto mode is supported by Widevine plugin "
|
"content encryption";
|
||||||
"for content encryption");
|
return false;
|
||||||
}
|
}
|
||||||
crypto_mode_ = crypto_mode;
|
crypto_mode_ = crypto_mode;
|
||||||
|
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
|
|
||||||
return util::OkStatus();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
util::Status WvCasEcm::GenerateEcm(const std::string& even_key,
|
bool WvCasEcm::GenerateEcm(const std::string& even_key,
|
||||||
|
const std::string& even_content_iv, const std::string& odd_key,
|
||||||
const std::string& even_content_iv,
|
const std::string& odd_content_iv,
|
||||||
const std::string& odd_key,
|
const std::string& entitlement_key_id,
|
||||||
const std::string& odd_content_iv,
|
const std::string& entitlement_key, std::string* ecm) const {
|
||||||
const std::string& entitlement_key_id,
|
|
||||||
const std::string& entitlement_key,
|
|
||||||
std::string* ecm) const {
|
|
||||||
DCHECK(ecm);
|
DCHECK(ecm);
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
return util::Status(util::error::INTERNAL,
|
LOG(ERROR) << "WvCasEcm has not been properly initialized";
|
||||||
"WvCasEcm has not been properly initialized");
|
return false;
|
||||||
}
|
}
|
||||||
if (!key_rotation_enabled_) {
|
if (!key_rotation_enabled_) {
|
||||||
return util::Status(util::error::INTERNAL,
|
LOG(ERROR) << "Please call GenerateSingleKeyEcm() instead when key "
|
||||||
"Please call GenerateSingleKeyEcm() instead when key "
|
"rotation is disabled";
|
||||||
"rotation is disabled");
|
return false;
|
||||||
}
|
}
|
||||||
if (even_content_iv.size() != content_iv_size_ ||
|
if (even_content_iv.size() != content_iv_size_ ||
|
||||||
odd_content_iv.size() != content_iv_size_) {
|
odd_content_iv.size() != content_iv_size_) {
|
||||||
return util::Status(util::error::INVALID_ARGUMENT,
|
LOG(ERROR) << "Size of content IV is incorrect";
|
||||||
"Size of content IV is incorrect");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an instance of CasEcm in order to set the entitlement keys.
|
// Create an instance of CasEcm in order to set the entitlement keys.
|
||||||
@@ -117,7 +116,8 @@ util::Status WvCasEcm::GenerateEcm(const std::string& even_key,
|
|||||||
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;
|
LOG(ERROR) << "Failed to initialize ECM class.";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
FixedKeyFetcher fixed_key_fetcher(
|
FixedKeyFetcher fixed_key_fetcher(
|
||||||
/* even_entitlement_key_id= */ entitlement_key_id,
|
/* even_entitlement_key_id= */ entitlement_key_id,
|
||||||
@@ -127,11 +127,13 @@ util::Status WvCasEcm::GenerateEcm(const std::string& even_key,
|
|||||||
if (!(status = fixed_key_fetcher.RequestEntitlementKey(entitlement_request,
|
if (!(status = fixed_key_fetcher.RequestEntitlementKey(entitlement_request,
|
||||||
&entitlement_response))
|
&entitlement_response))
|
||||||
.ok()) {
|
.ok()) {
|
||||||
return status;
|
LOG(ERROR) << "Failed to get entitlement key.";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!(status = cas_ecm->ProcessCasEncryptionResponse(entitlement_response))
|
if (!(status = cas_ecm->ProcessCasEncryptionResponse(entitlement_response))
|
||||||
.ok()) {
|
.ok()) {
|
||||||
return status;
|
LOG(ERROR) << "Failed to process entitlement key.";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate ECM.
|
// Generate ECM.
|
||||||
@@ -153,27 +155,27 @@ util::Status WvCasEcm::GenerateEcm(const std::string& even_key,
|
|||||||
ecm_param.key_params[1].content_ivs.push_back(odd_content_iv);
|
ecm_param.key_params[1].content_ivs.push_back(odd_content_iv);
|
||||||
*ecm = ecm_generator.GenerateEcm(ecm_param);
|
*ecm = ecm_generator.GenerateEcm(ecm_param);
|
||||||
|
|
||||||
return util::OkStatus();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
util::Status WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
|
bool WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
|
||||||
const std::string& even_content_iv,
|
const std::string& even_content_iv,
|
||||||
const std::string& entitlement_key_id,
|
const std::string& entitlement_key_id,
|
||||||
const std::string& entitlement_key,
|
const std::string& entitlement_key,
|
||||||
std::string* ecm) const {
|
std::string* ecm) const {
|
||||||
|
DCHECK(ecm);
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
DCHECK(ecm);
|
LOG(ERROR) << "WvCasEcm has not been properly initialized";
|
||||||
return util::Status(util::error::INTERNAL,
|
return false;
|
||||||
"WvCasEcm has not been properly initialized");
|
|
||||||
}
|
}
|
||||||
if (key_rotation_enabled_) {
|
if (key_rotation_enabled_) {
|
||||||
return util::Status(
|
LOG(ERROR)
|
||||||
util::error::INTERNAL,
|
<< "Please call GenerateEcm() instead when key rotation is enabled";
|
||||||
"Please call GenerateEcm() instead when key rotation is enabled");
|
return false;
|
||||||
}
|
}
|
||||||
if (even_content_iv.size() != content_iv_size_) {
|
if (even_content_iv.size() != content_iv_size_) {
|
||||||
return util::Status(util::error::INVALID_ARGUMENT,
|
LOG(ERROR) << "Size of content IV is incorrect";
|
||||||
"Size of content IV is incorrect");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an instance of CasEcm in order to set the entitlement keys.
|
// Create an instance of CasEcm in order to set the entitlement keys.
|
||||||
@@ -192,7 +194,8 @@ util::Status WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
|
|||||||
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;
|
LOG(ERROR) << "Failed to get initialize ECM class.";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
FixedKeyFetcher fixed_key_fetcher(
|
FixedKeyFetcher fixed_key_fetcher(
|
||||||
/* even_entitlement_key_id= */ entitlement_key_id,
|
/* even_entitlement_key_id= */ entitlement_key_id,
|
||||||
@@ -202,11 +205,13 @@ util::Status WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
|
|||||||
if (!(status = fixed_key_fetcher.RequestEntitlementKey(entitlement_request,
|
if (!(status = fixed_key_fetcher.RequestEntitlementKey(entitlement_request,
|
||||||
&entitlement_response))
|
&entitlement_response))
|
||||||
.ok()) {
|
.ok()) {
|
||||||
return status;
|
LOG(ERROR) << "Failed to get entitlement key.";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (!(status = cas_ecm->ProcessCasEncryptionResponse(entitlement_response))
|
if (!(status = cas_ecm->ProcessCasEncryptionResponse(entitlement_response))
|
||||||
.ok()) {
|
.ok()) {
|
||||||
return status;
|
LOG(ERROR) << "Failed to process entitlement key.";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate ECM.
|
// Generate ECM.
|
||||||
@@ -222,7 +227,7 @@ util::Status WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
|
|||||||
ecm_param.key_params[0].content_ivs.push_back(even_content_iv);
|
ecm_param.key_params[0].content_ivs.push_back(even_content_iv);
|
||||||
*ecm = ecm_generator.GenerateEcm(ecm_param);
|
*ecm = ecm_generator.GenerateEcm(ecm_param);
|
||||||
|
|
||||||
return util::OkStatus();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cas
|
} // namespace cas
|
||||||
|
|||||||
@@ -47,12 +47,12 @@ class WvCasEcm {
|
|||||||
// only CTR is supported by Widevine CAS plugin for now
|
// only CTR is supported by Widevine CAS plugin for now
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - A status indicating whether there was any error during initialization
|
// - A boolean indicating whether there was any error during initialization
|
||||||
//
|
//
|
||||||
// Note:
|
// Note:
|
||||||
// - 'even'/'odd' key in the ECM will be be encrypted using AEC_CBC
|
// - 'even'/'odd' key in the ECM will be be encrypted using AEC_CBC
|
||||||
virtual util::Status Initialize(int content_iv_size,
|
virtual bool Initialize(int content_iv_size, bool key_rotation_enabled,
|
||||||
bool key_rotation_enabled, int crypto_mode);
|
int crypto_mode);
|
||||||
|
|
||||||
// Generate an ECM containing two keys (even and odd). Can be called when
|
// Generate an ECM containing two keys (even and odd). Can be called when
|
||||||
// |key_rotation_enabled| is initialized to 'true'.
|
// |key_rotation_enabled| is initialized to 'true'.
|
||||||
@@ -67,20 +67,18 @@ class WvCasEcm {
|
|||||||
// - |ecm| for returning the generated ECM, must not be nullptr
|
// - |ecm| for returning the generated ECM, must not be nullptr
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - A status indicating whether there was any error during processing
|
// - A boolean indicating whether there was any error during processing
|
||||||
//
|
//
|
||||||
// Note:
|
// Note:
|
||||||
// - The same |entitlement_key| will be used to encrypt both |even_key|
|
// - The same |entitlement_key| will be used to encrypt both |even_key|
|
||||||
// and |odd_key| in the ECM
|
// and |odd_key| in the ECM
|
||||||
// - Size of |even_content_iv| and |odd_content_iv| must match
|
// - Size of |even_content_iv| and |odd_content_iv| must match
|
||||||
// |content_iv_size| set during initialization
|
// |content_iv_size| set during initialization
|
||||||
virtual util::Status GenerateEcm(const std::string& even_key,
|
virtual bool GenerateEcm(const std::string& even_key,
|
||||||
const std::string& even_content_iv,
|
const std::string& even_content_iv, const std::string& odd_key,
|
||||||
const std::string& odd_key,
|
const std::string& odd_content_iv,
|
||||||
const std::string& odd_content_iv,
|
const std::string& entitlement_key_id,
|
||||||
const std::string& entitlement_key_id,
|
const std::string& entitlement_key, std::string* ecm) const;
|
||||||
const std::string& entitlement_key,
|
|
||||||
std::string* ecm) const;
|
|
||||||
|
|
||||||
// Generate an ECM containing only a singe even key. Can be called when
|
// Generate an ECM containing only a singe even key. Can be called when
|
||||||
// |key_rotation_enabled| is initialized to 'false'.
|
// |key_rotation_enabled| is initialized to 'false'.
|
||||||
@@ -93,16 +91,16 @@ class WvCasEcm {
|
|||||||
// - |ecm| for returning the generated ECM, must not be nullptr
|
// - |ecm| for returning the generated ECM, must not be nullptr
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - A status indicating whether there was any error during processing
|
// - A boolean indicating whether there was any error during processing
|
||||||
//
|
//
|
||||||
// Note:
|
// Note:
|
||||||
// - Size of |even_content_iv| and |odd_content_iv| must match
|
// - Size of |even_content_iv| and |odd_content_iv| must match
|
||||||
// |content_iv_size| set during initialization
|
// |content_iv_size| set during initialization
|
||||||
virtual util::Status GenerateSingleKeyEcm(const std::string& even_key,
|
virtual bool GenerateSingleKeyEcm(const std::string& even_key,
|
||||||
const std::string& even_content_iv,
|
const std::string& even_content_iv,
|
||||||
const std::string& entitlement_key_id,
|
const std::string& entitlement_key_id,
|
||||||
const std::string& entitlement_key,
|
const std::string& entitlement_key,
|
||||||
std::string* ecm) const;
|
std::string* ecm) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
|
|||||||
@@ -30,94 +30,75 @@ class WvCasEcmTest : public Test {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, InitializeTwice) {
|
TEST_F(WvCasEcmTest, InitializeTwice) {
|
||||||
EXPECT_OK(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||||
/* key_rotation_enabled= */ true,
|
/* key_rotation_enabled= */ true,
|
||||||
/* crypto_mode= */ 1));
|
/* crypto_mode= */ 1));
|
||||||
EXPECT_EQ(util::error::INTERNAL,
|
EXPECT_FALSE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||||
wv_cas_ecm_
|
/* key_rotation_enabled= */ true,
|
||||||
.Initialize(/* content_iv_size= */ 8,
|
/* crypto_mode= */ 1));
|
||||||
/* key_rotation_enabled= */ true,
|
|
||||||
/* crypto_mode= */ 1)
|
|
||||||
.error_code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, InitializeContentIvSize) {
|
TEST_F(WvCasEcmTest, InitializeContentIvSize) {
|
||||||
EXPECT_EQ(
|
EXPECT_FALSE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 4,
|
||||||
util::error::INVALID_ARGUMENT,
|
/* key_rotation_enabled= */ true,
|
||||||
wv_cas_ecm_
|
/* crypto_mode= */ 1));
|
||||||
.Initialize(/* content_iv_size= */ 4,
|
|
||||||
/* key_rotation_enabled= */ true, /* crypto_mode= */ 1)
|
|
||||||
.error_code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, InitializeCryptoMode) {
|
TEST_F(WvCasEcmTest, InitializeCryptoMode) {
|
||||||
EXPECT_EQ(
|
EXPECT_FALSE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||||
util::error::INVALID_ARGUMENT,
|
/* key_rotation_enabled= */ true,
|
||||||
wv_cas_ecm_
|
/* crypto_mode= */ 0));
|
||||||
.Initialize(/* content_iv_size= */ 8,
|
|
||||||
/* key_rotation_enabled= */ true, /* crypto_mode= */ 0)
|
|
||||||
.error_code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, InitializeKeyRotationEnabled) {
|
TEST_F(WvCasEcmTest, InitializeKeyRotationEnabled) {
|
||||||
EXPECT_OK(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||||
/* key_rotation_enabled= */ true,
|
/* key_rotation_enabled= */ true,
|
||||||
/* crypto_mode= */ 1));
|
/* crypto_mode= */ 1));
|
||||||
std::string actual_ecm;
|
std::string actual_ecm;
|
||||||
EXPECT_EQ(util::error::INTERNAL,
|
EXPECT_FALSE(wv_cas_ecm_.GenerateSingleKeyEcm("", "", "", "", &actual_ecm));
|
||||||
wv_cas_ecm_.GenerateSingleKeyEcm("", "", "", "", &actual_ecm)
|
|
||||||
.error_code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, InitializeKeyRotationDisabled) {
|
TEST_F(WvCasEcmTest, InitializeKeyRotationDisabled) {
|
||||||
EXPECT_OK(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||||
/* key_rotation_enabled= */ false,
|
/* key_rotation_enabled= */ false,
|
||||||
/* crypto_mode= */ 1));
|
/* crypto_mode= */ 1));
|
||||||
std::string actual_ecm;
|
std::string actual_ecm;
|
||||||
EXPECT_EQ(util::error::INTERNAL,
|
EXPECT_FALSE(wv_cas_ecm_.GenerateEcm("", "", "", "", "", "", &actual_ecm));
|
||||||
wv_cas_ecm_.GenerateEcm("", "", "", "", "", "", &actual_ecm)
|
|
||||||
.error_code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, GenerateEcmInvalidContentIv) {
|
TEST_F(WvCasEcmTest, GenerateEcmInvalidContentIv) {
|
||||||
EXPECT_OK(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||||
/* key_rotation_enabled= */ true,
|
/* key_rotation_enabled= */ true,
|
||||||
/* crypto_mode= */ 1));
|
/* crypto_mode= */ 1));
|
||||||
std::string actual_ecm;
|
std::string actual_ecm;
|
||||||
EXPECT_EQ(util::error::INVALID_ARGUMENT,
|
EXPECT_FALSE(wv_cas_ecm_.GenerateEcm(
|
||||||
wv_cas_ecm_
|
/* even_key= */ kEvenKey,
|
||||||
.GenerateEcm(
|
/* even_content_iv= */ kEvenContentIv8Bytes,
|
||||||
/* even_key= */ kEvenKey,
|
/* odd_key= */ kOddKey,
|
||||||
/* even_content_iv= */ kEvenContentIv8Bytes,
|
/* odd_content_iv= */ "123456789",
|
||||||
/* odd_key= */ kOddKey,
|
/* entitlement_key_id= */ kEntitlementKeyId,
|
||||||
/* odd_content_iv= */ "123456789",
|
/* entitlement_key= */ kEntitlementKey, &actual_ecm));
|
||||||
/* entitlement_key_id= */ kEntitlementKeyId,
|
|
||||||
/* entitlement_key= */ kEntitlementKey, &actual_ecm)
|
|
||||||
.error_code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcmInvalidContentIv) {
|
TEST_F(WvCasEcmTest, GenerateSingleKeyEcmInvalidContentIv) {
|
||||||
EXPECT_OK(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||||
/* key_rotation_enabled= */ false,
|
/* key_rotation_enabled= */ false,
|
||||||
/* crypto_mode= */ 1));
|
/* crypto_mode= */ 1));
|
||||||
std::string actual_ecm;
|
std::string actual_ecm;
|
||||||
EXPECT_EQ(util::error::INVALID_ARGUMENT,
|
EXPECT_FALSE(wv_cas_ecm_.GenerateSingleKeyEcm(
|
||||||
wv_cas_ecm_
|
/* even_key= */ kEvenKey,
|
||||||
.GenerateSingleKeyEcm(
|
/* even_content_iv= */ "1234",
|
||||||
/* even_key= */ kEvenKey,
|
/* entitlement_key_id= */ kEntitlementKeyId,
|
||||||
/* even_content_iv= */ "1234",
|
/* entitlement_key= */ kEntitlementKey, &actual_ecm));
|
||||||
/* entitlement_key_id= */ kEntitlementKeyId,
|
|
||||||
/* entitlement_key= */ kEntitlementKey, &actual_ecm)
|
|
||||||
.error_code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, GenerateEcm8BytesContentIvSuccess) {
|
TEST_F(WvCasEcmTest, GenerateEcm8BytesContentIvSuccess) {
|
||||||
EXPECT_OK(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||||
/* key_rotation_enabled= */ true,
|
/* key_rotation_enabled= */ true,
|
||||||
/* crypto_mode= */ 1));
|
/* crypto_mode= */ 1));
|
||||||
|
|
||||||
std::string actual_ecm;
|
std::string actual_ecm;
|
||||||
EXPECT_OK(wv_cas_ecm_.GenerateEcm(
|
EXPECT_TRUE(wv_cas_ecm_.GenerateEcm(
|
||||||
/* even_key= */ kEvenKey,
|
/* even_key= */ kEvenKey,
|
||||||
/* even_content_iv= */ kEvenContentIv8Bytes,
|
/* even_content_iv= */ kEvenContentIv8Bytes,
|
||||||
/* odd_key= */ kOddKey,
|
/* odd_key= */ kOddKey,
|
||||||
@@ -135,12 +116,12 @@ TEST_F(WvCasEcmTest, GenerateEcm8BytesContentIvSuccess) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm8BytesContentIvSuccess) {
|
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm8BytesContentIvSuccess) {
|
||||||
EXPECT_OK(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||||
/* key_rotation_enabled= */ false,
|
/* key_rotation_enabled= */ false,
|
||||||
/* crypto_mode= */ 1));
|
/* crypto_mode= */ 1));
|
||||||
|
|
||||||
std::string actual_ecm;
|
std::string actual_ecm;
|
||||||
EXPECT_OK(wv_cas_ecm_.GenerateSingleKeyEcm(
|
EXPECT_TRUE(wv_cas_ecm_.GenerateSingleKeyEcm(
|
||||||
/* even_key= */ kEvenKey,
|
/* even_key= */ kEvenKey,
|
||||||
/* even_content_iv= */ kEvenContentIv8Bytes,
|
/* even_content_iv= */ kEvenContentIv8Bytes,
|
||||||
/* entitlement_key_id= */ kEntitlementKeyId,
|
/* entitlement_key_id= */ kEntitlementKeyId,
|
||||||
@@ -154,12 +135,12 @@ TEST_F(WvCasEcmTest, GenerateSingleKeyEcm8BytesContentIvSuccess) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvSuccess) {
|
TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvSuccess) {
|
||||||
EXPECT_OK(wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
||||||
/* key_rotation_enabled= */ true,
|
/* key_rotation_enabled= */ true,
|
||||||
/* crypto_mode= */ 1));
|
/* crypto_mode= */ 1));
|
||||||
|
|
||||||
std::string actual_ecm;
|
std::string actual_ecm;
|
||||||
EXPECT_OK(wv_cas_ecm_.GenerateEcm(
|
EXPECT_TRUE(wv_cas_ecm_.GenerateEcm(
|
||||||
/* even_key= */ kEvenKey,
|
/* even_key= */ kEvenKey,
|
||||||
/* even_content_iv= */
|
/* even_content_iv= */
|
||||||
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
|
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
|
||||||
@@ -179,12 +160,12 @@ TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvSuccess) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm16BytesContentIvSuccess) {
|
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm16BytesContentIvSuccess) {
|
||||||
EXPECT_OK(wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
||||||
/* key_rotation_enabled= */ false,
|
/* key_rotation_enabled= */ false,
|
||||||
/* crypto_mode= */ 1));
|
/* crypto_mode= */ 1));
|
||||||
|
|
||||||
std::string actual_ecm;
|
std::string actual_ecm;
|
||||||
EXPECT_OK(wv_cas_ecm_.GenerateSingleKeyEcm(
|
EXPECT_TRUE(wv_cas_ecm_.GenerateSingleKeyEcm(
|
||||||
/* even_key= */ kEvenKey,
|
/* even_key= */ kEvenKey,
|
||||||
/* even_content_iv= */
|
/* even_content_iv= */
|
||||||
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
|
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
|
||||||
|
|||||||
Reference in New Issue
Block a user