Chromium Code Reviews| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 NOTREACHED(); | 227 NOTREACHED(); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 void AesDecryptor::Decrypt(StreamType stream_type, | 231 void AesDecryptor::Decrypt(StreamType stream_type, |
| 232 const scoped_refptr<DecoderBuffer>& encrypted, | 232 const scoped_refptr<DecoderBuffer>& encrypted, |
| 233 const DecryptCB& decrypt_cb) { | 233 const DecryptCB& decrypt_cb) { |
| 234 CHECK(encrypted->GetDecryptConfig()); | 234 CHECK(encrypted->GetDecryptConfig()); |
| 235 const std::string& key_id = encrypted->GetDecryptConfig()->key_id(); | 235 const std::string& key_id = encrypted->GetDecryptConfig()->key_id(); |
| 236 | 236 |
| 237 DecryptionKey* key = GetKey(key_id); | |
| 238 if (!key) { | |
| 239 DVLOG(1) << "Could not find a matching key for the given key ID."; | |
| 240 decrypt_cb.Run(kNoKey, NULL); | |
| 241 return; | |
| 242 } | |
| 243 | |
| 244 scoped_refptr<DecoderBuffer> decrypted; | 237 scoped_refptr<DecoderBuffer> decrypted; |
| 245 // An empty iv string signals that the frame is unencrypted. | 238 // An empty iv string signals that the frame is unencrypted. |
| 246 if (encrypted->GetDecryptConfig()->iv().empty()) { | 239 if (encrypted->GetDecryptConfig()->iv().empty()) { |
| 247 int data_offset = encrypted->GetDecryptConfig()->data_offset(); | 240 int data_offset = encrypted->GetDecryptConfig()->data_offset(); |
| 248 decrypted = DecoderBuffer::CopyFrom(encrypted->GetData() + data_offset, | 241 decrypted = DecoderBuffer::CopyFrom(encrypted->GetData() + data_offset, |
| 249 encrypted->GetDataSize() - data_offset); | 242 encrypted->GetDataSize() - data_offset); |
| 250 } else { | 243 } else { |
|
xhwang
2013/01/09 21:18:21
move line 235 here?
ddorwin
2013/01/10 04:44:46
Done.
| |
| 244 DecryptionKey* key = GetKey(key_id); | |
| 245 if (!key) { | |
| 246 DVLOG(1) << "Could not find a matching key for the given key ID."; | |
| 247 decrypt_cb.Run(kNoKey, NULL); | |
| 248 return; | |
| 249 } | |
| 250 | |
| 251 crypto::SymmetricKey* decryption_key = key->decryption_key(); | 251 crypto::SymmetricKey* decryption_key = key->decryption_key(); |
| 252 decrypted = DecryptData(*encrypted, decryption_key); | 252 decrypted = DecryptData(*encrypted, decryption_key); |
| 253 if (!decrypted) { | 253 if (!decrypted) { |
| 254 DVLOG(1) << "Decryption failed."; | 254 DVLOG(1) << "Decryption failed."; |
| 255 decrypt_cb.Run(kError, NULL); | 255 decrypt_cb.Run(kError, NULL); |
| 256 return; | 256 return; |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 decrypted->SetTimestamp(encrypted->GetTimestamp()); | 260 decrypted->SetTimestamp(encrypted->GetTimestamp()); |
| (...skipping 67 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_.get()) | 332 if (!decryption_key_.get()) |
| 333 return false; | 333 return false; |
| 334 return true; | 334 return true; |
| 335 } | 335 } |
| 336 | 336 |
| 337 } // namespace media | 337 } // namespace media |
| OLD | NEW |