OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_CDM_JSON_WEB_KEY_H_ | 5 #ifndef MEDIA_CDM_JSON_WEB_KEY_H_ |
6 #define MEDIA_CDM_JSON_WEB_KEY_H_ | 6 #define MEDIA_CDM_JSON_WEB_KEY_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "media/base/content_decryption_module.h" |
14 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
15 #include "media/base/media_keys.h" | |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
19 // The ClearKey license request format is a JSON object containing the following | 19 // The ClearKey license request format is a JSON object containing the following |
20 // members (http://w3c.github.io/encrypted-media/#clear-key-request-format): | 20 // members (http://w3c.github.io/encrypted-media/#clear-key-request-format): |
21 // "kids" : An array of key IDs. Each element of the array is the base64url | 21 // "kids" : An array of key IDs. Each element of the array is the base64url |
22 // encoding of the octet sequence containing the key ID value. | 22 // encoding of the octet sequence containing the key ID value. |
23 // "type" : The requested MediaKeySessionType. | 23 // "type" : The requested MediaKeySessionType. |
24 // An example: | 24 // An example: |
25 // { "kids":["67ef0gd8pvfd0","77ef0gd8pvfd0"], "type":"temporary" } | 25 // { "kids":["67ef0gd8pvfd0","77ef0gd8pvfd0"], "type":"temporary" } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 typedef std::pair<std::string, std::string> KeyIdAndKeyPair; | 57 typedef std::pair<std::string, std::string> KeyIdAndKeyPair; |
58 typedef std::vector<KeyIdAndKeyPair> KeyIdAndKeyPairs; | 58 typedef std::vector<KeyIdAndKeyPair> KeyIdAndKeyPairs; |
59 | 59 |
60 // Converts a single |key|, |key_id| pair to a JSON Web Key Set. | 60 // Converts a single |key|, |key_id| pair to a JSON Web Key Set. |
61 MEDIA_EXPORT std::string GenerateJWKSet(const uint8_t* key, | 61 MEDIA_EXPORT std::string GenerateJWKSet(const uint8_t* key, |
62 int key_length, | 62 int key_length, |
63 const uint8_t* key_id, | 63 const uint8_t* key_id, |
64 int key_id_length); | 64 int key_id_length); |
65 | 65 |
66 // Converts a set of |key|, |key_id| pairs to a JSON Web Key Set. | 66 // Converts a set of |key|, |key_id| pairs to a JSON Web Key Set. |
67 MEDIA_EXPORT std::string GenerateJWKSet(const KeyIdAndKeyPairs& keys, | 67 MEDIA_EXPORT std::string GenerateJWKSet( |
68 MediaKeys::SessionType session_type); | 68 const KeyIdAndKeyPairs& keys, |
| 69 ContentDecryptionModule::SessionType session_type); |
69 | 70 |
70 // Extracts the JSON Web Keys from a JSON Web Key Set. If |input| looks like | 71 // Extracts the JSON Web Keys from a JSON Web Key Set. If |input| looks like |
71 // a valid JWK Set, then true is returned and |keys| and |session_type| are | 72 // a valid JWK Set, then true is returned and |keys| and |session_type| are |
72 // updated to contain the values found. Otherwise return false. | 73 // updated to contain the values found. Otherwise return false. |
73 MEDIA_EXPORT bool ExtractKeysFromJWKSet(const std::string& jwk_set, | 74 MEDIA_EXPORT bool ExtractKeysFromJWKSet( |
74 KeyIdAndKeyPairs* keys, | 75 const std::string& jwk_set, |
75 MediaKeys::SessionType* session_type); | 76 KeyIdAndKeyPairs* keys, |
| 77 ContentDecryptionModule::SessionType* session_type); |
76 | 78 |
77 // Extracts the Key Ids from a Key IDs Initialization Data | 79 // Extracts the Key Ids from a Key IDs Initialization Data |
78 // (https://w3c.github.io/encrypted-media/keyids-format.html). If |input| looks | 80 // (https://w3c.github.io/encrypted-media/keyids-format.html). If |input| looks |
79 // valid, then true is returned and |key_ids| is updated to contain the values | 81 // valid, then true is returned and |key_ids| is updated to contain the values |
80 // found. Otherwise return false and |error_message| contains the reason. | 82 // found. Otherwise return false and |error_message| contains the reason. |
81 MEDIA_EXPORT bool ExtractKeyIdsFromKeyIdsInitData(const std::string& input, | 83 MEDIA_EXPORT bool ExtractKeyIdsFromKeyIdsInitData(const std::string& input, |
82 KeyIdList* key_ids, | 84 KeyIdList* key_ids, |
83 std::string* error_message); | 85 std::string* error_message); |
84 | 86 |
85 // Creates a license request message for the |key_ids| and |session_type| | 87 // Creates a license request message for the |key_ids| and |session_type| |
86 // specified. |license| is updated to contain the resulting JSON string. | 88 // specified. |license| is updated to contain the resulting JSON string. |
87 MEDIA_EXPORT void CreateLicenseRequest(const KeyIdList& key_ids, | 89 MEDIA_EXPORT void CreateLicenseRequest( |
88 MediaKeys::SessionType session_type, | 90 const KeyIdList& key_ids, |
89 std::vector<uint8_t>* license); | 91 ContentDecryptionModule::SessionType session_type, |
| 92 std::vector<uint8_t>* license); |
90 | 93 |
91 // Creates a keyIDs init_data message for the |key_ids| specified. | 94 // Creates a keyIDs init_data message for the |key_ids| specified. |
92 // |key_ids_init_data| is updated to contain the resulting JSON string. | 95 // |key_ids_init_data| is updated to contain the resulting JSON string. |
93 MEDIA_EXPORT void CreateKeyIdsInitData(const KeyIdList& key_ids, | 96 MEDIA_EXPORT void CreateKeyIdsInitData(const KeyIdList& key_ids, |
94 std::vector<uint8_t>* key_ids_init_data); | 97 std::vector<uint8_t>* key_ids_init_data); |
95 | 98 |
96 // Extract the first key from the license request message. Returns true if | 99 // Extract the first key from the license request message. Returns true if |
97 // |license| is a valid license request and contains at least one key, | 100 // |license| is a valid license request and contains at least one key, |
98 // otherwise false and |first_key| is not touched. | 101 // otherwise false and |first_key| is not touched. |
99 MEDIA_EXPORT bool ExtractFirstKeyIdFromLicenseRequest( | 102 MEDIA_EXPORT bool ExtractFirstKeyIdFromLicenseRequest( |
100 const std::vector<uint8_t>& license, | 103 const std::vector<uint8_t>& license, |
101 std::vector<uint8_t>* first_key); | 104 std::vector<uint8_t>* first_key); |
102 | 105 |
103 } // namespace media | 106 } // namespace media |
104 | 107 |
105 #endif // MEDIA_CDM_JSON_WEB_KEY_H_ | 108 #endif // MEDIA_CDM_JSON_WEB_KEY_H_ |
OLD | NEW |