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