Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: media/cdm/aes_decryptor.cc

Issue 1072403009: Use std::vector<uint8_t> instead of uint8*/int for MediaKeys interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "media/cdm/aes_decryptor.h" 5 #include "media/cdm/aes_decryptor.h"
6 6
7 #include <list> 7 #include <list>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // with |security_origin|. 235 // with |security_origin|.
236 DCHECK(!session_message_cb_.is_null()); 236 DCHECK(!session_message_cb_.is_null());
237 DCHECK(!session_closed_cb_.is_null()); 237 DCHECK(!session_closed_cb_.is_null());
238 DCHECK(!session_keys_change_cb_.is_null()); 238 DCHECK(!session_keys_change_cb_.is_null());
239 } 239 }
240 240
241 AesDecryptor::~AesDecryptor() { 241 AesDecryptor::~AesDecryptor() {
242 key_map_.clear(); 242 key_map_.clear();
243 } 243 }
244 244
245 void AesDecryptor::SetServerCertificate(const uint8* certificate_data, 245 void AesDecryptor::SetServerCertificate(const std::vector<uint8>& certificate,
246 int certificate_data_length,
247 scoped_ptr<SimpleCdmPromise> promise) { 246 scoped_ptr<SimpleCdmPromise> promise) {
248 promise->reject( 247 promise->reject(
249 NOT_SUPPORTED_ERROR, 0, "SetServerCertificate() is not supported."); 248 NOT_SUPPORTED_ERROR, 0, "SetServerCertificate() is not supported.");
250 } 249 }
251 250
252 void AesDecryptor::CreateSessionAndGenerateRequest( 251 void AesDecryptor::CreateSessionAndGenerateRequest(
253 SessionType session_type, 252 SessionType session_type,
254 EmeInitDataType init_data_type, 253 EmeInitDataType init_data_type,
255 const uint8* init_data, 254 const std::vector<uint8>& init_data,
256 int init_data_length,
257 scoped_ptr<NewSessionCdmPromise> promise) { 255 scoped_ptr<NewSessionCdmPromise> promise) {
258 std::string session_id(base::UintToString(next_session_id_++)); 256 std::string session_id(base::UintToString(next_session_id_++));
259 valid_sessions_.insert(session_id); 257 valid_sessions_.insert(session_id);
260 258
261 // For now, the AesDecryptor does not care about |session_type|. 259 // For now, the AesDecryptor does not care about |session_type|.
262 // TODO(jrummell): Validate |session_type|. 260 // TODO(jrummell): Validate |session_type|.
263 261
264 std::vector<uint8> message; 262 std::vector<uint8> message;
265 // TODO(jrummell): Since unprefixed will never send NULL, remove this check 263 // TODO(jrummell): Since unprefixed will never send NULL, remove this check
266 // when prefixed EME is removed (http://crbug.com/249976). 264 // when prefixed EME is removed (http://crbug.com/249976).
267 if (init_data && init_data_length) { 265 if (init_data.size() > 0) {
xhwang 2015/04/21 04:47:11 !empty()
jrummell 2015/04/21 22:59:36 Done.
268 std::vector<std::vector<uint8>> keys; 266 std::vector<std::vector<uint8>> keys;
269 switch (init_data_type) { 267 switch (init_data_type) {
270 case EmeInitDataType::WEBM: 268 case EmeInitDataType::WEBM:
271 // |init_data| is simply the key needed. 269 // |init_data| is simply the key needed.
272 keys.push_back( 270 keys.push_back(init_data);
273 std::vector<uint8>(init_data, init_data + init_data_length));
274 break; 271 break;
275 case EmeInitDataType::CENC: 272 case EmeInitDataType::CENC:
276 // |init_data| is a set of 0 or more concatenated 'pssh' boxes. 273 // |init_data| is a set of 0 or more concatenated 'pssh' boxes.
277 if (!GetKeyIdsForCommonSystemId(init_data, init_data_length, &keys)) { 274 if (!GetKeyIdsForCommonSystemId(vector_as_array(&init_data),
275 init_data.size(), &keys)) {
xhwang 2015/04/21 04:47:11 Can you make GetKeyIdsForCommonSystemId() taking v
jrummell 2015/04/21 22:59:36 Done.
278 promise->reject(NOT_SUPPORTED_ERROR, 0, 276 promise->reject(NOT_SUPPORTED_ERROR, 0,
279 "No supported PSSH box found."); 277 "No supported PSSH box found.");
280 return; 278 return;
281 } 279 }
282 break; 280 break;
283 case EmeInitDataType::KEYIDS: { 281 case EmeInitDataType::KEYIDS: {
284 std::string init_data_string(init_data, init_data + init_data_length); 282 std::string init_data_string(init_data.begin(), init_data.end());
285 std::string error_message; 283 std::string error_message;
286 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &keys, 284 if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &keys,
287 &error_message)) { 285 &error_message)) {
288 promise->reject(NOT_SUPPORTED_ERROR, 0, error_message); 286 promise->reject(NOT_SUPPORTED_ERROR, 0, error_message);
289 return; 287 return;
290 } 288 }
291 break; 289 break;
292 } 290 }
293 default: 291 default:
294 NOTREACHED(); 292 NOTREACHED();
(...skipping 13 matching lines...) Expand all
308 306
309 void AesDecryptor::LoadSession(SessionType session_type, 307 void AesDecryptor::LoadSession(SessionType session_type,
310 const std::string& session_id, 308 const std::string& session_id,
311 scoped_ptr<NewSessionCdmPromise> promise) { 309 scoped_ptr<NewSessionCdmPromise> promise) {
312 // TODO(xhwang): Change this to NOTREACHED() when blink checks for key systems 310 // TODO(xhwang): Change this to NOTREACHED() when blink checks for key systems
313 // that do not support loadSession. See http://crbug.com/342481 311 // that do not support loadSession. See http://crbug.com/342481
314 promise->reject(NOT_SUPPORTED_ERROR, 0, "LoadSession() is not supported."); 312 promise->reject(NOT_SUPPORTED_ERROR, 0, "LoadSession() is not supported.");
315 } 313 }
316 314
317 void AesDecryptor::UpdateSession(const std::string& session_id, 315 void AesDecryptor::UpdateSession(const std::string& session_id,
318 const uint8* response, 316 const std::vector<uint8>& response,
319 int response_length,
320 scoped_ptr<SimpleCdmPromise> promise) { 317 scoped_ptr<SimpleCdmPromise> promise) {
321 CHECK(response); 318 CHECK_GT(response.size(), 0u);
xhwang 2015/04/21 04:47:11 !empty()
jrummell 2015/04/21 22:59:36 Done.
322 CHECK_GT(response_length, 0);
323 319
324 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. 320 // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed.
325 if (valid_sessions_.find(session_id) == valid_sessions_.end()) { 321 if (valid_sessions_.find(session_id) == valid_sessions_.end()) {
326 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); 322 promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist.");
327 return; 323 return;
328 } 324 }
329 325
330 std::string key_string(reinterpret_cast<const char*>(response), 326 std::string key_string(response.begin(), response.end());
331 response_length);
332 327
333 KeyIdAndKeyPairs keys; 328 KeyIdAndKeyPairs keys;
334 SessionType session_type = MediaKeys::TEMPORARY_SESSION; 329 SessionType session_type = MediaKeys::TEMPORARY_SESSION;
335 if (!ExtractKeysFromJWKSet(key_string, &keys, &session_type)) { 330 if (!ExtractKeysFromJWKSet(key_string, &keys, &session_type)) {
336 promise->reject( 331 promise->reject(
337 INVALID_ACCESS_ERROR, 0, "Response is not a valid JSON Web Key Set."); 332 INVALID_ACCESS_ERROR, 0, "Response is not a valid JSON Web Key Set.");
338 return; 333 return;
339 } 334 }
340 335
341 // Make sure that at least one key was extracted. 336 // Make sure that at least one key was extracted.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 bool AesDecryptor::DecryptionKey::Init() { 595 bool AesDecryptor::DecryptionKey::Init() {
601 CHECK(!secret_.empty()); 596 CHECK(!secret_.empty());
602 decryption_key_.reset(crypto::SymmetricKey::Import( 597 decryption_key_.reset(crypto::SymmetricKey::Import(
603 crypto::SymmetricKey::AES, secret_)); 598 crypto::SymmetricKey::AES, secret_));
604 if (!decryption_key_) 599 if (!decryption_key_)
605 return false; 600 return false;
606 return true; 601 return true;
607 } 602 }
608 603
609 } // namespace media 604 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698