Shaka Packager SDK
Loading...
Searching...
No Matches
cpix_encryption_flags.cc
1// Copyright 2026 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// Defines command line flags for CPIX encryption.
8
9#include <packager/app/cpix_encryption_flags.h>
10
11#include <string>
12
13#include <absl/flags/flag.h>
14
15#include <packager/app/validate_flag.h>
16
17ABSL_FLAG(bool,
18 enable_cpix_encryption,
19 false,
20 "Enable encryption with keys from a CPIX document (DASH-IF Content "
21 "Protection Information Exchange). Keys, DRM signaling (PSSH) and "
22 "key to stream mapping are read from the document. Note that DRM "
23 "signaling comes from the document's DRMSystemList; "
24 "--protection_systems may be used to generate signaling for "
25 "additional protection systems.");
26ABSL_FLAG(bool,
27 enable_cpix_decryption,
28 false,
29 "Enable decryption with keys from a CPIX document. Keys are looked "
30 "up by key ID, so the document's usage rules are not used.");
31ABSL_FLAG(std::string, cpix, "", "Path or URL to the CPIX document.");
32ABSL_FLAG(std::string,
33 cpix_request_file,
34 "",
35 "Optional path to a CPIX request document. If set, --cpix must be "
36 "an HTTP(S) URL; the request document is POSTed to it and the "
37 "response is used as the CPIX document (SPEKE style exchange).");
38ABSL_FLAG(std::string,
39 cpix_headers,
40 "",
41 "Optional semicolon separated list of HTTP headers in 'Name: "
42 "value' form to send when fetching the CPIX document, e.g. for "
43 "authentication.");
44ABSL_FLAG(std::string,
45 cpix_private_key,
46 "",
47 "Optional path to the recipient RSA private key (PEM or DER), "
48 "used to decrypt encrypted CPIX documents. Required when the "
49 "document's content keys are encrypted.");
50
51namespace shaka {
52
54 bool success = true;
55
56 const bool cpix_crypto = absl::GetFlag(FLAGS_enable_cpix_encryption) ||
57 absl::GetFlag(FLAGS_enable_cpix_decryption);
58 if (!ValidateFlag("cpix", absl::GetFlag(FLAGS_cpix), cpix_crypto,
59 /* optional= */ false,
60 "--enable_cpix_encryption/decryption")) {
61 success = false;
62 }
63 if (!ValidateFlag("cpix_request_file", absl::GetFlag(FLAGS_cpix_request_file),
64 cpix_crypto,
65 /* optional= */ true,
66 "--enable_cpix_encryption/decryption")) {
67 success = false;
68 }
69 if (!ValidateFlag("cpix_headers", absl::GetFlag(FLAGS_cpix_headers),
70 cpix_crypto, /* optional= */ true,
71 "--enable_cpix_encryption/decryption")) {
72 success = false;
73 }
74 if (!ValidateFlag("cpix_private_key", absl::GetFlag(FLAGS_cpix_private_key),
75 cpix_crypto, /* optional= */ true,
76 "--enable_cpix_encryption/decryption")) {
77 success = false;
78 }
79 return success;
80}
81
82} // namespace shaka
All the methods that are virtual are virtual for mocking.
bool ValidateFlag(const char *flag_name, const FlagType &flag_value, bool condition, bool optional, const char *label)
bool ValidateCpixCryptoFlags()