Print uint16 as \x01 not \x1

-------------
Allow the usage of different entitlement keys to wrap even vs. odd key.

-------------
(1) Change parameter type from 'string' to 'const char* const' to handle possible '\x00' (Nul char) byte in the input.
(2) Check size of generated ECM string, return error if the size is not as expected.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=220172089
This commit is contained in:
Widevine Buildbot
2018-11-05 22:29:44 +00:00
parent 548fe9a335
commit 081bc9d064
4 changed files with 62 additions and 53 deletions

View File

@@ -14,32 +14,32 @@
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
#include "media_cas_packager_sdk/public/wv_cas_types.h"
const bool kKeyRotationEnabled = true;
const char kEvenKey[] = "even_content_key"; // 16 bytes
const char kCsaEvenKey[] = "12345678"; // 8 bytes
const char kEvenContentIv8Bytes[] = "evencont"; // 8 bytes
const char kEvenContentIv16Bytes[] = "evencontevencont"; // 16 bytes
const char kOddKey[] = "odd_content_key."; // 16 bytes
const char kCsaOddKey[] = "87654321"; // 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 kEntitlementKey[] = "entitlement_key................."; // 32 bytes
const char kCsaEvenKey[] = "even_key"; // 8 bytes
const char kEvenContentIv8Bytes[] = "even_iv."; // 8 bytes
const char kEvenEntitlementKeyId[] = "fake_key_id1...."; // 16 bytes
const char kEvenEntitlementKey[] =
"fakefakefakefakefakefakefake1..."; // 32 bytes
const char kCsaOddKey[] = "odd_key."; // 8 bytes
const char kOddContentIv8Bytes[] = "odd_iv.."; // 8 bytes
const char kOddEntitlementKeyId[] = "fake_key_id2...."; // 16 bytes
const char kOddEntitlementKey[] =
"fakefakefakefakefakefakefake2..."; // 32 bytes
int main(int argc, char **argv) {
widevine::cas::WvCasEcm wv_cas_ecm;
widevine::cas::WvCasStatus status =
wv_cas_ecm.Initialize(/* content_iv_size= */ 8, kKeyRotationEnabled,
widevine::cas::CryptoMode::kDvbCsa2);
widevine::cas::WvCasStatus status = wv_cas_ecm.Initialize(
/* content_iv_size= */ 8, /* key_rotation_enabled= */ true,
widevine::cas::CryptoMode::kDvbCsa2);
if (status != widevine::cas::OK) {
std::cerr << "Failed to initialize WV CAS ECM, error: "
<< widevine::cas::GetWvCasStatusMessage(status)
<< std::endl;
}
std::string ecm;
status = wv_cas_ecm.GenerateEcm(kCsaEvenKey, kEvenContentIv8Bytes, kCsaOddKey,
kOddContentIv8Bytes, kEntitlementKeyId,
kEntitlementKey, &ecm);
status = wv_cas_ecm.GenerateEcm(
kCsaEvenKey, kEvenContentIv8Bytes, kEvenEntitlementKeyId,
kEvenEntitlementKey, kCsaOddKey, kOddContentIv8Bytes,
kOddEntitlementKeyId, kOddEntitlementKey, &ecm);
if (status != widevine::cas::OK) {
std::cerr << "Failed to generate WV CAS ECM, error: "
<< widevine::cas::GetWvCasStatusMessage(status)
@@ -48,7 +48,7 @@ int main(int argc, char **argv) {
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)));
printf("'\\x%02x', ", static_cast<uint16_t>(ecm.at(i)));
}
std::cout << std::endl;
}