2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2017-03-28 15:19:15 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/app/crypto_flags.h>
|
2017-03-28 15:19:15 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <cstdio>
|
2017-03-28 15:19:15 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <absl/flags/flag.h>
|
|
|
|
|
|
|
|
ABSL_FLAG(std::string,
|
|
|
|
protection_scheme,
|
|
|
|
"cenc",
|
|
|
|
"Specify a protection scheme, 'cenc' or 'cbc1' or pattern-based "
|
|
|
|
"protection schemes 'cens' or 'cbcs'.");
|
|
|
|
ABSL_FLAG(
|
|
|
|
int32_t,
|
2020-02-10 08:31:45 +00:00
|
|
|
crypt_byte_block,
|
|
|
|
1,
|
|
|
|
"Specify the count of the encrypted blocks in the protection pattern, "
|
|
|
|
"where block is of size 16-bytes. There are three common "
|
|
|
|
"patterns (crypt_byte_block:skip_byte_block): 1:9 (default), 5:5, 10:0. "
|
|
|
|
"Apply to video streams with 'cbcs' and 'cens' protection schemes only; "
|
|
|
|
"ignored otherwise.");
|
2023-12-01 17:32:19 +00:00
|
|
|
ABSL_FLAG(
|
|
|
|
int32_t,
|
2020-02-10 08:31:45 +00:00
|
|
|
skip_byte_block,
|
|
|
|
9,
|
|
|
|
"Specify the count of the unencrypted blocks in the protection pattern. "
|
|
|
|
"Apply to video streams with 'cbcs' and 'cens' protection schemes only; "
|
|
|
|
"ignored otherwise.");
|
2023-12-01 17:32:19 +00:00
|
|
|
ABSL_FLAG(bool,
|
|
|
|
vp9_subsample_encryption,
|
|
|
|
true,
|
|
|
|
"Enable VP9 subsample encryption.");
|
|
|
|
ABSL_FLAG(std::string,
|
|
|
|
playready_extra_header_data,
|
|
|
|
"",
|
|
|
|
"Extra XML data to add to PlayReady headers.");
|
2020-02-10 08:31:45 +00:00
|
|
|
|
|
|
|
bool ValueNotGreaterThanTen(const char* flagname, int32_t value) {
|
|
|
|
if (value > 10) {
|
|
|
|
fprintf(stderr, "ERROR: %s must not be greater than 10.\n", flagname);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (value < 0) {
|
|
|
|
fprintf(stderr, "ERROR: %s must be non-negative.\n", flagname);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-09 20:50:55 +00:00
|
|
|
bool ValueIsXml(const char* flagname, const std::string& value) {
|
|
|
|
if (value.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (value[0] != '<' || value[value.size() - 1] != '>') {
|
|
|
|
fprintf(stderr, "ERROR: %s must be valid XML.\n", flagname);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
namespace shaka {
|
|
|
|
bool ValidateCryptoFlags() {
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
auto crypt_byte_block = absl::GetFlag(FLAGS_crypt_byte_block);
|
|
|
|
if (!ValueNotGreaterThanTen("crypt_byte_block", crypt_byte_block)) {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto skip_byte_block = absl::GetFlag(FLAGS_skip_byte_block);
|
|
|
|
if (!ValueNotGreaterThanTen("skip_byte_block", skip_byte_block)) {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto playready_extra_header_data =
|
|
|
|
absl::GetFlag(FLAGS_playready_extra_header_data);
|
|
|
|
if (!ValueIsXml("playready_extra_header_data", playready_extra_header_data)) {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
} // namespace shaka
|