| 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 | 6 |
| 7 #include "media/base/data_buffer.h" | 7 #include "media/base/data_buffer.h" |
| 8 #include "media/base/decrypt_config.h" | 8 #include "media/base/decrypt_config.h" |
| 9 #include "media/crypto/aes_decryptor.h" | 9 #include "media/crypto/aes_decryptor.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 protected: | 34 protected: |
| 35 void SetKeyIdForEncryptedData(const uint8* key_id, int key_id_size) { | 35 void SetKeyIdForEncryptedData(const uint8* key_id, int key_id_size) { |
| 36 encrypted_data_->SetDecryptConfig( | 36 encrypted_data_->SetDecryptConfig( |
| 37 scoped_ptr<DecryptConfig>(new DecryptConfig(key_id, key_id_size))); | 37 scoped_ptr<DecryptConfig>(new DecryptConfig(key_id, key_id_size))); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void DecryptAndExpectToSucceed() { | 40 void DecryptAndExpectToSucceed() { |
| 41 scoped_refptr<Buffer> decrypted = decryptor_.Decrypt(encrypted_data_); | 41 scoped_refptr<Buffer> decrypted = decryptor_.Decrypt(encrypted_data_); |
| 42 ASSERT_TRUE(decrypted); | 42 ASSERT_TRUE(decrypted); |
| 43 size_t data_length = sizeof(kOriginalData) - 1; | 43 int data_length = sizeof(kOriginalData) - 1; |
| 44 ASSERT_EQ(data_length, decrypted->GetDataSize()); | 44 ASSERT_EQ(data_length, decrypted->GetDataSize()); |
| 45 EXPECT_EQ(0, memcmp(kOriginalData, decrypted->GetData(), data_length)); | 45 EXPECT_EQ(0, memcmp(kOriginalData, decrypted->GetData(), data_length)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void DecryptAndExpectToFail() { | 48 void DecryptAndExpectToFail() { |
| 49 scoped_refptr<Buffer> decrypted = decryptor_.Decrypt(encrypted_data_); | 49 scoped_refptr<Buffer> decrypted = decryptor_.Decrypt(encrypted_data_); |
| 50 EXPECT_FALSE(decrypted); | 50 EXPECT_FALSE(decrypted); |
| 51 } | 51 } |
| 52 | 52 |
| 53 scoped_refptr<DataBuffer> encrypted_data_; | 53 scoped_refptr<DataBuffer> encrypted_data_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 75 | 75 |
| 76 TEST_F(AesDecryptorTest, KeyReplacement) { | 76 TEST_F(AesDecryptorTest, KeyReplacement) { |
| 77 SetKeyIdForEncryptedData(kKeyId1, kKeyIdSize); | 77 SetKeyIdForEncryptedData(kKeyId1, kKeyIdSize); |
| 78 decryptor_.AddKey(kKeyId1, kKeyIdSize, kWrongKey, kKeySize); | 78 decryptor_.AddKey(kKeyId1, kKeyIdSize, kWrongKey, kKeySize); |
| 79 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail()); | 79 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToFail()); |
| 80 decryptor_.AddKey(kKeyId1, kKeyIdSize, kRightKey, kKeySize); | 80 decryptor_.AddKey(kKeyId1, kKeyIdSize, kRightKey, kKeySize); |
| 81 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed()); | 81 ASSERT_NO_FATAL_FAILURE(DecryptAndExpectToSucceed()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // media | 84 } // media |
| OLD | NEW |