| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // Creates a WebM encrypted buffer that the demuxer would pass to the | 172 // Creates a WebM encrypted buffer that the demuxer would pass to the |
| 173 // decryptor. |data| is the payload of a WebM encrypted Block. |key_id| is | 173 // decryptor. |data| is the payload of a WebM encrypted Block. |key_id| is |
| 174 // initialization data from the WebM file. Every encrypted Block has | 174 // initialization data from the WebM file. Every encrypted Block has |
| 175 // a signal byte prepended to a frame. If the frame is encrypted then an IV is | 175 // a signal byte prepended to a frame. If the frame is encrypted then an IV is |
| 176 // prepended to the Block. Current encrypted WebM request for comments | 176 // prepended to the Block. Current encrypted WebM request for comments |
| 177 // specification is here | 177 // specification is here |
| 178 // http://wiki.webmproject.org/encryption/webm-encryption-rfc | 178 // http://wiki.webmproject.org/encryption/webm-encryption-rfc |
| 179 static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer( | 179 static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer( |
| 180 const uint8* data, int data_size, | 180 const uint8* data, int data_size, |
| 181 const uint8* key_id, int key_id_size) { | 181 const uint8* key_id, int key_id_size) { |
| 182 scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom( | 182 scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::copy_from( |
| 183 data, data_size); | 183 data, data_size); |
| 184 CHECK(encrypted_buffer.get()); | 184 CHECK(encrypted_buffer.get()); |
| 185 DCHECK_EQ(kWebMSignalByteSize, 1); | 185 DCHECK_EQ(kWebMSignalByteSize, 1); |
| 186 | 186 |
| 187 uint8 signal_byte = data[0]; | 187 uint8 signal_byte = data[0]; |
| 188 int data_offset = kWebMSignalByteSize; | 188 int data_offset = kWebMSignalByteSize; |
| 189 | 189 |
| 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. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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::copy_from(data, data_size); |
| 217 CHECK(encrypted_buffer.get()); | 217 CHECK(encrypted_buffer.get()); |
| 218 encrypted_buffer->SetDecryptConfig( | 218 encrypted_buffer->SetDecryptConfig( |
| 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 |
| (...skipping 41 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->get_data_size()); |
| 279 EXPECT_EQ(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 279 EXPECT_EQ(0, memcmp(plain_text, decrypted->get_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->get_data_size()); |
| 292 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 292 EXPECT_NE(0, memcmp(plain_text, decrypted->get_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->get_data_size()); |
| 305 EXPECT_NE(0, memcmp(plain_text, decrypted->GetData(), plain_text_size)); | 305 EXPECT_NE(0, memcmp(plain_text, decrypted->get_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 |