Chromium Code Reviews| Index: media/cdm/json_web_key.cc |
| diff --git a/media/cdm/json_web_key.cc b/media/cdm/json_web_key.cc |
| index cd50a8c2e01397e7ddebdff9c1cfc7a9cb7c1f2d..18487bb4c176fbe5338f8ef4081dd2001386d90a 100644 |
| --- a/media/cdm/json_web_key.cc |
| +++ b/media/cdm/json_web_key.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/json/string_escape.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_util.h" |
| #include "base/values.h" |
| @@ -226,6 +227,70 @@ bool ExtractKeysFromJWKSet(const std::string& jwk_set, |
| return true; |
| } |
| +bool ExtractKeyIdsFromKeyIdsInitData(const std::string& input, |
| + KeyIdList* key_ids, |
| + std::string* error_message) { |
| + if (!base::IsStringASCII(input)) { |
| + error_message->assign("Non ASCII: "); |
| + error_message->append(input); |
|
sandersd (OOO until July 31)
2015/03/04 01:04:21
Is it wise to have arbitrarily large error message
jrummell
2015/03/04 01:28:52
Good catch. Done.
|
| + return false; |
| + } |
| + |
| + scoped_ptr<base::Value> root(base::JSONReader().ReadToValue(input)); |
| + if (!root.get() || root->GetType() != base::Value::TYPE_DICTIONARY) { |
| + error_message->assign("Not valid JSON: "); |
| + error_message->append(input); |
| + return false; |
| + } |
| + |
| + // Locate the set from the dictionary. |
| + base::DictionaryValue* dictionary = |
| + static_cast<base::DictionaryValue*>(root.get()); |
| + base::ListValue* list_val = NULL; |
| + if (!dictionary->GetList(kKeyIdsTag, &list_val)) { |
| + error_message->assign("Missing '"); |
| + error_message->append(kKeyIdsTag); |
| + error_message->append("' parameter or not a list"); |
| + return false; |
| + } |
| + |
| + // Create a local list of key ids, so that |key_ids| only gets updated on |
| + // success. |
| + KeyIdList local_key_ids; |
| + for (size_t i = 0; i < list_val->GetSize(); ++i) { |
| + std::string encoded_key_id; |
| + if (!list_val->GetString(i, &encoded_key_id)) { |
| + error_message->assign("Unable to access '"); |
|
sandersd (OOO until July 31)
2015/03/04 01:04:21
Presumably this happens only when the value at tha
jrummell
2015/03/04 01:28:52
Done.
|
| + error_message->append(kKeyIdsTag); |
| + error_message->append("'["); |
| + error_message->append(base::UintToString(i)); |
| + error_message->append("]"); |
| + return false; |
| + } |
| + |
| + // Key ID is a base64-encoded string, so decode it. |
| + std::string raw_key_id = DecodeBase64Url(encoded_key_id); |
| + if (raw_key_id.empty()) { |
| + error_message->assign("'"); |
| + error_message->append(kKeyIdsTag); |
| + error_message->append("'["); |
| + error_message->append(base::UintToString(i)); |
| + error_message->append("] is not valid base64url encoded. Value: "); |
| + error_message->append(encoded_key_id); |
| + return false; |
| + } |
| + |
| + // Add the decoded key ID to the list. |
| + local_key_ids.push_back(std::vector<uint8>( |
| + raw_key_id.data(), raw_key_id.data() + raw_key_id.length())); |
| + } |
| + |
| + // All done. |
| + key_ids->swap(local_key_ids); |
| + error_message->clear(); |
| + return true; |
| +} |
| + |
| void CreateLicenseRequest(const KeyIdList& key_ids, |
| MediaKeys::SessionType session_type, |
| std::vector<uint8>* license) { |