| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "media/base/decoder_buffer.h" | 10 #include "media/base/decoder_buffer.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // Setting the DecryptConfig object of the buffer while leaving the | 190 // Setting the DecryptConfig object of the buffer while leaving the |
| 191 // initialization vector empty will tell the decryptor that the frame is | 191 // initialization vector empty will tell the decryptor that the frame is |
| 192 // unencrypted. | 192 // unencrypted. |
| 193 std::string counter_block_str; | 193 std::string counter_block_str; |
| 194 | 194 |
| 195 if (signal_byte & kWebMFlagEncryptedFrame) { | 195 if (signal_byte & kWebMFlagEncryptedFrame) { |
| 196 counter_block_str = GenerateCounterBlock(data + data_offset, kWebMIvSize); | 196 counter_block_str = GenerateCounterBlock(data + data_offset, kWebMIvSize); |
| 197 data_offset += kWebMIvSize; | 197 data_offset += kWebMIvSize; |
| 198 } | 198 } |
| 199 | 199 |
| 200 encrypted_buffer->SetDecryptConfig( | 200 encrypted_buffer->set_decrypt_config( |
| 201 scoped_ptr<DecryptConfig>(new DecryptConfig( | 201 scoped_ptr<DecryptConfig>(new DecryptConfig( |
| 202 std::string(reinterpret_cast<const char*>(key_id), key_id_size), | 202 std::string(reinterpret_cast<const char*>(key_id), key_id_size), |
| 203 counter_block_str, | 203 counter_block_str, |
| 204 data_offset, | 204 data_offset, |
| 205 std::vector<SubsampleEntry>()))); | 205 std::vector<SubsampleEntry>()))); |
| 206 return encrypted_buffer; | 206 return encrypted_buffer; |
| 207 } | 207 } |
| 208 | 208 |
| 209 static scoped_refptr<DecoderBuffer> CreateSubsampleEncryptedBuffer( | 209 static scoped_refptr<DecoderBuffer> CreateSubsampleEncryptedBuffer( |
| 210 const uint8* data, int data_size, | 210 const uint8* data, int data_size, |
| 211 const uint8* key_id, int key_id_size, | 211 const uint8* key_id, int key_id_size, |
| 212 const uint8* iv, int iv_size, | 212 const uint8* iv, int iv_size, |
| 213 int data_offset, | 213 int data_offset, |
| 214 const std::vector<SubsampleEntry>& subsample_entries) { | 214 const std::vector<SubsampleEntry>& subsample_entries) { |
| 215 scoped_refptr<DecoderBuffer> encrypted_buffer = | 215 scoped_refptr<DecoderBuffer> encrypted_buffer = |
| 216 DecoderBuffer::CopyFrom(data, data_size); | 216 DecoderBuffer::CopyFrom(data, data_size); |
| 217 CHECK(encrypted_buffer.get()); | 217 CHECK(encrypted_buffer.get()); |
| 218 encrypted_buffer->SetDecryptConfig( | 218 encrypted_buffer->set_decrypt_config( |
| 219 scoped_ptr<DecryptConfig>(new DecryptConfig( | 219 scoped_ptr<DecryptConfig>(new DecryptConfig( |
| 220 std::string(reinterpret_cast<const char*>(key_id), key_id_size), | 220 std::string(reinterpret_cast<const char*>(key_id), key_id_size), |
| 221 std::string(reinterpret_cast<const char*>(iv), iv_size), | 221 std::string(reinterpret_cast<const char*>(iv), iv_size), |
| 222 data_offset, | 222 data_offset, |
| 223 subsample_entries))); | 223 subsample_entries))); |
| 224 return encrypted_buffer; | 224 return encrypted_buffer; |
| 225 } | 225 } |
| 226 | 226 |
| 227 class AesDecryptorTest : public testing::Test { | 227 class AesDecryptorTest : public testing::Test { |
| 228 public: | 228 public: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 const scoped_refptr<DecoderBuffer>&)); | 268 const scoped_refptr<DecoderBuffer>&)); |
| 269 | 269 |
| 270 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, | 270 void DecryptAndExpectToSucceed(const scoped_refptr<DecoderBuffer>& encrypted, |
| 271 const uint8* plain_text, int plain_text_size) { | 271 const uint8* plain_text, int plain_text_size) { |
| 272 scoped_refptr<DecoderBuffer> decrypted; | 272 scoped_refptr<DecoderBuffer> decrypted; |
| 273 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 273 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
| 274 .WillOnce(SaveArg<1>(&decrypted)); | 274 .WillOnce(SaveArg<1>(&decrypted)); |
| 275 | 275 |
| 276 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); | 276 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
| 277 ASSERT_TRUE(decrypted.get()); | 277 ASSERT_TRUE(decrypted.get()); |
| 278 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); | 278 ASSERT_EQ(plain_text_size, decrypted->data_size()); |
| 279 EXPECT_EQ(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 279 EXPECT_EQ(0, memcmp(plain_text, decrypted->data(), plain_text_size)); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void DecryptAndExpectDataMismatch( | 282 void DecryptAndExpectDataMismatch( |
| 283 const scoped_refptr<DecoderBuffer>& encrypted, | 283 const scoped_refptr<DecoderBuffer>& encrypted, |
| 284 const uint8* plain_text, int plain_text_size) { | 284 const uint8* plain_text, int plain_text_size) { |
| 285 scoped_refptr<DecoderBuffer> decrypted; | 285 scoped_refptr<DecoderBuffer> decrypted; |
| 286 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 286 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
| 287 .WillOnce(SaveArg<1>(&decrypted)); | 287 .WillOnce(SaveArg<1>(&decrypted)); |
| 288 | 288 |
| 289 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); | 289 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
| 290 ASSERT_TRUE(decrypted.get()); | 290 ASSERT_TRUE(decrypted.get()); |
| 291 ASSERT_EQ(plain_text_size, decrypted->GetDataSize()); | 291 ASSERT_EQ(plain_text_size, decrypted->data_size()); |
| 292 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 292 EXPECT_NE(0, memcmp(plain_text, decrypted->data(), plain_text_size)); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void DecryptAndExpectSizeDataMismatch( | 295 void DecryptAndExpectSizeDataMismatch( |
| 296 const scoped_refptr<DecoderBuffer>& encrypted, | 296 const scoped_refptr<DecoderBuffer>& encrypted, |
| 297 const uint8* plain_text, int plain_text_size) { | 297 const uint8* plain_text, int plain_text_size) { |
| 298 scoped_refptr<DecoderBuffer> decrypted; | 298 scoped_refptr<DecoderBuffer> decrypted; |
| 299 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) | 299 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kSuccess, NotNull())) |
| 300 .WillOnce(SaveArg<1>(&decrypted)); | 300 .WillOnce(SaveArg<1>(&decrypted)); |
| 301 | 301 |
| 302 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); | 302 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
| 303 ASSERT_TRUE(decrypted.get()); | 303 ASSERT_TRUE(decrypted.get()); |
| 304 EXPECT_NE(plain_text_size, decrypted->GetDataSize()); | 304 EXPECT_NE(plain_text_size, decrypted->data_size()); |
| 305 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 305 EXPECT_NE(0, memcmp(plain_text, decrypted->data(), plain_text_size)); |
| 306 } | 306 } |
| 307 | 307 |
| 308 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { | 308 void DecryptAndExpectToFail(const scoped_refptr<DecoderBuffer>& encrypted) { |
| 309 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); | 309 EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kError, IsNull())); |
| 310 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); | 310 decryptor_.Decrypt(Decryptor::kVideo, encrypted, decrypt_cb_); |
| 311 } | 311 } |
| 312 | 312 |
| 313 MOCK_METHOD1(KeyAdded, void(const std::string&)); | 313 MOCK_METHOD1(KeyAdded, void(const std::string&)); |
| 314 MOCK_METHOD3(KeyError, void(const std::string&, | 314 MOCK_METHOD3(KeyError, void(const std::string&, |
| 315 MediaKeys::KeyError, int)); | 315 MediaKeys::KeyError, int)); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( | 595 scoped_refptr<DecoderBuffer> encrypted_data = CreateSubsampleEncryptedBuffer( |
| 596 kSubsampleData, arraysize(kSubsampleData), | 596 kSubsampleData, arraysize(kSubsampleData), |
| 597 kSubsampleKeyId, arraysize(kSubsampleKeyId), | 597 kSubsampleKeyId, arraysize(kSubsampleKeyId), |
| 598 kSubsampleIv, arraysize(kSubsampleIv), | 598 kSubsampleIv, arraysize(kSubsampleIv), |
| 599 0, | 599 0, |
| 600 entries); | 600 entries); |
| 601 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); | 601 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail(encrypted_data)); |
| 602 } | 602 } |
| 603 | 603 |
| 604 } // namespace media | 604 } // namespace media |
| OLD | NEW |