(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:
Fang Yu
2018-10-26 11:20:39 -07:00
parent d2f5df0c9f
commit 70f62ed75e
5 changed files with 142 additions and 164 deletions

View File

@@ -48,8 +48,6 @@ cc_binary(
srcs = ["wv_cas_ecm_example.cc"],
deps = [
"//base",
"@abseil_repo//absl/strings",
"//util:status",
"//media_cas_packager_sdk/public:wv_cas_ecm",
],
)

View File

@@ -8,47 +8,43 @@
// Example of how to use the wv_cas_ecm library.
#include <iostream>
#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"
const int kContentIvSize = 16;
const bool kKeyRotationEnabled = true;
const int kCryptoMode = 1; // CTR
const char kEvenKey[] = "even_content_key"; // 16 bytes
const char kEvenContentIv8Bytes[] = "evencont"; // 8 bytes
const char kEvenContentIv16Bytes[] = "evencontevencont"; // 16 bytes
const char kOddKey[] = "odd_content_key."; // 16 bytes
const char kOddContentIv8Bytes[] = "oddcont."; // 8 bytes
const char kOddContentIv16Bytes[] = "oddcont.oddcont."; // 16 bytes
const char kEntitlementKeyId[] = "ent_key_id......"; // 16 bytes
const char kEntitlementKey[] = "entitlement_key................."; // 32 bytes
int main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
widevine::cas::WvCasEcm wv_cas_ecm;
auto status = wv_cas_ecm.Initialize(/* content_iv_size= */ 16,
/* key_rotation_enabled= */ true,
/* crypto_mode= */ 1);
if (!status.ok()) {
LOG(FATAL) << "Failed to initialize WV CAS ECM, error: " << status;
bool status =
wv_cas_ecm.Initialize(kContentIvSize, kKeyRotationEnabled, kCryptoMode);
if (!status) {
std::cerr << "Failed to initialize WV CAS ECM, error." << std::endl;
}
std::string ecm;
status = 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, &ecm);
if (!status.ok()) {
LOG(FATAL) << "Failed to generate WV CAS ECM, error: " << status;
status = wv_cas_ecm.GenerateEcm(kEvenKey, kEvenContentIv16Bytes, kOddKey,
kOddContentIv16Bytes, kEntitlementKeyId,
kEntitlementKey, &ecm);
if (!status) {
std::cerr << "Failed to generate WV CAS ECM, error" << std::endl;
} else {
LOG(INFO) << "Generated WV CAS ECM (in hex): "
<< absl::BytesToHexString(ecm);
std::cout << "ECM size: " << ecm.size() << std::endl;
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;