Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Unified Diff: media/crypto/aes_decryptor_unittest.cc

Issue 10822013: Code clean-up in AesDecryptor and test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« media/crypto/aes_decryptor.cc ('K') | « media/crypto/aes_decryptor.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« media/crypto/aes_decryptor.cc ('K') | « media/crypto/aes_decryptor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698