Create a WvCasStatus to be used as return type of libraries in media_cas_packager_sdk.

Following example: []/video/widevine/export/provisioning_sdk/public/provisioning_status.h
and
[]/video/widevine/export/exported_root/util/status.h

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=218918745
This commit is contained in:
Fang Yu
2018-10-26 14:56:05 -07:00
parent 70f62ed75e
commit 051a520776
9 changed files with 305 additions and 141 deletions

View File

@@ -47,7 +47,8 @@ cc_binary(
name = "wv_cas_ecm_example", name = "wv_cas_ecm_example",
srcs = ["wv_cas_ecm_example.cc"], srcs = ["wv_cas_ecm_example.cc"],
deps = [ deps = [
"//base", "@abseil_repo//absl/base:core_headers",
"//media_cas_packager_sdk/public:wv_cas_ecm", "//media_cas_packager_sdk/public:wv_cas_ecm",
"//media_cas_packager_sdk/public:wv_cas_status",
], ],
) )

View File

@@ -12,6 +12,7 @@
#include <string> #include <string>
#include "media_cas_packager_sdk/public/wv_cas_ecm.h" #include "media_cas_packager_sdk/public/wv_cas_ecm.h"
#include "media_cas_packager_sdk/public/wv_cas_status.h"
const int kContentIvSize = 16; const int kContentIvSize = 16;
const bool kKeyRotationEnabled = true; const bool kKeyRotationEnabled = true;
@@ -27,17 +28,21 @@ const char kEntitlementKey[] = "entitlement_key................."; // 32 bytes
int main(int argc, char **argv) { int main(int argc, char **argv) {
widevine::cas::WvCasEcm wv_cas_ecm; widevine::cas::WvCasEcm wv_cas_ecm;
bool status = widevine::cas::WvCasStatus status =
wv_cas_ecm.Initialize(kContentIvSize, kKeyRotationEnabled, kCryptoMode); wv_cas_ecm.Initialize(kContentIvSize, kKeyRotationEnabled, kCryptoMode);
if (!status) { if (status != widevine::cas::OK) {
std::cerr << "Failed to initialize WV CAS ECM, error." << std::endl; std::cerr << "Failed to initialize WV CAS ECM, error: "
<< widevine::cas::GetWvCasStatusMessage(status)
<< std::endl;
} }
std::string ecm; std::string ecm;
status = wv_cas_ecm.GenerateEcm(kEvenKey, kEvenContentIv16Bytes, kOddKey, status = wv_cas_ecm.GenerateEcm(kEvenKey, kEvenContentIv16Bytes, kOddKey,
kOddContentIv16Bytes, kEntitlementKeyId, kOddContentIv16Bytes, kEntitlementKeyId,
kEntitlementKey, &ecm); kEntitlementKey, &ecm);
if (!status) { if (status != widevine::cas::OK) {
std::cerr << "Failed to generate WV CAS ECM, error" << std::endl; std::cerr << "Failed to generate WV CAS ECM, error: "
<< widevine::cas::GetWvCasStatusMessage(status)
<< std::endl;
} else { } else {
std::cout << "ECM size: " << ecm.size() << std::endl; std::cout << "ECM size: " << ecm.size() << std::endl;
std::cout << "ECM bytes: "; std::cout << "ECM bytes: ";

View File

@@ -28,7 +28,10 @@ filegroup(
cc_binary( cc_binary(
name = "libmedia_cas_packager_sdk.so", name = "libmedia_cas_packager_sdk.so",
linkshared = 1, linkshared = 1,
deps = [":wv_cas_ecm"], deps = [
":wv_cas_ecm",
":wv_cas_status",
],
) )
cc_library( cc_library(
@@ -60,6 +63,7 @@ cc_library(
hdrs = ["wv_cas_ecm.h"], hdrs = ["wv_cas_ecm.h"],
copts = PUBLIC_COPTS, copts = PUBLIC_COPTS,
deps = [ deps = [
":wv_cas_status",
"//base", "//base",
"@abseil_repo//absl/base:core_headers", "@abseil_repo//absl/base:core_headers",
"@abseil_repo//absl/memory", "@abseil_repo//absl/memory",
@@ -80,7 +84,26 @@ cc_test(
srcs = ["wv_cas_ecm_test.cc"], srcs = ["wv_cas_ecm_test.cc"],
deps = [ deps = [
":wv_cas_ecm", ":wv_cas_ecm",
":wv_cas_status",
"//testing:gunit_main", "//testing:gunit_main",
"@abseil_repo//absl/strings", "@abseil_repo//absl/strings",
], ],
) )
cc_library(
name = "wv_cas_status",
srcs = ["wv_cas_status.cc"],
hdrs = ["wv_cas_status.h"],
copts = PUBLIC_COPTS,
deps = ["//base"],
)
cc_test(
name = "wv_cas_status_test",
size = "small",
srcs = ["wv_cas_status_test.cc"],
deps = [
":wv_cas_status",
"//testing:gunit_main",
],
)

View File

@@ -8,21 +8,21 @@
#include "media_cas_packager_sdk/public/wv_cas_ecm.h" #include "media_cas_packager_sdk/public/wv_cas_ecm.h"
#include <stdio.h> #include <stddef.h>
#include <iostream>
#include <memory> #include <memory>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "glog/logging.h" #include "glog/logging.h"
#include "util/status.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "util/status.h"
#include "common/crypto_util.h" #include "common/crypto_util.h"
#include "example/constants.h" #include "example/constants.h"
#include "media_cas_packager_sdk/internal/ecm.h" #include "media_cas_packager_sdk/internal/ecm.h"
#include "media_cas_packager_sdk/internal/ecm_generator.h" #include "media_cas_packager_sdk/internal/ecm_generator.h"
#include "media_cas_packager_sdk/internal/fixed_key_fetcher.h" #include "media_cas_packager_sdk/internal/fixed_key_fetcher.h"
#include "media_cas_packager_sdk/public/wv_cas_status.h"
#include "protos/public/media_cas.pb.h" #include "protos/public/media_cas.pb.h"
namespace widevine { namespace widevine {
@@ -52,52 +52,51 @@ EcmInitParameters CreateEcmInitParameters(int content_iv_size,
} // namespace } // namespace
// TODO(user): Return a status class like WvCasStatus WvCasEcm::Initialize(int content_iv_size, bool key_rotation_enabled,
// instead of boolean.
bool WvCasEcm::Initialize(int content_iv_size, bool key_rotation_enabled,
int crypto_mode) { int crypto_mode) {
if (initialized_) { if (initialized_) {
LOG(ERROR) << "Cannot initialize an instance of WvCasEcm more than once"; LOG(ERROR) << "Cannot initialize an instance of WvCasEcm more than once";
return false; return UNAVAILABLE;
} }
if (content_iv_size != 8 && content_iv_size != 16) { if (content_iv_size != 8 && content_iv_size != 16) {
LOG(ERROR) << "Only support content_iv_size being 8 now"; LOG(ERROR) << "Only support content_iv_size being 8 now";
return false; return INVALID_ARGUMENT;
} }
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) {
LOG(ERROR) << "Only CTR crypto mode is supported by Widevine plugin for " LOG(ERROR) << "Only CTR crypto mode is supported by Widevine plugin for "
"content encryption"; "content encryption";
return false; return INVALID_ARGUMENT;
} }
crypto_mode_ = crypto_mode; crypto_mode_ = crypto_mode;
initialized_ = true; initialized_ = true;
return true; return OK;
} }
bool WvCasEcm::GenerateEcm(const std::string& even_key, WvCasStatus 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_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 {
DCHECK(ecm); DCHECK(ecm);
if (!initialized_) { if (!initialized_) {
LOG(ERROR) << "WvCasEcm has not been properly initialized"; LOG(ERROR) << "WvCasEcm has not been properly initialized";
return false; return UNAVAILABLE;
} }
if (!key_rotation_enabled_) { if (!key_rotation_enabled_) {
LOG(ERROR) << "Please call GenerateSingleKeyEcm() instead when key " LOG(ERROR) << "Please call GenerateSingleKeyEcm() instead when key "
"rotation is disabled"; "rotation is disabled";
return false; return UNAVAILABLE;
} }
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_) {
LOG(ERROR) << "Size of content IV is incorrect"; LOG(ERROR) << "Size of content IV is incorrect";
return false; return INVALID_ARGUMENT;
} }
// 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,7 @@ bool WvCasEcm::GenerateEcm(const std::string& even_key,
ecm_init_params, &entitlement_request)) ecm_init_params, &entitlement_request))
.ok()) { .ok()) {
LOG(ERROR) << "Failed to initialize ECM class."; LOG(ERROR) << "Failed to initialize ECM class.";
return false; return INTERNAL;
} }
FixedKeyFetcher fixed_key_fetcher( FixedKeyFetcher fixed_key_fetcher(
/* even_entitlement_key_id= */ entitlement_key_id, /* even_entitlement_key_id= */ entitlement_key_id,
@@ -128,12 +127,12 @@ bool WvCasEcm::GenerateEcm(const std::string& even_key,
&entitlement_response)) &entitlement_response))
.ok()) { .ok()) {
LOG(ERROR) << "Failed to get entitlement key."; LOG(ERROR) << "Failed to get entitlement key.";
return false; return INTERNAL;
} }
if (!(status = cas_ecm->ProcessCasEncryptionResponse(entitlement_response)) if (!(status = cas_ecm->ProcessCasEncryptionResponse(entitlement_response))
.ok()) { .ok()) {
LOG(ERROR) << "Failed to process entitlement key."; LOG(ERROR) << "Failed to process entitlement key.";
return false; return INTERNAL;
} }
// Generate ECM. // Generate ECM.
@@ -155,10 +154,10 @@ bool 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 true; return OK;
} }
bool WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key, WvCasStatus 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,
@@ -166,16 +165,16 @@ bool WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
DCHECK(ecm); DCHECK(ecm);
if (!initialized_) { if (!initialized_) {
LOG(ERROR) << "WvCasEcm has not been properly initialized"; LOG(ERROR) << "WvCasEcm has not been properly initialized";
return false; return UNAVAILABLE;
} }
if (key_rotation_enabled_) { if (key_rotation_enabled_) {
LOG(ERROR) LOG(ERROR)
<< "Please call GenerateEcm() instead when key rotation is enabled"; << "Please call GenerateEcm() instead when key rotation is enabled";
return false; return UNAVAILABLE;
} }
if (even_content_iv.size() != content_iv_size_) { if (even_content_iv.size() != content_iv_size_) {
LOG(ERROR) << "Size of content IV is incorrect"; LOG(ERROR) << "Size of content IV is incorrect";
return false; return INVALID_ARGUMENT;
} }
// Create an instance of CasEcm in order to set the entitlement keys. // Create an instance of CasEcm in order to set the entitlement keys.
@@ -195,7 +194,7 @@ bool WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
ecm_init_params, &entitlement_request)) ecm_init_params, &entitlement_request))
.ok()) { .ok()) {
LOG(ERROR) << "Failed to get initialize ECM class."; LOG(ERROR) << "Failed to get initialize ECM class.";
return false; return INTERNAL;
} }
FixedKeyFetcher fixed_key_fetcher( FixedKeyFetcher fixed_key_fetcher(
/* even_entitlement_key_id= */ entitlement_key_id, /* even_entitlement_key_id= */ entitlement_key_id,
@@ -206,12 +205,12 @@ bool WvCasEcm::GenerateSingleKeyEcm(const std::string& even_key,
&entitlement_response)) &entitlement_response))
.ok()) { .ok()) {
LOG(ERROR) << "Failed to get entitlement key."; LOG(ERROR) << "Failed to get entitlement key.";
return false; return INTERNAL;
} }
if (!(status = cas_ecm->ProcessCasEncryptionResponse(entitlement_response)) if (!(status = cas_ecm->ProcessCasEncryptionResponse(entitlement_response))
.ok()) { .ok()) {
LOG(ERROR) << "Failed to process entitlement key."; LOG(ERROR) << "Failed to process entitlement key.";
return false; return INTERNAL;
} }
// Generate ECM. // Generate ECM.
@@ -227,7 +226,7 @@ bool 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 true; return OK;
} }
} // namespace cas } // namespace cas

