diff --git a/example/wv_cas_ecm_example b/example/wv_cas_ecm_example index 7cce9e4..6df5af8 100644 Binary files a/example/wv_cas_ecm_example and b/example/wv_cas_ecm_example differ diff --git a/example/wv_cas_ecm_example.cc b/example/wv_cas_ecm_example.cc index 3b5a1f3..2d94154 100644 --- a/example/wv_cas_ecm_example.cc +++ b/example/wv_cas_ecm_example.cc @@ -8,47 +8,43 @@ // Example of how to use the wv_cas_ecm library. +#include #include -#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(ecm.at(i))); + } + std::cout << std::endl; } return 0; diff --git a/libmedia_cas_packager_sdk.so b/libmedia_cas_packager_sdk.so index 57b2812..8c68942 100755 Binary files a/libmedia_cas_packager_sdk.so and b/libmedia_cas_packager_sdk.so differ diff --git a/media_cas_packager_sdk/public/wv_cas_ecm.h b/media_cas_packager_sdk/public/wv_cas_ecm.h index b59f785..020bffd 100644 --- a/media_cas_packager_sdk/public/wv_cas_ecm.h +++ b/media_cas_packager_sdk/public/wv_cas_ecm.h @@ -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;