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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 AesDecryptor::~AesDecryptor() { | 132 AesDecryptor::~AesDecryptor() { |
133 STLDeleteValues(&key_map_); | 133 STLDeleteValues(&key_map_); |
134 } | 134 } |
135 | 135 |
136 bool AesDecryptor::GenerateKeyRequest(const std::string& key_system, | 136 bool AesDecryptor::GenerateKeyRequest(const std::string& key_system, |
137 const std::string& type, | 137 const std::string& type, |
138 const uint8* init_data, | 138 const uint8* init_data, |
139 int init_data_length) { | 139 int init_data_length) { |
140 std::string session_id_string(base::UintToString(next_session_id_++)); | 140 std::string session_id_string(base::UintToString(next_session_id_++)); |
141 | 141 |
142 if (!init_data || !init_data_length) { | |
143 DVLOG(1) << "init_data required to generate a key request."; | |
144 return false; | |
145 } | |
146 | |
147 // For now, the AesDecryptor does not care about |key_system| and |type|; | 142 // For now, the AesDecryptor does not care about |key_system| and |type|; |
148 // just fire the event with the |init_data| as the request. | 143 // just fire the event with the |init_data| as the request. |
149 int message_length = init_data_length; | 144 scoped_array<uint8> message; |
150 scoped_array<uint8> message(new uint8[message_length]); | 145 int message_length = 0; |
151 memcpy(message.get(), init_data, message_length); | 146 |
| 147 if (init_data && init_data_length) { |
| 148 message_length = init_data_length; |
| 149 message.reset(new uint8[message_length]); |
| 150 memcpy(message.get(), init_data, message_length); |
| 151 } |
152 | 152 |
153 client_->KeyMessage(key_system, session_id_string, | 153 client_->KeyMessage(key_system, session_id_string, |
154 message.Pass(), message_length, ""); | 154 message.Pass(), message_length, ""); |
155 return true; | 155 return true; |
156 } | 156 } |
157 | 157 |
158 void AesDecryptor::AddKey(const std::string& key_system, | 158 void AesDecryptor::AddKey(const std::string& key_system, |
159 const uint8* key, | 159 const uint8* key, |
160 int key_length, | 160 int key_length, |
161 const uint8* init_data, | 161 const uint8* init_data, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 bool AesDecryptor::DecryptionKey::Init() { | 327 bool AesDecryptor::DecryptionKey::Init() { |
328 CHECK(!secret_.empty()); | 328 CHECK(!secret_.empty()); |
329 decryption_key_.reset(crypto::SymmetricKey::Import( | 329 decryption_key_.reset(crypto::SymmetricKey::Import( |
330 crypto::SymmetricKey::AES, secret_)); | 330 crypto::SymmetricKey::AES, secret_)); |
331 if (!decryption_key_.get()) | 331 if (!decryption_key_.get()) |
332 return false; | 332 return false; |
333 return true; | 333 return true; |
334 } | 334 } |
335 | 335 |
336 } // namespace media | 336 } // namespace media |
OLD | NEW |