summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-30 08:31:38 +0000
committerxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-30 08:31:38 +0000
commit74dca3bac433c591a4fe5c95f032f2bf3d7d3c5a (patch)
tree5084b751712c2351992a02288713c327e52aee76 /media
parent6ae19a8667d11ace65f8646d4f1ebda2df5086ff (diff)
downloadchromium_src-74dca3bac433c591a4fe5c95f032f2bf3d7d3c5a.zip
chromium_src-74dca3bac433c591a4fe5c95f032f2bf3d7d3c5a.tar.gz
chromium_src-74dca3bac433c591a4fe5c95f032f2bf3d7d3c5a.tar.bz2
Encrypted Media: Handle empty init_data in AesDecryptor::GenerateKeyRequest().
Based on the EME spec, init_data is optional in GenerateKeyRequest(). Update AesDecryptor to support this. BUG=162759 TEST=added test in AesDecryptorTest to test this case. Review URL: https://chromiumcodereview.appspot.com/11434025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/crypto/aes_decryptor.cc5
-rw-r--r--media/crypto/aes_decryptor_unittest.cc22
2 files changed, 18 insertions, 9 deletions
diff --git a/media/crypto/aes_decryptor.cc b/media/crypto/aes_decryptor.cc
index fb16486..88d194e 100644
--- a/media/crypto/aes_decryptor.cc
+++ b/media/crypto/aes_decryptor.cc
@@ -139,6 +139,11 @@ bool AesDecryptor::GenerateKeyRequest(const std::string& key_system,
int init_data_length) {
std::string session_id_string(base::UintToString(next_session_id_++));
+ if (!init_data || !init_data_length) {
+ DVLOG(1) << "init_data required to generate a key request.";
+ return false;
+ }
+
// For now, the AesDecryptor does not care about |key_system| and |type|;
// just fire the event with the |init_data| as the request.
int message_length = init_data_length;
diff --git a/media/crypto/aes_decryptor_unittest.cc b/media/crypto/aes_decryptor_unittest.cc
index dac0208..b6c9805 100644
--- a/media/crypto/aes_decryptor_unittest.cc
+++ b/media/crypto/aes_decryptor_unittest.cc
@@ -24,6 +24,10 @@ using ::testing::StrNe;
namespace media {
+MATCHER_P2(ArrayEq, array, size, "") {
+ return !memcmp(arg, array, size);
+}
+
// |encrypted_data| is encrypted from |plain_text| using |key|. |key_id| is
// used to distinguish |key|.
struct WebmEncryptedData {
@@ -59,8 +63,7 @@ const WebmEncryptedData kWebmEncryptedFrames[] = {
0xff, 0xf0, 0xd1, 0x12, 0xd5, 0x24, 0x81, 0x96,
0x55, 0x1b, 0x68, 0x9f, 0x38, 0x91, 0x85
}, 23
- },
- {
+ }, {
// plaintext
"Changed Original data.", 22,
// key_id
@@ -78,8 +81,7 @@ const WebmEncryptedData kWebmEncryptedFrames[] = {
0x79, 0x1c, 0x8e, 0x25, 0xd7, 0x17, 0xe7, 0x5e,
0x16, 0xe3, 0x40, 0x08, 0x27, 0x11, 0xe9
}, 31
- },
- {
+ }, {
// plaintext
"Original data.", 14,
// key_id
@@ -95,8 +97,7 @@ const WebmEncryptedData kWebmEncryptedFrames[] = {
0x00, 0x9c, 0x71, 0x26, 0x57, 0x3e, 0x25, 0x37,
0xf7, 0x31, 0x81, 0x19, 0x64, 0xce, 0xbc
}, 23
- },
- {
+ }, {
// plaintext
"Changed Original data.", 22,
// key_id
@@ -115,8 +116,6 @@ const WebmEncryptedData kWebmEncryptedFrames[] = {
}
};
-
-
static const uint8 kWebmWrongSizedKey[] = { 0x20, 0x20 };
static const uint8 kSubsampleOriginalData[] = "Original subsample data.";
@@ -241,7 +240,8 @@ class AesDecryptorTest : public testing::Test {
protected:
void GenerateKeyRequest(const uint8* key_id, int key_id_size) {
EXPECT_CALL(client_, KeyMessageMock(kClearKeySystem, StrNe(""),
- NotNull(), Gt(0), ""))
+ ArrayEq(key_id, key_id_size),
+ key_id_size, ""))
.WillOnce(SaveArg<1>(&session_id_string_));
EXPECT_TRUE(decryptor_.GenerateKeyRequest(kClearKeySystem, "",
key_id, key_id_size));
@@ -315,6 +315,10 @@ class AesDecryptorTest : public testing::Test {
std::vector<SubsampleEntry> subsample_entries_;
};
+TEST_F(AesDecryptorTest, GenerateKeyRequestWithNullInitData) {
+ EXPECT_FALSE(decryptor_.GenerateKeyRequest(kClearKeySystem, "", NULL, 0));
+}
+
TEST_F(AesDecryptorTest, NormalWebMDecryption) {
const WebmEncryptedData& frame = kWebmEncryptedFrames[0];
GenerateKeyRequest(frame.key_id, frame.key_id_size);