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