OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "media/crypto/aes_decryptor.h" | 5 #include "media/crypto/aes_decryptor.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 const uint8* init_data, | 162 const uint8* init_data, |
163 int init_data_length, | 163 int init_data_length, |
164 const std::string& session_id) { | 164 const std::string& session_id) { |
165 CHECK(key); | 165 CHECK(key); |
166 CHECK_GT(key_length, 0); | 166 CHECK_GT(key_length, 0); |
167 | 167 |
168 // TODO(xhwang): Add |session_id| check after we figure out how: | 168 // TODO(xhwang): Add |session_id| check after we figure out how: |
169 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16550 | 169 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=16550 |
170 if (key_length != DecryptConfig::kDecryptionKeySize) { | 170 if (key_length != DecryptConfig::kDecryptionKeySize) { |
171 DVLOG(1) << "Invalid key length: " << key_length; | 171 DVLOG(1) << "Invalid key length: " << key_length; |
172 key_error_cb_.Run(key_system, session_id, Decryptor::kUnknownError, 0); | 172 key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0); |
173 return; | 173 return; |
174 } | 174 } |
175 | 175 |
176 // TODO(xhwang): Fix the decryptor to accept no |init_data|. See | 176 // TODO(xhwang): Fix the decryptor to accept no |init_data|. See |
177 // http://crbug.com/123265. Until then, ensure a non-empty value is passed. | 177 // http://crbug.com/123265. Until then, ensure a non-empty value is passed. |
178 static const uint8 kDummyInitData[1] = { 0 }; | 178 static const uint8 kDummyInitData[1] = { 0 }; |
179 if (!init_data) { | 179 if (!init_data) { |
180 init_data = kDummyInitData; | 180 init_data = kDummyInitData; |
181 init_data_length = arraysize(kDummyInitData); | 181 init_data_length = arraysize(kDummyInitData); |
182 } | 182 } |
183 | 183 |
184 // TODO(xhwang): For now, use |init_data| for key ID. Make this more spec | 184 // TODO(xhwang): For now, use |init_data| for key ID. Make this more spec |
185 // compliant later (http://crbug.com/123262, http://crbug.com/123265). | 185 // compliant later (http://crbug.com/123262, http://crbug.com/123265). |
186 std::string key_id_string(reinterpret_cast<const char*>(init_data), | 186 std::string key_id_string(reinterpret_cast<const char*>(init_data), |
187 init_data_length); | 187 init_data_length); |
188 std::string key_string(reinterpret_cast<const char*>(key) , key_length); | 188 std::string key_string(reinterpret_cast<const char*>(key) , key_length); |
189 scoped_ptr<DecryptionKey> decryption_key(new DecryptionKey(key_string)); | 189 scoped_ptr<DecryptionKey> decryption_key(new DecryptionKey(key_string)); |
190 if (!decryption_key) { | 190 if (!decryption_key) { |
191 DVLOG(1) << "Could not create key."; | 191 DVLOG(1) << "Could not create key."; |
192 key_error_cb_.Run(key_system, session_id, Decryptor::kUnknownError, 0); | 192 key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0); |
193 return; | 193 return; |
194 } | 194 } |
195 | 195 |
196 if (!decryption_key->Init()) { | 196 if (!decryption_key->Init()) { |
197 DVLOG(1) << "Could not initialize decryption key."; | 197 DVLOG(1) << "Could not initialize decryption key."; |
198 key_error_cb_.Run(key_system, session_id, Decryptor::kUnknownError, 0); | 198 key_error_cb_.Run(key_system, session_id, MediaKeys::kUnknownError, 0); |
199 return; | 199 return; |
200 } | 200 } |
201 | 201 |
202 SetKey(key_id_string, decryption_key.Pass()); | 202 SetKey(key_id_string, decryption_key.Pass()); |
203 | 203 |
204 if (!new_audio_key_cb_.is_null()) | 204 if (!new_audio_key_cb_.is_null()) |
205 new_audio_key_cb_.Run(); | 205 new_audio_key_cb_.Run(); |
206 | 206 |
207 if (!new_video_key_cb_.is_null()) | 207 if (!new_video_key_cb_.is_null()) |
208 new_video_key_cb_.Run(); | 208 new_video_key_cb_.Run(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 bool AesDecryptor::DecryptionKey::Init() { | 328 bool AesDecryptor::DecryptionKey::Init() { |
329 CHECK(!secret_.empty()); | 329 CHECK(!secret_.empty()); |
330 decryption_key_.reset(crypto::SymmetricKey::Import( | 330 decryption_key_.reset(crypto::SymmetricKey::Import( |
331 crypto::SymmetricKey::AES, secret_)); | 331 crypto::SymmetricKey::AES, secret_)); |
332 if (!decryption_key_) | 332 if (!decryption_key_) |
333 return false; | 333 return false; |
334 return true; | 334 return true; |
335 } | 335 } |
336 | 336 |
337 } // namespace media | 337 } // namespace media |
OLD | NEW |