View File

@@ -16,7 +16,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "util/status.h" #include "media_cas_packager_sdk/public/wv_cas_status.h"
namespace widevine { namespace widevine {
namespace cas { namespace cas {
@@ -47,11 +47,11 @@ 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 boolean indicating whether there was any error during initialization // - A status 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 bool Initialize(int content_iv_size, bool key_rotation_enabled, virtual WvCasStatus Initialize(int content_iv_size, 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
@@ -67,18 +67,20 @@ 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 boolean indicating whether there was any error during processing // - A status 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 bool GenerateEcm(const std::string& even_key, virtual WvCasStatus 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_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'.
@@ -91,12 +93,12 @@ 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 boolean indicating whether there was any error during processing // - A status 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 bool GenerateSingleKeyEcm(const std::string& even_key, virtual WvCasStatus 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,

View File

@@ -7,9 +7,11 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include "media_cas_packager_sdk/public/wv_cas_ecm.h" #include "media_cas_packager_sdk/public/wv_cas_ecm.h"
#include "testing/gmock.h"
#include "testing/gunit.h" #include "testing/gunit.h"
#include "absl/strings/escaping.h" #include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "media_cas_packager_sdk/public/wv_cas_status.h"
using ::testing::Test; using ::testing::Test;
@@ -30,48 +32,54 @@ class WvCasEcmTest : public Test {
}; };
TEST_F(WvCasEcmTest, InitializeTwice) { TEST_F(WvCasEcmTest, InitializeTwice) {
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8, EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
/* key_rotation_enabled= */ true, /* key_rotation_enabled= */ true,
/* crypto_mode= */ 1)); /* crypto_mode= */ 1));
EXPECT_FALSE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8, EXPECT_EQ(UNAVAILABLE,
wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
/* key_rotation_enabled= */ true, /* key_rotation_enabled= */ true,
/* crypto_mode= */ 1)); /* crypto_mode= */ 1));
} }
TEST_F(WvCasEcmTest, InitializeContentIvSize) { TEST_F(WvCasEcmTest, InitializeInvalidContentIvSize) {
EXPECT_FALSE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 4, EXPECT_EQ(INVALID_ARGUMENT,
wv_cas_ecm_.Initialize(/* content_iv_size= */ 4,
/* key_rotation_enabled= */ true, /* key_rotation_enabled= */ true,
/* crypto_mode= */ 1)); /* crypto_mode= */ 1));
} }
TEST_F(WvCasEcmTest, InitializeCryptoMode) { TEST_F(WvCasEcmTest, InitializeUnsupportedCryptoMode) {
EXPECT_FALSE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8, EXPECT_EQ(INVALID_ARGUMENT,
wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
/* key_rotation_enabled= */ true, /* key_rotation_enabled= */ true,
/* crypto_mode= */ 0)); /* crypto_mode= */ 0));
} }
TEST_F(WvCasEcmTest, InitializeKeyRotationEnabled) { TEST_F(WvCasEcmTest, InitializeKeyRotationEnabledThenGenerateSingleKeyEcm) {
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8, EXPECT_EQ(OK, 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_FALSE(wv_cas_ecm_.GenerateSingleKeyEcm("", "", "", "", &actual_ecm)); EXPECT_EQ(UNAVAILABLE,
wv_cas_ecm_.GenerateSingleKeyEcm("", "", "", "", &actual_ecm));
} }
TEST_F(WvCasEcmTest, InitializeKeyRotationDisabled) { TEST_F(WvCasEcmTest, InitializeKeyRotationDisabledThenGenerateEcm) {
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8, EXPECT_EQ(OK, 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_FALSE(wv_cas_ecm_.GenerateEcm("", "", "", "", "", "", &actual_ecm)); EXPECT_EQ(UNAVAILABLE,
wv_cas_ecm_.GenerateEcm("", "", "", "", "", "", &actual_ecm));
} }
TEST_F(WvCasEcmTest, GenerateEcmInvalidContentIv) { TEST_F(WvCasEcmTest, GenerateEcmInvalidContentIv) {
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8, EXPECT_EQ(OK, 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_FALSE(wv_cas_ecm_.GenerateEcm( EXPECT_EQ(INVALID_ARGUMENT,
wv_cas_ecm_.GenerateEcm(
/* even_key= */ kEvenKey, /* even_key= */ kEvenKey,
/* even_content_iv= */ kEvenContentIv8Bytes, /* even_content_iv= */ kEvenContentIv8Bytes,
/* odd_key= */ kOddKey, /* odd_key= */ kOddKey,
@@ -81,11 +89,12 @@ TEST_F(WvCasEcmTest, GenerateEcmInvalidContentIv) {
} }
TEST_F(WvCasEcmTest, GenerateSingleKeyEcmInvalidContentIv) { TEST_F(WvCasEcmTest, GenerateSingleKeyEcmInvalidContentIv) {
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8, EXPECT_EQ(OK, 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_FALSE(wv_cas_ecm_.GenerateSingleKeyEcm( EXPECT_EQ(INVALID_ARGUMENT,
wv_cas_ecm_.GenerateSingleKeyEcm(
/* even_key= */ kEvenKey, /* even_key= */ kEvenKey,
/* even_content_iv= */ "1234", /* even_content_iv= */ "1234",
/* entitlement_key_id= */ kEntitlementKeyId, /* entitlement_key_id= */ kEntitlementKeyId,
@@ -93,12 +102,12 @@ TEST_F(WvCasEcmTest, GenerateSingleKeyEcmInvalidContentIv) {
} }
TEST_F(WvCasEcmTest, GenerateEcm8BytesContentIvSuccess) { TEST_F(WvCasEcmTest, GenerateEcm8BytesContentIvSuccess) {
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8, EXPECT_EQ(OK, 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_TRUE(wv_cas_ecm_.GenerateEcm( EXPECT_EQ(OK, wv_cas_ecm_.GenerateEcm(
/* even_key= */ kEvenKey, /* even_key= */ kEvenKey,
/* even_content_iv= */ kEvenContentIv8Bytes, /* even_content_iv= */ kEvenContentIv8Bytes,
/* odd_key= */ kOddKey, /* odd_key= */ kOddKey,
@@ -116,12 +125,12 @@ TEST_F(WvCasEcmTest, GenerateEcm8BytesContentIvSuccess) {
} }
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm8BytesContentIvSuccess) { TEST_F(WvCasEcmTest, GenerateSingleKeyEcm8BytesContentIvSuccess) {
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 8, EXPECT_EQ(OK, 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_TRUE(wv_cas_ecm_.GenerateSingleKeyEcm( EXPECT_EQ(OK, 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,
@@ -135,12 +144,12 @@ TEST_F(WvCasEcmTest, GenerateSingleKeyEcm8BytesContentIvSuccess) {
} }
TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvSuccess) { TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvSuccess) {
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 16, EXPECT_EQ(OK, 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_TRUE(wv_cas_ecm_.GenerateEcm( EXPECT_EQ(OK, wv_cas_ecm_.GenerateEcm(
/* even_key= */ kEvenKey, /* even_key= */ kEvenKey,
/* even_content_iv= */ /* even_content_iv= */
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes), absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
@@ -160,12 +169,12 @@ TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvSuccess) {
} }
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm16BytesContentIvSuccess) { TEST_F(WvCasEcmTest, GenerateSingleKeyEcm16BytesContentIvSuccess) {
EXPECT_TRUE(wv_cas_ecm_.Initialize(/* content_iv_size= */ 16, EXPECT_EQ(OK, 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_TRUE(wv_cas_ecm_.GenerateSingleKeyEcm( EXPECT_EQ(OK, wv_cas_ecm_.GenerateSingleKeyEcm(
/* even_key= */ kEvenKey, /* even_key= */ kEvenKey,
/* even_content_iv= */ /* even_content_iv= */
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes), absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),

View File

@@ -0,0 +1,41 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2018 Google LLC.
//
// This software is licensed under the terms defined in the Widevine Master
// License Agreement. For a copy of this agreement, please contact
// widevine-licensing@google.com.
////////////////////////////////////////////////////////////////////////////////
#include "media_cas_packager_sdk/public/wv_cas_status.h"
#include "base/macros.h"
namespace widevine {
namespace cas {
static const char* kWvCasStatusMessage[] = {
"OK", // OK = 0,
"",
"",
"Invalid argument", // INVALID_ARGUMENT = 3,
"",
"Not found", // NOT_FOUND = 5,
"Already exists", // ALREADY_EXISTS = 6,
"Permission denied", // PERMISSION_DENIED = 7,
"",
"",
"",
"",
"Unimplemented", // UNIMPLEMENTED = 12,
"Internal", // INTERNAL = 13,
"Unavailable", // UNAVAILABLE = 14,
};
std::string GetWvCasStatusMessage(WvCasStatus status) {
static_assert(arraysize(kWvCasStatusMessage) == NUM_WV_CAS_STATUS,
"mismatching status message and status.");
return kWvCasStatusMessage[status];
}
} // namespace cas
} // namespace widevine

View File

@@ -0,0 +1,56 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2018 Google LLC.
//
// This software is licensed under the terms defined in the Widevine Master
// License Agreement. For a copy of this agreement, please contact
// widevine-licensing@google.com.
////////////////////////////////////////////////////////////////////////////////
#ifndef MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_STATUS_H_
#define MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_STATUS_H_
#include <string>
namespace widevine {
namespace cas {
enum WvCasStatus {
// Success.
OK = 0,
// Client specified an invalid argument.
INVALID_ARGUMENT = 3,
// Some requested entity (e.g., file or directory) was not found.
NOT_FOUND = 5,
// Some entity that we attempted to create (e.g., file or directory)
// already exists.
ALREADY_EXISTS = 6,
// The caller does not have permission to execute the specified
// operation.
PERMISSION_DENIED = 7,
// Operation is not implemented or not supported/enabled in this service.
UNIMPLEMENTED = 12,
// Internal errors. Means some invariants expected by underlying
// system has been broken. If you see one of these errors,
// something is very broken.
INTERNAL = 13,
// Operation is not implemented or not supported/enabled in this service.
UNAVAILABLE = 14,
// Number of errors.
NUM_WV_CAS_STATUS,
};
// Returns the message std::string for the given WvCasStatus.
std::string GetWvCasStatusMessage(WvCasStatus status);
} // namespace cas
} // namespace widevine
#endif // MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_STATUS_H_

View File

@@ -0,0 +1,28 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2018 Google LLC.
//
// This software is licensed under the terms defined in the Widevine Master
// License Agreement. For a copy of this agreement, please contact
// widevine-licensing@google.com.
////////////////////////////////////////////////////////////////////////////////
#include "media_cas_packager_sdk/public/wv_cas_status.h"
#include "testing/gunit.h"
namespace widevine {
namespace cas {
TEST(WvCasStatusTest, GetWvCasStatusMessage) {
EXPECT_EQ("OK", GetWvCasStatusMessage(OK));
EXPECT_EQ("Invalid argument", GetWvCasStatusMessage(INVALID_ARGUMENT));
EXPECT_EQ("Not found", GetWvCasStatusMessage(NOT_FOUND));
EXPECT_EQ("Already exists", GetWvCasStatusMessage(ALREADY_EXISTS));
EXPECT_EQ("Permission denied", GetWvCasStatusMessage(PERMISSION_DENIED));
EXPECT_EQ("Unimplemented", GetWvCasStatusMessage(UNIMPLEMENTED));
EXPECT_EQ("Internal", GetWvCasStatusMessage(INTERNAL));
EXPECT_EQ("Unavailable", GetWvCasStatusMessage(UNAVAILABLE));
}
} // namespace cas
} // namespace widevine