(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:
Widevine Buildbot
2018-10-26 18:26:35 +00:00
parent 770fdbd1cc
commit bdb15b6393
4 changed files with 36 additions and 42 deletions

Binary file not shown.

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;

Binary file not shown.

View File

@@ -47,12 +47,12 @@ class WvCasEcm {
// only CTR is supported by Widevine CAS plugin for now
//
// Returns:
// - A status indicating whether there was any error during initialization
// - A boolean indicating whether there was any error during initialization
//
// Note:
// - 'even'/'odd' key in the ECM will be be encrypted using AEC_CBC
virtual util::Status Initialize(int content_iv_size,
bool key_rotation_enabled, int crypto_mode);
virtual bool Initialize(int content_iv_size, bool key_rotation_enabled,
int crypto_mode);
// Generate an ECM containing two keys (even and odd). Can be called when
// |key_rotation_enabled| is initialized to 'true'.
@@ -67,20 +67,18 @@ class WvCasEcm {
// - |ecm| for returning the generated ECM, must not be nullptr
//
// Returns:
// - A status indicating whether there was any error during processing
// - A boolean indicating whether there was any error during processing
//
// Note:
// - The same |entitlement_key| will be used to encrypt both |even_key|
// and |odd_key| in the ECM
// - Size of |even_content_iv| and |odd_content_iv| must match
// |content_iv_size| set during initialization
virtual util::Status GenerateEcm(const std::string& even_key,
const std::string& even_content_iv,
const std::string& odd_key,
const std::string& odd_content_iv,
const std::string& entitlement_key_id,
const std::string& entitlement_key,
std::string* ecm) const;
virtual bool GenerateEcm(const std::string& even_key,
const std::string& even_content_iv, const std::string& odd_key,
const std::string& odd_content_iv,
const std::string& entitlement_key_id,
const std::string& entitlement_key, std::string* ecm) const;
// Generate an ECM containing only a singe even key. Can be called when
// |key_rotation_enabled| is initialized to 'false'.
@@ -93,16 +91,16 @@ class WvCasEcm {
// - |ecm| for returning the generated ECM, must not be nullptr
//
// Returns:
// - A status indicating whether there was any error during processing
// - A boolean indicating whether there was any error during processing
//
// Note:
// - Size of |even_content_iv| and |odd_content_iv| must match
// |content_iv_size| set during initialization
virtual util::Status GenerateSingleKeyEcm(const std::string& even_key,
const std::string& even_content_iv,
const std::string& entitlement_key_id,
const std::string& entitlement_key,
std::string* ecm) const;
virtual bool GenerateSingleKeyEcm(const std::string& even_key,
const std::string& even_content_iv,
const std::string& entitlement_key_id,
const std::string& entitlement_key,
std::string* ecm) const;
private:
bool initialized_ = false;