Shaka Packager SDK
Loading...
Searching...
No Matches
crypto_flags.cc
1// Copyright 2017 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#include <packager/app/crypto_flags.h>
8
9#include <cstdio>
10
11#include <absl/flags/flag.h>
12
13ABSL_FLAG(std::string,
14 protection_scheme,
15 "cenc",
16 "Specify a protection scheme, 'cenc' or 'cbc1' or pattern-based "
17 "protection schemes 'cens' or 'cbcs', or 'aes128' for HLS AES-128 "
18 "full-segment CBC encryption (TS/HLS only, no DRM system required).");
19ABSL_FLAG(
20 int32_t,
21 crypt_byte_block,
22 1,
23 "Specify the count of the encrypted blocks in the protection pattern, "
24 "where block is of size 16-bytes. There are three common "
25 "patterns (crypt_byte_block:skip_byte_block): 1:9 (default), 5:5, 10:0. "
26 "Apply to video streams with 'cbcs' and 'cens' protection schemes only; "
27 "ignored otherwise.");
28ABSL_FLAG(
29 int32_t,
30 skip_byte_block,
31 9,
32 "Specify the count of the unencrypted blocks in the protection pattern. "
33 "Apply to video streams with 'cbcs' and 'cens' protection schemes only; "
34 "ignored otherwise.");
35ABSL_FLAG(bool,
36 vp9_subsample_encryption,
37 true,
38 "Enable VP9 subsample encryption.");
39ABSL_FLAG(bool,
40 cencv1,
41 false,
42 "Use CENC v1 (2012) instead of v3 (2016+) for encryption.");
43ABSL_FLAG(std::string,
44 playready_extra_header_data,
45 "",
46 "Extra XML data to add to PlayReady headers.");
47
48bool ValueNotGreaterThanTen(const char* flagname, int32_t value) {
49 if (value > 10) {
50 fprintf(stderr, "ERROR: %s must not be greater than 10.\n", flagname);
51 return false;
52 }
53 if (value < 0) {
54 fprintf(stderr, "ERROR: %s must be non-negative.\n", flagname);
55 return false;
56 }
57 return true;
58}
59
60bool ValueIsXml(const char* flagname, const std::string& value) {
61 if (value.empty())
62 return true;
63
64 if (value[0] != '<' || value[value.size() - 1] != '>') {
65 fprintf(stderr, "ERROR: %s must be valid XML.\n", flagname);
66 return false;
67 }
68 return true;
69}
70
71namespace shaka {
72bool ValidateCryptoFlags() {
73 bool success = true;
74
75 auto cencv1 = absl::GetFlag(FLAGS_cencv1);
76 auto scheme = absl::GetFlag(FLAGS_protection_scheme);
77 if (cencv1 && scheme != "cenc") {
78 fprintf(stderr, "ERROR: CENC v1 only supports 'cenc' scheme.\n");
79 success = false;
80 }
81
82 auto crypt_byte_block = absl::GetFlag(FLAGS_crypt_byte_block);
83 if (!ValueNotGreaterThanTen("crypt_byte_block", crypt_byte_block)) {
84 success = false;
85 }
86
87 auto skip_byte_block = absl::GetFlag(FLAGS_skip_byte_block);
88 if (!ValueNotGreaterThanTen("skip_byte_block", skip_byte_block)) {
89 success = false;
90 }
91
92 auto playready_extra_header_data =
93 absl::GetFlag(FLAGS_playready_extra_header_data);
94 if (!ValueIsXml("playready_extra_header_data", playready_extra_header_data)) {
95 success = false;
96 }
97
98 return success;
99}
100} // namespace shaka
All the methods that are virtual are virtual for mocking.