(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. // 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;

Binary file not shown.

View File

@@ -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, const std::string& entitlement_key, std::string* ecm) const;
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,12 +91,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 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,