(1) Move the CryptoMode enum definition to media_cas_packager_sdk partners can use it when calling libraries in the SDK.
(2) Add a new enum value for kDvbCsa. (3) Allow caller to specify CTR, CBC, as well as CSA when using the ecm genertor from the SDK. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=219707788
This commit is contained in:
@@ -29,7 +29,7 @@ cc_binary(
|
||||
deps = [
|
||||
":wv_cas_ca_descriptor",
|
||||
":wv_cas_ecm",
|
||||
":wv_cas_status",
|
||||
":wv_cas_types",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -63,7 +63,7 @@ cc_library(
|
||||
hdrs = ["wv_cas_ca_descriptor.h"],
|
||||
copts = PUBLIC_COPTS,
|
||||
deps = [
|
||||
":wv_cas_status",
|
||||
":wv_cas_types",
|
||||
"//base",
|
||||
"@abseil_repo//absl/base:core_headers",
|
||||
"@abseil_repo//absl/strings",
|
||||
@@ -79,7 +79,7 @@ cc_test(
|
||||
srcs = ["wv_cas_ca_descriptor_test.cc"],
|
||||
deps = [
|
||||
":wv_cas_ca_descriptor",
|
||||
":wv_cas_status",
|
||||
":wv_cas_types",
|
||||
"//testing:gunit_main",
|
||||
"//protos/public:media_cas_proto",
|
||||
],
|
||||
@@ -91,7 +91,7 @@ cc_library(
|
||||
hdrs = ["wv_cas_ecm.h"],
|
||||
copts = PUBLIC_COPTS,
|
||||
deps = [
|
||||
":wv_cas_status",
|
||||
":wv_cas_types",
|
||||
"//base",
|
||||
"@abseil_repo//absl/base:core_headers",
|
||||
"@abseil_repo//absl/memory",
|
||||
@@ -102,7 +102,6 @@ cc_library(
|
||||
"//media_cas_packager_sdk/internal:ecm",
|
||||
"//media_cas_packager_sdk/internal:ecm_generator",
|
||||
"//media_cas_packager_sdk/internal:fixed_key_fetcher",
|
||||
"//protos/public:media_cas_proto",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -112,26 +111,26 @@ cc_test(
|
||||
srcs = ["wv_cas_ecm_test.cc"],
|
||||
deps = [
|
||||
":wv_cas_ecm",
|
||||
":wv_cas_status",
|
||||
":wv_cas_types",
|
||||
"//testing:gunit_main",
|
||||
"@abseil_repo//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "wv_cas_status",
|
||||
srcs = ["wv_cas_status.cc"],
|
||||
hdrs = ["wv_cas_status.h"],
|
||||
name = "wv_cas_types",
|
||||
srcs = ["wv_cas_types.cc"],
|
||||
hdrs = ["wv_cas_types.h"],
|
||||
copts = PUBLIC_COPTS,
|
||||
deps = ["//base"],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "wv_cas_status_test",
|
||||
name = "wv_cas_types_test",
|
||||
size = "small",
|
||||
srcs = ["wv_cas_status_test.cc"],
|
||||
srcs = ["wv_cas_types_test.cc"],
|
||||
deps = [
|
||||
":wv_cas_status",
|
||||
":wv_cas_types",
|
||||
"//testing:gunit_main",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "util/status.h"
|
||||
#include "common/string_util.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_status.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
#include "protos/public/media_cas.pb.h"
|
||||
|
||||
namespace widevine {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
|
||||
#include "media_cas_packager_sdk/public/wv_cas_status.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace cas {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "testing/gunit.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_status.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
#include "protos/public/media_cas.pb.h"
|
||||
|
||||
using ::testing::Test;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -22,19 +21,15 @@
|
||||
#include "media_cas_packager_sdk/internal/ecm.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/public/wv_cas_status.h"
|
||||
#include "protos/public/media_cas.pb.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace cas {
|
||||
|
||||
namespace {
|
||||
static constexpr size_t kCryptoModeCbc = 0;
|
||||
static constexpr size_t kCryptoModeCtr = 1;
|
||||
|
||||
EcmInitParameters CreateEcmInitParameters(int content_iv_size,
|
||||
bool key_rotation_enabled,
|
||||
int crypto_mode) {
|
||||
CryptoMode crypto_mode) {
|
||||
EcmInitParameters params;
|
||||
if (content_iv_size == 8) {
|
||||
params.content_iv_size = kIvSize8;
|
||||
@@ -42,7 +37,7 @@ EcmInitParameters CreateEcmInitParameters(int content_iv_size,
|
||||
params.content_iv_size = kIvSize16;
|
||||
}
|
||||
params.key_rotation_enabled = key_rotation_enabled;
|
||||
params.crypto_mode = CasCryptoMode::CTR;
|
||||
params.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.
|
||||
@@ -53,7 +48,7 @@ EcmInitParameters CreateEcmInitParameters(int content_iv_size,
|
||||
} // namespace
|
||||
|
||||
WvCasStatus WvCasEcm::Initialize(int content_iv_size, bool key_rotation_enabled,
|
||||
int crypto_mode) {
|
||||
CryptoMode crypto_mode) {
|
||||
if (initialized_) {
|
||||
LOG(ERROR) << "Cannot initialize an instance of WvCasEcm more than once";
|
||||
return UNAVAILABLE;
|
||||
@@ -64,11 +59,6 @@ WvCasStatus WvCasEcm::Initialize(int content_iv_size, bool key_rotation_enabled,
|
||||
}
|
||||
content_iv_size_ = content_iv_size;
|
||||
key_rotation_enabled_ = key_rotation_enabled;
|
||||
if (crypto_mode != kCryptoModeCtr) {
|
||||
LOG(ERROR) << "Only CTR crypto mode is supported by Widevine plugin for "
|
||||
"content encryption";
|
||||
return INVALID_ARGUMENT;
|
||||
}
|
||||
crypto_mode_ = crypto_mode;
|
||||
|
||||
initialized_ = true;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "media_cas_packager_sdk/public/wv_cas_status.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace cas {
|
||||
@@ -42,9 +42,7 @@ class WvCasEcm {
|
||||
// if this is 'true' only subsequent call to GenerateEcm will be allowed,
|
||||
// if this is 'false' only subsequent call to GenerateSingleKeyEcm will
|
||||
// be allowed
|
||||
// - |crypto_mode| crypto mode for encrypting content,
|
||||
// kCryptoModeCbc = 0, kCryptoModeCtr = 1
|
||||
// only CTR is supported by Widevine CAS plugin for now
|
||||
// - |crypto_mode| crypto mode for encrypting content
|
||||
//
|
||||
// Returns:
|
||||
// - A status indicating whether there was any error during initialization
|
||||
@@ -52,7 +50,7 @@ class WvCasEcm {
|
||||
// Note:
|
||||
// - 'even'/'odd' key in the ECM will be be encrypted using AEC_CBC
|
||||
virtual WvCasStatus Initialize(int content_iv_size, bool key_rotation_enabled,
|
||||
int crypto_mode);
|
||||
CryptoMode crypto_mode);
|
||||
|
||||
// Generate an ECM containing two keys (even and odd). Can be called when
|
||||
// |key_rotation_enabled| is initialized to 'true'.
|
||||
@@ -108,7 +106,7 @@ class WvCasEcm {
|
||||
bool initialized_ = false;
|
||||
int content_iv_size_;
|
||||
bool key_rotation_enabled_;
|
||||
int crypto_mode_;
|
||||
CryptoMode crypto_mode_;
|
||||
};
|
||||
|
||||
} // namespace cas
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "testing/gunit.h"
|
||||
#include "absl/strings/escaping.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_status.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
using ::testing::Test;
|
||||
|
||||
@@ -34,31 +34,24 @@ class WvCasEcmTest : public Test {
|
||||
TEST_F(WvCasEcmTest, InitializeTwice) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||
/* key_rotation_enabled= */ true,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
EXPECT_EQ(UNAVAILABLE,
|
||||
wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||
/* key_rotation_enabled= */ true,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, InitializeInvalidContentIvSize) {
|
||||
EXPECT_EQ(INVALID_ARGUMENT,
|
||||
wv_cas_ecm_.Initialize(/* content_iv_size= */ 4,
|
||||
/* key_rotation_enabled= */ true,
|
||||
/* crypto_mode= */ 1));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, InitializeUnsupportedCryptoMode) {
|
||||
EXPECT_EQ(INVALID_ARGUMENT,
|
||||
wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||
/* key_rotation_enabled= */ true,
|
||||
/* crypto_mode= */ 0));
|
||||
CryptoMode::kAesCtr));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, InitializeKeyRotationEnabledThenGenerateSingleKeyEcm) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||
/* key_rotation_enabled= */ true,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(UNAVAILABLE,
|
||||
wv_cas_ecm_.GenerateSingleKeyEcm("", "", "", "", &actual_ecm));
|
||||
@@ -67,7 +60,7 @@ TEST_F(WvCasEcmTest, InitializeKeyRotationEnabledThenGenerateSingleKeyEcm) {
|
||||
TEST_F(WvCasEcmTest, InitializeKeyRotationDisabledThenGenerateEcm) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||
/* key_rotation_enabled= */ false,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(UNAVAILABLE,
|
||||
wv_cas_ecm_.GenerateEcm("", "", "", "", "", "", &actual_ecm));
|
||||
@@ -76,7 +69,7 @@ TEST_F(WvCasEcmTest, InitializeKeyRotationDisabledThenGenerateEcm) {
|
||||
TEST_F(WvCasEcmTest, GenerateEcmInvalidContentIv) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||
/* key_rotation_enabled= */ true,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(INVALID_ARGUMENT,
|
||||
wv_cas_ecm_.GenerateEcm(
|
||||
@@ -91,7 +84,7 @@ TEST_F(WvCasEcmTest, GenerateEcmInvalidContentIv) {
|
||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcmInvalidContentIv) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||
/* key_rotation_enabled= */ false,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(INVALID_ARGUMENT,
|
||||
wv_cas_ecm_.GenerateSingleKeyEcm(
|
||||
@@ -101,10 +94,10 @@ TEST_F(WvCasEcmTest, GenerateSingleKeyEcmInvalidContentIv) {
|
||||
/* entitlement_key= */ kEntitlementKey, &actual_ecm));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, GenerateEcm8BytesContentIvSuccess) {
|
||||
TEST_F(WvCasEcmTest, GenerateEcm8BytesContentIvCtrSuccess) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||
/* key_rotation_enabled= */ true,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.GenerateEcm(
|
||||
@@ -124,10 +117,10 @@ TEST_F(WvCasEcmTest, GenerateEcm8BytesContentIvSuccess) {
|
||||
absl::BytesToHexString(actual_ecm));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm8BytesContentIvSuccess) {
|
||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm8BytesContentIvCtrSuccess) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 8,
|
||||
/* key_rotation_enabled= */ false,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.GenerateSingleKeyEcm(
|
||||
@@ -143,10 +136,10 @@ TEST_F(WvCasEcmTest, GenerateSingleKeyEcm8BytesContentIvSuccess) {
|
||||
absl::BytesToHexString(actual_ecm));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvSuccess) {
|
||||
TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvCtrSuccess) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
||||
/* key_rotation_enabled= */ true,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.GenerateEcm(
|
||||
@@ -168,10 +161,10 @@ TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvSuccess) {
|
||||
absl::BytesToHexString(actual_ecm));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm16BytesContentIvSuccess) {
|
||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm16BytesContentIvCtrSuccess) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
||||
/* key_rotation_enabled= */ false,
|
||||
/* crypto_mode= */ 1));
|
||||
CryptoMode::kAesCtr));
|
||||
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.GenerateSingleKeyEcm(
|
||||
@@ -188,5 +181,95 @@ TEST_F(WvCasEcmTest, GenerateSingleKeyEcm16BytesContentIvSuccess) {
|
||||
absl::BytesToHexString(actual_ecm));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvCbcSuccess) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
||||
/* key_rotation_enabled= */ true,
|
||||
CryptoMode::kAesCbc));
|
||||
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.GenerateEcm(
|
||||
/* even_key= */ kEvenKey,
|
||||
/* even_content_iv= */
|
||||
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
|
||||
/* odd_key= */ kOddKey,
|
||||
/* odd_content_iv= */
|
||||
absl::StrCat(kOddContentIv8Bytes, kOddContentIv8Bytes),
|
||||
/* entitlement_key_id= */ kEntitlementKeyId,
|
||||
/* entitlement_key= */ kEntitlementKey, &actual_ecm));
|
||||
|
||||
EXPECT_EQ(
|
||||
"4ad40105c0656e745f6b65795f69642e2e2e2e2e2ea5693deeba52b4cb27e7021eefa2f8"
|
||||
"c2b25f7d48e60627208f4ecca00703aa2467f28b214546a42320e3fa49f936369c657665"
|
||||
"6e636f6e746576656e636f6e74656e745f6b65795f69642e2e2e2e2e2e0700509b67763b"
|
||||
"3f1c356bc1e1dc8bac99a1e2f95c37d9183cbb96582f3a05fdbe29925c37c6c6a45eb552"
|
||||
"b5ddf87f8a6f6464636f6e742e6f6464636f6e742e",
|
||||
absl::BytesToHexString(actual_ecm));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm16BytesContentIvCbcSuccess) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
||||
/* key_rotation_enabled= */ false,
|
||||
CryptoMode::kAesCbc));
|
||||
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.GenerateSingleKeyEcm(
|
||||
/* even_key= */ kEvenKey,
|
||||
/* even_content_iv= */
|
||||
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
|
||||
/* entitlement_key_id= */ kEntitlementKeyId,
|
||||
/* entitlement_key= */ kEntitlementKey, &actual_ecm));
|
||||
|
||||
EXPECT_EQ(
|
||||
"4ad40104c0656e745f6b65795f69642e2e2e2e2e2ea5693deeba52b4cb27e7021eefa2f8"
|
||||
"c2b25f7d48e60627208f4ecca00703aa2467f28b214546a42320e3fa49f936369c657665"
|
||||
"6e636f6e746576656e636f6e74",
|
||||
absl::BytesToHexString(actual_ecm));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, GenerateEcm16BytesContentIvCsaSuccess) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
||||
/* key_rotation_enabled= */ true,
|
||||
CryptoMode::kDvbCsa));
|
||||
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.GenerateEcm(
|
||||
/* even_key= */ kEvenKey,
|
||||
/* even_content_iv= */
|
||||
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
|
||||
/* odd_key= */ kOddKey,
|
||||
/* odd_content_iv= */
|
||||
absl::StrCat(kOddContentIv8Bytes, kOddContentIv8Bytes),
|
||||
/* entitlement_key_id= */ kEntitlementKeyId,
|
||||
/* entitlement_key= */ kEntitlementKey, &actual_ecm));
|
||||
|
||||
EXPECT_EQ(
|
||||
"4ad40107c0656e745f6b65795f69642e2e2e2e2e2ea5693deeba52b4cb27e7021eefa2f8"
|
||||
"c2b25f7d48e60627208f4ecca00703aa2467f28b214546a42320e3fa49f936369c657665"
|
||||
"6e636f6e746576656e636f6e74656e745f6b65795f69642e2e2e2e2e2e0700509b67763b"
|
||||
"3f1c356bc1e1dc8bac99a1e2f95c37d9183cbb96582f3a05fdbe29925c37c6c6a45eb552"
|
||||
"b5ddf87f8a6f6464636f6e742e6f6464636f6e742e",
|
||||
absl::BytesToHexString(actual_ecm));
|
||||
}
|
||||
|
||||
TEST_F(WvCasEcmTest, GenerateSingleKeyEcm16BytesContentIvCsaSuccess) {
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.Initialize(/* content_iv_size= */ 16,
|
||||
/* key_rotation_enabled= */ false,
|
||||
CryptoMode::kDvbCsa));
|
||||
|
||||
std::string actual_ecm;
|
||||
EXPECT_EQ(OK, wv_cas_ecm_.GenerateSingleKeyEcm(
|
||||
/* even_key= */ kEvenKey,
|
||||
/* even_content_iv= */
|
||||
absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes),
|
||||
/* entitlement_key_id= */ kEntitlementKeyId,
|
||||
/* entitlement_key= */ kEntitlementKey, &actual_ecm));
|
||||
|
||||
EXPECT_EQ(
|
||||
"4ad40106c0656e745f6b65795f69642e2e2e2e2e2ea5693deeba52b4cb27e7021eefa2f8"
|
||||
"c2b25f7d48e60627208f4ecca00703aa2467f28b214546a42320e3fa49f936369c657665"
|
||||
"6e636f6e746576656e636f6e74",
|
||||
absl::BytesToHexString(actual_ecm));
|
||||
}
|
||||
|
||||
} // namespace cas
|
||||
} // namespace widevine
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "media_cas_packager_sdk/public/wv_cas_status.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
#include "base/macros.h"
|
||||
|
||||
@@ -37,5 +37,35 @@ std::string GetWvCasStatusMessage(WvCasStatus status) {
|
||||
return kWvCasStatusMessage[status];
|
||||
}
|
||||
|
||||
std::string CryptoModeToString(CryptoMode mode) {
|
||||
switch (mode) {
|
||||
case CryptoMode::kAesCtr: {
|
||||
return "kAesCtr";
|
||||
}
|
||||
case CryptoMode::kAesCbc: {
|
||||
return "kAesCbc";
|
||||
}
|
||||
case CryptoMode::kDvbCsa: {
|
||||
return "kDvbCsa";
|
||||
}
|
||||
default: {
|
||||
return "kCryptoModeUnspecified";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CryptoMode StringToCryptoMode(std::string str) {
|
||||
if (str == "kAesCtr") {
|
||||
return CryptoMode::kAesCtr;
|
||||
}
|
||||
if (str == "kAesCbc") {
|
||||
return CryptoMode::kAesCbc;
|
||||
}
|
||||
if (str == "kDvbCsa") {
|
||||
return CryptoMode::kDvbCsa;
|
||||
}
|
||||
return CryptoMode::kCryptoModeUnspecified;
|
||||
}
|
||||
|
||||
} // namespace cas
|
||||
} // namespace widevine
|
||||
@@ -6,8 +6,8 @@
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_STATUS_H_
|
||||
#define MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_STATUS_H_
|
||||
#ifndef MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_TYPES_H_
|
||||
#define MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_TYPES_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -50,7 +50,19 @@ enum WvCasStatus {
|
||||
// Returns the message std::string for the given WvCasStatus.
|
||||
std::string GetWvCasStatusMessage(WvCasStatus status);
|
||||
|
||||
// Crypto mode for encryption / decryption.
|
||||
enum class CryptoMode : int {
|
||||
kCryptoModeUnspecified = 0,
|
||||
kAesCtr = 1,
|
||||
kAesCbc = 2,
|
||||
kDvbCsa = 3
|
||||
};
|
||||
|
||||
std::string CryptoModeToString(CryptoMode mode);
|
||||
|
||||
CryptoMode StringToCryptoMode(std::string str);
|
||||
|
||||
} // namespace cas
|
||||
} // namespace widevine
|
||||
|
||||
#endif // MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_STATUS_H_
|
||||
#endif // MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_TYPES_H_
|
||||
@@ -6,14 +6,14 @@
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "media_cas_packager_sdk/public/wv_cas_status.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
#include "testing/gunit.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace cas {
|
||||
|
||||
TEST(WvCasStatusTest, GetWvCasStatusMessage) {
|
||||
TEST(WvCasTypesTest, GetWvCasStatusMessage) {
|
||||
EXPECT_EQ("OK", GetWvCasStatusMessage(OK));
|
||||
EXPECT_EQ("Invalid argument", GetWvCasStatusMessage(INVALID_ARGUMENT));
|
||||
EXPECT_EQ("Not found", GetWvCasStatusMessage(NOT_FOUND));
|
||||
@@ -24,5 +24,21 @@ TEST(WvCasStatusTest, GetWvCasStatusMessage) {
|
||||
EXPECT_EQ("Unavailable", GetWvCasStatusMessage(UNAVAILABLE));
|
||||
}
|
||||
|
||||
TEST(WvCasTypesTest, CryptoModeToString) {
|
||||
EXPECT_EQ("kAesCtr", CryptoModeToString(CryptoMode::kAesCtr));
|
||||
EXPECT_EQ("kAesCbc", CryptoModeToString(CryptoMode::kAesCbc));
|
||||
EXPECT_EQ("kDvbCsa", CryptoModeToString(CryptoMode::kDvbCsa));
|
||||
EXPECT_EQ("kCryptoModeUnspecified",
|
||||
CryptoModeToString(CryptoMode::kCryptoModeUnspecified));
|
||||
}
|
||||
|
||||
TEST(WvCasTypesTest, StringToCryptoMode) {
|
||||
EXPECT_EQ(CryptoMode::kAesCtr, StringToCryptoMode("kAesCtr"));
|
||||
EXPECT_EQ(CryptoMode::kAesCbc, StringToCryptoMode("kAesCbc"));
|
||||
EXPECT_EQ(CryptoMode::kDvbCsa, StringToCryptoMode("kDvbCsa"));
|
||||
EXPECT_EQ(CryptoMode::kCryptoModeUnspecified,
|
||||
StringToCryptoMode("wrong crypto mode"));
|
||||
}
|
||||
|
||||
} // namespace cas
|
||||
} // namespace widevine
|
||||
Reference in New Issue
Block a user