OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "media/cdm/cenc_utils.h" | 5 #include "media/cdm/cenc_utils.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
11 | 11 |
12 const uint8_t kKey1Data[] = { | 12 const uint8_t kKey1Data[] = { |
13 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, | 13 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, |
14 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03 | 14 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03 |
15 }; | 15 }; |
16 const uint8_t kKey2Data[] = { | 16 const uint8_t kKey2Data[] = { |
17 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, | 17 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, |
18 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, | 18 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, |
19 }; | 19 }; |
20 const uint8_t kKey3Data[] = { | 20 const uint8_t kKey3Data[] = { |
21 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05, | 21 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05, |
22 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05, | 22 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05, |
23 }; | 23 }; |
24 const uint8_t kKey4Data[] = { | 24 const uint8_t kKey4Data[] = { |
25 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06, | 25 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06, |
26 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06, | 26 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06, |
27 }; | 27 }; |
28 const uint8_t kCommonEncryptionUuid[] = { | |
ddorwin
2015/06/04 22:09:15
nit: Is there a reason "Uuid" is used? That's only
jrummell
2015/06/05 17:57:24
Done.
| |
29 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, | |
30 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B | |
31 }; | |
28 | 32 |
29 class CencUtilsTest : public testing::Test { | 33 class CencUtilsTest : public testing::Test { |
30 public: | 34 public: |
31 CencUtilsTest() | 35 CencUtilsTest() |
32 : key1_(kKey1Data, kKey1Data + arraysize(kKey1Data)), | 36 : key1_(kKey1Data, kKey1Data + arraysize(kKey1Data)), |
33 key2_(kKey2Data, kKey2Data + arraysize(kKey2Data)), | 37 key2_(kKey2Data, kKey2Data + arraysize(kKey2Data)), |
34 key3_(kKey3Data, kKey3Data + arraysize(kKey3Data)), | 38 key3_(kKey3Data, kKey3Data + arraysize(kKey3Data)), |
35 key4_(kKey4Data, kKey4Data + arraysize(kKey4Data)) {} | 39 key4_(kKey4Data, kKey4Data + arraysize(kKey4Data)) {} |
36 | 40 |
37 protected: | 41 protected: |
(...skipping 13 matching lines...) Expand all Loading... | |
51 box->push_back('p'); | 55 box->push_back('p'); |
52 box->push_back('s'); | 56 box->push_back('s'); |
53 box->push_back('s'); | 57 box->push_back('s'); |
54 box->push_back('h'); | 58 box->push_back('h'); |
55 // Add version. | 59 // Add version. |
56 box->push_back(version); | 60 box->push_back(version); |
57 // Add flags. | 61 // Add flags. |
58 box->push_back(0); | 62 box->push_back(0); |
59 box->push_back(0); | 63 box->push_back(0); |
60 box->push_back(0); | 64 box->push_back(0); |
61 // Add Clear Key SystemID. | 65 // Add Common Encryption SystemID. |
62 box->push_back(0x10); | 66 for (uint i = 0; i < arraysize(kCommonEncryptionUuid); ++i) |
63 box->push_back(0x77); | 67 box->push_back(kCommonEncryptionUuid[i]); |
64 box->push_back(0xEF); | |
65 box->push_back(0xEC); | |
66 box->push_back(0xC0); | |
67 box->push_back(0xB2); | |
68 box->push_back(0x4D); | |
69 box->push_back(0x02); | |
70 box->push_back(0xAC); | |
71 box->push_back(0xE3); | |
72 box->push_back(0x3C); | |
73 box->push_back(0x1E); | |
74 box->push_back(0x52); | |
75 box->push_back(0xE2); | |
76 box->push_back(0xFB); | |
77 box->push_back(0x4B); | |
78 } | 68 } |
79 | 69 |
80 std::vector<uint8_t> MakePSSHBox(uint8_t version) { | 70 std::vector<uint8_t> MakePSSHBox(uint8_t version) { |
81 std::vector<uint8_t> box; | 71 std::vector<uint8_t> box; |
82 uint8_t size = (version == 0) ? 32 : 36; | 72 uint8_t size = (version == 0) ? 32 : 36; |
83 InitializePSSHBox(&box, size, version); | 73 InitializePSSHBox(&box, size, version); |
84 if (version > 0) { | 74 if (version > 0) { |
85 // Add key_count (= 0). | 75 // Add key_count (= 0). |
86 box.push_back(0); | 76 box.push_back(0); |
87 box.push_back(0); | 77 box.push_back(0); |
(...skipping 17 matching lines...) Expand all Loading... | |
105 uint8_t size = 52; | 95 uint8_t size = 52; |
106 InitializePSSHBox(&box, size, version); | 96 InitializePSSHBox(&box, size, version); |
107 | 97 |
108 // Add key_count (= 1). | 98 // Add key_count (= 1). |
109 box.push_back(0); | 99 box.push_back(0); |
110 box.push_back(0); | 100 box.push_back(0); |
111 box.push_back(0); | 101 box.push_back(0); |
112 box.push_back(1); | 102 box.push_back(1); |
113 | 103 |
114 // Add key1. | 104 // Add key1. |
115 for (int i = 0; i < 16; ++i) | 105 for (uint i = 0; i < key1.size(); ++i) |
116 box.push_back(key1[i]); | 106 box.push_back(key1[i]); |
117 | 107 |
118 // Add data_size (= 0). | 108 // Add data_size (= 0). |
119 box.push_back(0); | 109 box.push_back(0); |
120 box.push_back(0); | 110 box.push_back(0); |
121 box.push_back(0); | 111 box.push_back(0); |
122 box.push_back(0); | 112 box.push_back(0); |
123 return box; | 113 return box; |
124 } | 114 } |
125 | 115 |
126 std::vector<uint8_t> MakePSSHBox(uint8_t version, | 116 std::vector<uint8_t> MakePSSHBox(uint8_t version, |
127 const std::vector<uint8_t>& key1, | 117 const std::vector<uint8_t>& key1, |
128 const std::vector<uint8_t>& key2) { | 118 const std::vector<uint8_t>& key2) { |
129 DCHECK(version > 0); | 119 DCHECK(version > 0); |
130 DCHECK(key1.size() == 16); | 120 DCHECK(key1.size() == 16); |
131 DCHECK(key2.size() == 16); | 121 DCHECK(key2.size() == 16); |
132 | 122 |
133 std::vector<uint8_t> box; | 123 std::vector<uint8_t> box; |
134 uint8_t size = 68; | 124 uint8_t size = 68; |
135 InitializePSSHBox(&box, size, version); | 125 InitializePSSHBox(&box, size, version); |
136 | 126 |
137 // Add key_count (= 2). | 127 // Add key_count (= 2). |
138 box.push_back(0); | 128 box.push_back(0); |
139 box.push_back(0); | 129 box.push_back(0); |
140 box.push_back(0); | 130 box.push_back(0); |
141 box.push_back(2); | 131 box.push_back(2); |
142 | 132 |
143 // Add key1. | 133 // Add key1. |
144 for (int i = 0; i < 16; ++i) | 134 for (uint i = 0; i < key1.size(); ++i) |
145 box.push_back(key1[i]); | 135 box.push_back(key1[i]); |
146 | 136 |
147 // Add key2. | 137 // Add key2. |
148 for (int i = 0; i < 16; ++i) | 138 for (uint i = 0; i < key2.size(); ++i) |
149 box.push_back(key2[i]); | 139 box.push_back(key2[i]); |
150 | 140 |
151 // Add data_size (= 0). | 141 // Add data_size (= 0). |
152 box.push_back(0); | 142 box.push_back(0); |
153 box.push_back(0); | 143 box.push_back(0); |
154 box.push_back(0); | 144 box.push_back(0); |
155 box.push_back(0); | 145 box.push_back(0); |
156 return box; | 146 return box; |
157 } | 147 } |
158 | 148 |
149 void AppendData(std::vector<uint8_t>& pssh_box, | |
150 const std::vector<uint8_t>& data) { | |
151 // This assumes that |pssh_box| has been created using the routines above, | |
152 // and simply appends the data to the end of it. It updates the box size | |
153 // and sets the data size. | |
154 DCHECK(data.size() < 100); | |
155 pssh_box[3] += data.size(); | |
156 pssh_box.pop_back(); | |
157 pssh_box.push_back(data.size()); | |
158 pssh_box.insert(pssh_box.end(), data.begin(), data.end()); | |
159 } | |
160 | |
159 const std::vector<uint8_t>& Key1() { return key1_; } | 161 const std::vector<uint8_t>& Key1() { return key1_; } |
160 const std::vector<uint8_t>& Key2() { return key2_; } | 162 const std::vector<uint8_t>& Key2() { return key2_; } |
161 const std::vector<uint8_t>& Key3() { return key3_; } | 163 const std::vector<uint8_t>& Key3() { return key3_; } |
162 const std::vector<uint8_t>& Key4() { return key4_; } | 164 const std::vector<uint8_t>& Key4() { return key4_; } |
163 | 165 |
164 private: | 166 private: |
165 std::vector<uint8_t> key1_; | 167 std::vector<uint8_t> key1_; |
166 std::vector<uint8_t> key2_; | 168 std::vector<uint8_t> key2_; |
167 std::vector<uint8_t> key3_; | 169 std::vector<uint8_t> key3_; |
168 std::vector<uint8_t> key4_; | 170 std::vector<uint8_t> key4_; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); | 209 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); |
208 EXPECT_EQ(2u, key_ids.size()); | 210 EXPECT_EQ(2u, key_ids.size()); |
209 EXPECT_EQ(key_ids[0], Key1()); | 211 EXPECT_EQ(key_ids[0], Key1()); |
210 EXPECT_EQ(key_ids[1], Key2()); | 212 EXPECT_EQ(key_ids[1], Key2()); |
211 } | 213 } |
212 | 214 |
213 TEST_F(CencUtilsTest, PSSHVersion0Plus1) { | 215 TEST_F(CencUtilsTest, PSSHVersion0Plus1) { |
214 std::vector<uint8_t> box0 = MakePSSHBox(0); | 216 std::vector<uint8_t> box0 = MakePSSHBox(0); |
215 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); | 217 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); |
216 | 218 |
217 // Concatentate box1 into box0. | 219 // Concatentate box1 onto end of box0. |
218 for (const auto& value : box1) | 220 box0.insert(box0.end(), box1.begin(), box1.end()); |
219 box0.push_back(value); | |
220 | 221 |
221 KeyIdList key_ids; | 222 KeyIdList key_ids; |
222 EXPECT_TRUE(ValidatePsshInput(box0)); | 223 EXPECT_TRUE(ValidatePsshInput(box0)); |
223 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box0, &key_ids)); | 224 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box0, &key_ids)); |
224 EXPECT_EQ(1u, key_ids.size()); | 225 EXPECT_EQ(1u, key_ids.size()); |
225 EXPECT_EQ(key_ids[0], Key1()); | 226 EXPECT_EQ(key_ids[0], Key1()); |
226 } | 227 } |
227 | 228 |
228 TEST_F(CencUtilsTest, PSSHVersion1Plus0) { | 229 TEST_F(CencUtilsTest, PSSHVersion1Plus0) { |
229 std::vector<uint8_t> box0 = MakePSSHBox(0); | 230 std::vector<uint8_t> box0 = MakePSSHBox(0); |
230 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); | 231 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); |
231 | 232 |
232 // Concatentate box0 into box1. | 233 // Concatentate box0 onto end of box1. |
233 for (const auto& value : box0) | 234 box1.insert(box1.end(), box0.begin(), box0.end()); |
234 box1.push_back(value); | |
235 | 235 |
236 KeyIdList key_ids; | 236 KeyIdList key_ids; |
237 EXPECT_TRUE(ValidatePsshInput(box1)); | 237 EXPECT_TRUE(ValidatePsshInput(box1)); |
238 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids)); | 238 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids)); |
239 EXPECT_EQ(1u, key_ids.size()); | 239 EXPECT_EQ(1u, key_ids.size()); |
240 EXPECT_EQ(key_ids[0], Key1()); | 240 EXPECT_EQ(key_ids[0], Key1()); |
241 } | 241 } |
242 | 242 |
243 TEST_F(CencUtilsTest, MultiplePSSHVersion1) { | 243 TEST_F(CencUtilsTest, MultiplePSSHVersion1) { |
244 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 244 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
245 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); | 245 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); |
246 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4()); | 246 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4()); |
247 | 247 |
248 // Concatentate box1 into box. | 248 // Concatentate box1 and box2 onto end of box. |
249 for (const auto& value : box1) | 249 box.insert(box.end(), box1.begin(), box1.end()); |
250 box.push_back(value); | 250 box.insert(box.end(), box2.begin(), box2.end()); |
251 // Concatentate box2 into box. | |
252 for (const auto& value : box2) | |
253 box.push_back(value); | |
254 | 251 |
255 KeyIdList key_ids; | 252 KeyIdList key_ids; |
256 EXPECT_TRUE(ValidatePsshInput(box)); | 253 EXPECT_TRUE(ValidatePsshInput(box)); |
257 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); | 254 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); |
258 EXPECT_EQ(4u, key_ids.size()); | 255 EXPECT_EQ(4u, key_ids.size()); |
259 EXPECT_EQ(key_ids[0], Key1()); | 256 EXPECT_EQ(key_ids[0], Key1()); |
260 EXPECT_EQ(key_ids[1], Key2()); | 257 EXPECT_EQ(key_ids[1], Key2()); |
261 EXPECT_EQ(key_ids[2], Key3()); | 258 EXPECT_EQ(key_ids[2], Key3()); |
262 EXPECT_EQ(key_ids[3], Key4()); | 259 EXPECT_EQ(key_ids[3], Key4()); |
263 } | 260 } |
264 | 261 |
265 TEST_F(CencUtilsTest, InvalidPSSH) { | 262 TEST_F(CencUtilsTest, InvalidPSSH) { |
266 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 263 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
267 KeyIdList key_ids; | 264 KeyIdList key_ids; |
268 for (uint32 i = 1; i < box.size(); ++i) { | 265 for (uint32 i = 1; i < box.size(); ++i) { |
269 // Modify size of data passed to be less than real size. | 266 // Modify size of data passed to be less than real size. |
270 std::vector<uint8_t> truncated(&box[0], &box[0] + i); | 267 std::vector<uint8_t> truncated(&box[0], &box[0] + i); |
271 EXPECT_FALSE(ValidatePsshInput(truncated)); | 268 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i; |
272 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); | 269 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); |
273 // Modify starting point. | 270 // Modify starting point. |
274 std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i); | 271 std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i); |
275 EXPECT_FALSE(ValidatePsshInput(changed_offset)); | 272 EXPECT_FALSE(ValidatePsshInput(changed_offset)) << "Failed for offset " |
273 << i; | |
276 EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids)); | 274 EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids)); |
277 } | 275 } |
278 } | 276 } |
279 | 277 |
280 TEST_F(CencUtilsTest, InvalidSystemID) { | 278 TEST_F(CencUtilsTest, InvalidSystemID) { |
281 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 279 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
282 | 280 |
283 // Modify the System ID. | 281 // Modify the System ID. |
284 ++box[20]; | 282 ++box[20]; |
285 | 283 |
286 KeyIdList key_ids; | 284 KeyIdList key_ids; |
287 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); | 285 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); |
288 EXPECT_EQ(0u, key_ids.size()); | 286 EXPECT_EQ(0u, key_ids.size()); |
289 } | 287 } |
290 | 288 |
291 TEST_F(CencUtilsTest, InvalidFlags) { | 289 TEST_F(CencUtilsTest, InvalidFlags) { |
292 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 290 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
293 | 291 |
294 // Modify flags. | 292 // Modify flags. |
295 box[10] = 3; | 293 box[10] = 3; |
296 | 294 |
297 KeyIdList key_ids; | 295 KeyIdList key_ids; |
298 // TODO(jrummell): This should fail as the 'pssh' box is skipped. | 296 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); |
299 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); | |
300 EXPECT_EQ(0u, key_ids.size()); | |
301 } | 297 } |
302 | 298 |
303 TEST_F(CencUtilsTest, LongSize) { | 299 TEST_F(CencUtilsTest, LongSize) { |
304 const uint8_t data[] = { | 300 const uint8_t data[] = { |
305 0x00, 0x00, 0x00, 0x01, // size = 1 | 301 0x00, 0x00, 0x00, 0x01, // size = 1 |
306 0x70, 0x73, 0x73, 0x68, // 'pssh' | 302 0x70, 0x73, 0x73, 0x68, // 'pssh' |
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // longsize | 303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // longsize |
308 0x01, // version | 304 0x01, // version |
309 0x00, 0x00, 0x00, // flags | 305 0x00, 0x00, 0x00, // flags |
310 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID | 306 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 0x00, 0x00, 0x00, 0x00 // datasize | 362 0x00, 0x00, 0x00, 0x00 // datasize |
367 }; | 363 }; |
368 | 364 |
369 KeyIdList key_ids; | 365 KeyIdList key_ids; |
370 EXPECT_FALSE( | 366 EXPECT_FALSE( |
371 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); | 367 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); |
372 EXPECT_FALSE(GetKeyIdsForCommonSystemId( | 368 EXPECT_FALSE(GetKeyIdsForCommonSystemId( |
373 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); | 369 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); |
374 } | 370 } |
375 | 371 |
372 TEST_F(CencUtilsTest, GetPsshData_Version0) { | |
373 std::vector<uint8_t> clear_key( | |
374 kCommonEncryptionUuid, | |
375 kCommonEncryptionUuid + arraysize(kCommonEncryptionUuid)); | |
376 std::vector<uint8_t> pssh_data; | |
377 | |
378 std::vector<uint8_t> box = MakePSSHBox(0); | |
379 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data)); | |
380 EXPECT_EQ(0u, pssh_data.size()); | |
381 | |
382 std::vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04}; | |
383 AppendData(box, data); | |
384 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data)); | |
385 EXPECT_EQ(data, pssh_data); | |
386 } | |
387 | |
388 TEST_F(CencUtilsTest, GetPsshData_Version1NoKeys) { | |
389 std::vector<uint8_t> clear_key( | |
390 kCommonEncryptionUuid, | |
391 kCommonEncryptionUuid + arraysize(kCommonEncryptionUuid)); | |
392 std::vector<uint8_t> pssh_data; | |
393 | |
394 std::vector<uint8_t> box = MakePSSHBox(1); | |
395 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data)); | |
396 EXPECT_EQ(0u, pssh_data.size()); | |
397 | |
398 std::vector<uint8_t> data = {0x05, 0x06, 0x07, 0x08}; | |
399 AppendData(box, data); | |
400 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data)); | |
401 EXPECT_EQ(data, pssh_data); | |
402 } | |
403 | |
404 TEST_F(CencUtilsTest, GetPsshData_Version1WithKeys) { | |
405 std::vector<uint8_t> clear_key( | |
406 kCommonEncryptionUuid, | |
407 kCommonEncryptionUuid + arraysize(kCommonEncryptionUuid)); | |
408 std::vector<uint8_t> pssh_data; | |
409 | |
410 std::vector<uint8_t> box = MakePSSHBox(1, Key1()); | |
411 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data)); | |
412 EXPECT_EQ(0u, pssh_data.size()); | |
413 | |
414 std::vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; | |
415 AppendData(box, data); | |
416 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data)); | |
417 EXPECT_EQ(data, pssh_data); | |
418 } | |
419 | |
420 TEST_F(CencUtilsTest, GetPsshData_Version2) { | |
421 std::vector<uint8_t> clear_key( | |
422 kCommonEncryptionUuid, | |
423 kCommonEncryptionUuid + arraysize(kCommonEncryptionUuid)); | |
424 std::vector<uint8_t> pssh_data; | |
425 | |
426 std::vector<uint8_t> box = MakePSSHBox(1, Key1()); | |
427 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data)); | |
428 | |
429 // Change the version manually, since we don't know what v2 will contain. | |
430 box[8] = 2; | |
431 EXPECT_FALSE(GetPsshData(box, clear_key, &pssh_data)); | |
432 } | |
433 | |
434 TEST_F(CencUtilsTest, GetPsshData_Version2ThenVersion1) { | |
435 std::vector<uint8_t> clear_key( | |
436 kCommonEncryptionUuid, | |
437 kCommonEncryptionUuid + arraysize(kCommonEncryptionUuid)); | |
438 std::vector<uint8_t> pssh_data; | |
439 | |
440 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); | |
441 std::vector<uint8_t> box2 = MakePSSHBox(2, Key2(), Key3()); | |
442 | |
443 // Concatentate box1 onto end of box2. | |
ddorwin
2015/06/04 22:09:15
This is a little confusing. box_v1 and box_v2 migh
jrummell
2015/06/05 17:57:24
Done.
| |
444 box2.insert(box2.end(), box1.begin(), box1.end()); | |
445 EXPECT_TRUE(GetPsshData(box2, clear_key, &pssh_data)); | |
446 | |
447 // GetKeyIdsForCommonSystemId() should return the single key from the v1 | |
448 // 'pssh' box. | |
449 KeyIdList key_ids; | |
450 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box2, &key_ids)); | |
451 EXPECT_EQ(1u, key_ids.size()); | |
452 EXPECT_EQ(key_ids[0], Key1()); | |
453 } | |
454 | |
455 TEST_F(CencUtilsTest, GetPsshData_Version1ThenVersion2) { | |
456 std::vector<uint8_t> clear_key( | |
457 kCommonEncryptionUuid, | |
458 kCommonEncryptionUuid + arraysize(kCommonEncryptionUuid)); | |
459 std::vector<uint8_t> pssh_data; | |
460 | |
461 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); | |
462 std::vector<uint8_t> box2 = MakePSSHBox(2, Key4()); | |
463 | |
464 // Concatentate box2 onto end of box1. | |
465 box1.insert(box1.end(), box2.begin(), box2.end()); | |
466 EXPECT_TRUE(GetPsshData(box1, clear_key, &pssh_data)); | |
467 | |
468 // GetKeyIdsForCommonSystemId() should return the single key from the v1 | |
469 // 'pssh' box. | |
470 KeyIdList key_ids; | |
471 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids)); | |
472 EXPECT_EQ(1u, key_ids.size()); | |
473 EXPECT_EQ(key_ids[0], Key3()); | |
474 } | |
475 | |
476 TEST_F(CencUtilsTest, GetPsshData_DifferentSystemID) { | |
477 std::vector<uint8_t> clear_key( | |
478 kCommonEncryptionUuid, | |
479 kCommonEncryptionUuid + arraysize(kCommonEncryptionUuid)); | |
480 std::vector<uint8_t> unknown_system_id(kKey1Data, | |
481 kKey1Data + arraysize(kKey1Data)); | |
482 std::vector<uint8_t> pssh_data; | |
483 | |
484 std::vector<uint8_t> box = MakePSSHBox(1, Key1()); | |
485 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data)); | |
486 EXPECT_FALSE(GetPsshData(box, unknown_system_id, &pssh_data)); | |
487 } | |
488 | |
489 TEST_F(CencUtilsTest, GetPsshData_MissingData) { | |
490 std::vector<uint8_t> clear_key( | |
491 kCommonEncryptionUuid, | |
492 kCommonEncryptionUuid + arraysize(kCommonEncryptionUuid)); | |
493 std::vector<uint8_t> pssh_data; | |
494 | |
495 std::vector<uint8_t> box = MakePSSHBox(1, Key1()); | |
496 std::vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; | |
497 AppendData(box, data); | |
498 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data)); | |
499 | |
500 // Remove some data from the end, so now the size is incorrect. | |
501 box.pop_back(); | |
502 box.pop_back(); | |
503 EXPECT_FALSE(GetPsshData(box, clear_key, &pssh_data)); | |
504 } | |
505 | |
506 TEST_F(CencUtilsTest, GetPsshData_MultiplePssh) { | |
507 std::vector<uint8_t> clear_key( | |
508 kCommonEncryptionUuid, | |
509 kCommonEncryptionUuid + arraysize(kCommonEncryptionUuid)); | |
510 std::vector<uint8_t> pssh_data; | |
511 | |
512 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); | |
513 std::vector<uint8_t> data1 = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; | |
514 AppendData(box1, data1); | |
515 | |
516 std::vector<uint8_t> box2 = MakePSSHBox(0); | |
517 std::vector<uint8_t> data2 = {0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}; | |
518 AppendData(box2, data2); | |
519 | |
520 box1.insert(box1.end(), box2.begin(), box2.end()); | |
521 EXPECT_TRUE(GetPsshData(box1, clear_key, &pssh_data)); | |
522 EXPECT_EQ(data1, pssh_data); | |
523 EXPECT_NE(data2, pssh_data); | |
524 } | |
376 } // namespace media | 525 } // namespace media |
OLD | NEW |