Index: media/crypto/aes_decryptor_unittest.cc |
diff --git a/media/crypto/aes_decryptor_unittest.cc b/media/crypto/aes_decryptor_unittest.cc |
index 34354a4a657a7740aae40b5ee1820351a9189510..66f869f8570086067e6af8a0dbe088c94765777e 100644 |
--- a/media/crypto/aes_decryptor_unittest.cc |
+++ b/media/crypto/aes_decryptor_unittest.cc |
@@ -143,6 +143,50 @@ static const unsigned char kWebmFrame0FrameDataChanged[] = { |
0x64, 0xf8 |
}; |
+// Returns a 16 byte CTR counter block. The CTR counter block format is a |
+// CTR IV appended with a CTR block counter. |iv| is a CTR IV. |iv_size| is |
+// the size of |iv| in bytes. |
+static std::string GenerateCounterBlock(const uint8* iv, int iv_size) { |
+ const int kDecryptionKeySize = 16; |
+ CHECK_GT(iv_size, 0); |
+ CHECK_LE(iv_size, kDecryptionKeySize); |
+ char counter_block_data[kDecryptionKeySize]; |
+ |
+ // Set the IV. |
+ memcpy(counter_block_data, iv, iv_size); |
+ |
+ // Set block counter to all 0's. |
+ memset(counter_block_data + iv_size, 0, kDecryptionKeySize - iv_size); |
+ |
+ return std::string(counter_block_data, kDecryptionKeySize); |
+} |
+ |
+// Creates a WebM encrypted buffer that the demuxer would pass to the |
+// decryptor. |data| is the payload of a WebM encrypted Block. |key_id| is |
+// initialization data from the WebM file. Every encrypted Block has |
+// an HMAC and IV prepended to an encrypted frame. Current encrypted WebM |
+// request for comments specification is here: |
+// http://wiki.webmproject.org/encryption/webm-encryption-rfc |
+static scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer( |
+ const uint8* data, int data_size, |
+ const uint8* key_id, int key_id_size) { |
+ scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom( |
+ data + kWebMHmacSize, data_size - kWebMHmacSize); |
+ CHECK(encrypted_buffer); |
+ |
+ uint64 network_iv; |
+ memcpy(&network_iv, data + kWebMHmacSize, sizeof(network_iv)); |
+ const uint64 iv = base::NetToHost64(network_iv); |
+ std::string webm_iv = GenerateCounterBlock( |
+ reinterpret_cast<const uint8*>(&iv), sizeof(iv)); |
+ encrypted_buffer->SetDecryptConfig( |
+ scoped_ptr<DecryptConfig>( |
+ new DecryptConfig(key_id, key_id_size, |
+ reinterpret_cast<const uint8*>(webm_iv.data()), |
+ webm_iv.size(), data, kWebMHmacSize, sizeof(iv)))); |
+ return encrypted_buffer; |
+} |
+ |
class AesDecryptorTest : public testing::Test { |
public: |
AesDecryptorTest() |
@@ -152,52 +196,6 @@ class AesDecryptorTest : public testing::Test { |
} |
protected: |
- // Returns a 16 byte CTR counter block. The CTR counter block format is a |
- // CTR IV appended with a CTR block counter. |iv| is a CTR IV. |iv_size| is |
- // the size of |iv| in bytes. |
- static std::string GenerateCounterBlock(const uint8* iv, int iv_size) { |
- const int kDecryptionKeySize = 16; |
- CHECK_GT(iv_size, 0); |
- CHECK_LE(iv_size, kDecryptionKeySize); |
- char counter_block_data[kDecryptionKeySize]; |
- |
- // Set the IV. |
- memcpy(counter_block_data, iv, iv_size); |
- |
- // Set block counter to all 0's. |
- memset(counter_block_data + iv_size, 0, kDecryptionKeySize - iv_size); |
- |
- return std::string(counter_block_data, kDecryptionKeySize); |
- } |
- |
- // Creates a WebM encrypted buffer that the demuxer would pass to the |
- // decryptor. |data| is the payload of a WebM encrypted Block. |key_id| is |
- // initialization data from the WebM file. Every encrypted Block has |
- // an HMAC and IV prepended to an encrypted frame. Current encrypted WebM |
- // request for comments specification is here |
- // http://wiki.webmproject.org/encryption/webm-encryption-rfc |
- scoped_refptr<DecoderBuffer> CreateWebMEncryptedBuffer(const uint8* data, |
- int data_size, |
- const uint8* key_id, |
- int key_id_size) { |
- scoped_refptr<DecoderBuffer> encrypted_buffer = DecoderBuffer::CopyFrom( |
- data + kWebMHmacSize, data_size - kWebMHmacSize); |
- CHECK(encrypted_buffer); |
- |
- uint64 network_iv; |
- memcpy(&network_iv, data + kWebMHmacSize, sizeof(network_iv)); |
- const uint64 iv = base::NetToHost64(network_iv); |
- std::string webm_iv = |
- GenerateCounterBlock(reinterpret_cast<const uint8*>(&iv), sizeof(iv)); |
- encrypted_buffer->SetDecryptConfig( |
- scoped_ptr<DecryptConfig>(new DecryptConfig( |
- key_id, key_id_size, |
- reinterpret_cast<const uint8*>(webm_iv.data()), webm_iv.size(), |
- data, kWebMHmacSize, |
- sizeof(iv)))); |
- return encrypted_buffer; |
- } |
- |
void GenerateKeyRequest(const uint8* key_id, int key_id_size) { |
EXPECT_CALL(client_, KeyMessageMock(kClearKeySystem, StrNe(std::string()), |
NotNull(), Gt(0), "")) |
@@ -253,6 +251,9 @@ class AesDecryptorTest : public testing::Test { |
AesDecryptor decryptor_; |
std::string session_id_string_; |
AesDecryptor::DecryptCB decrypt_cb_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(AesDecryptorTest); |
}; |
TEST_F(AesDecryptorTest, NormalDecryption) { |