42 auto iter = encryption_key_map_.find(stream_label);
43 if (iter == encryption_key_map_.end()) {
44 iter = encryption_key_map_.find(kEmptyDrmLabel);
45 if (iter == encryption_key_map_.end()) {
46 return Status(error::NOT_FOUND,
47 "Key for '" + stream_label +
"' was not found.");
70 uint32_t crypto_period_index,
71 int32_t crypto_period_duration_in_seconds,
72 const std::string& stream_label,
74 UNUSED(crypto_period_duration_in_seconds);
76 RETURN_IF_ERROR(
GetKey(stream_label, key));
83 <<
"This naive key rotation algorithm should not be used in production.";
84 std::rotate(key->
key_id.begin(),
85 key->
key_id.begin() + (crypto_period_index % key->
key_id.size()),
87 std::rotate(key->key.begin(),
88 key->key.begin() + (crypto_period_index % key->key.size()),
97 const RawKeyParams& raw_key) {
98 std::vector<ProtectionSystemSpecificInfo> key_system_info;
99 if (!raw_key.pssh.empty()) {
101 raw_key.pssh.data(), raw_key.pssh.size(), &key_system_info)) {
102 LOG(ERROR) <<
"--pssh argument should be full PSSH boxes.";
103 return std::unique_ptr<RawKeySource>();
107 std::vector<std::vector<uint8_t>> key_ids;
108 for (
const auto& entry : raw_key.key_map)
109 key_ids.emplace_back(entry.second.key_id);
111 EncryptionKeyMap encryption_key_map;
112 for (
const auto& entry : raw_key.key_map) {
113 const std::string& drm_label = entry.first;
114 const RawKeyParams::KeyInfo& key_pair = entry.second;
116 if (key_pair.key_id.size() != 16) {
117 LOG(ERROR) <<
"Invalid key ID size '" << key_pair.key_id.size()
118 <<
"', must be 16 bytes.";
119 return std::unique_ptr<RawKeySource>();
121 if (key_pair.key.size() != 16) {
123 LOG(ERROR) <<
"Invalid key size '" << key_pair.key.size()
124 <<
"', must be 16 bytes.";
125 return std::unique_ptr<RawKeySource>();
127 if (!key_pair.iv.empty() && key_pair.iv.size() != 8 && key_pair.iv.size() != 16) {
128 LOG(ERROR) <<
"Invalid IV '" << key_pair.iv.size()
129 <<
"', must be 8 or 16 bytes.";
130 return std::unique_ptr<RawKeySource>();
133 std::unique_ptr<EncryptionKey> encryption_key(
new EncryptionKey);
134 encryption_key->key_id = key_pair.key_id;
135 encryption_key->key_ids = key_ids;
136 encryption_key->key = key_pair.key;
137 encryption_key->iv = (key_pair.iv.empty()) ? raw_key.iv : key_pair.iv;
138 encryption_key->key_system_info = key_system_info;
139 encryption_key_map[drm_label] = std::move(encryption_key);
142 return std::unique_ptr<RawKeySource>(