50 auto iter = encryption_key_map_.find(stream_label);
51 if (iter == encryption_key_map_.end()) {
52 iter = encryption_key_map_.find(kEmptyDrmLabel);
53 if (iter == encryption_key_map_.end()) {
54 return Status(error::NOT_FOUND,
55 "Key for '" + stream_label +
"' was not found.");
78 uint32_t crypto_period_index,
79 int32_t crypto_period_duration_in_seconds,
80 const std::string& stream_label,
82 UNUSED(crypto_period_duration_in_seconds);
84 RETURN_IF_ERROR(
GetKey(stream_label, key));
91 <<
"This naive key rotation algorithm should not be used in production.";
92 std::rotate(key->
key_id.begin(),
93 key->
key_id.begin() + (crypto_period_index % key->
key_id.size()),
95 std::rotate(key->key.begin(),
96 key->key.begin() + (crypto_period_index % key->key.size()),
105 const RawKeyParams& raw_key) {
106 std::vector<ProtectionSystemSpecificInfo> key_system_info;
107 if (!raw_key.pssh.empty()) {
109 raw_key.pssh.data(), raw_key.pssh.size(), &key_system_info)) {
110 LOG(ERROR) <<
"--pssh argument should be full PSSH boxes.";
111 return std::unique_ptr<RawKeySource>();
115 std::vector<std::vector<uint8_t>> key_ids;
116 for (
const auto& entry : raw_key.key_map)
117 key_ids.emplace_back(entry.second.key_id);
119 EncryptionKeyMap encryption_key_map;
120 for (
const auto& entry : raw_key.key_map) {
121 const std::string& drm_label = entry.first;
122 const RawKeyParams::KeyInfo& key_pair = entry.second;
124 if (key_pair.key_id.size() != 16) {
125 LOG(ERROR) <<
"Invalid key ID size '" << key_pair.key_id.size()
126 <<
"', must be 16 bytes.";
127 return std::unique_ptr<RawKeySource>();
129 if (key_pair.key.size() != 16) {
131 LOG(ERROR) <<
"Invalid key size '" << key_pair.key.size()
132 <<
"', must be 16 bytes.";
133 return std::unique_ptr<RawKeySource>();
135 if (!key_pair.iv.empty() && key_pair.iv.size() != 8 &&
136 key_pair.iv.size() != 16) {
137 LOG(ERROR) <<
"Invalid IV '" << key_pair.iv.size()
138 <<
"', must be 8 or 16 bytes.";
139 return std::unique_ptr<RawKeySource>();
142 std::unique_ptr<EncryptionKey> encryption_key(
new EncryptionKey);
143 encryption_key->key_id = key_pair.key_id;
144 encryption_key->key_ids = key_ids;
145 encryption_key->key = key_pair.key;
146 encryption_key->iv = (key_pair.iv.empty()) ? raw_key.iv : key_pair.iv;
147 encryption_key->key_system_info = key_system_info;
148 encryption_key_map[drm_label] = std::move(encryption_key);
151 return std::unique_ptr<RawKeySource>(