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 }; |
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)), |
| 40 common_system_system_id_( |
| 41 kCommonSystemSystemId, |
| 42 kCommonSystemSystemId + arraysize(kCommonSystemSystemId)) {} |
36 | 43 |
37 protected: | 44 protected: |
38 // Initialize the start of the 'pssh' box (up to key_count) | 45 // Initialize the start of the 'pssh' box (up to key_count) |
39 void InitializePSSHBox(std::vector<uint8_t>* box, | 46 void InitializePSSHBox(std::vector<uint8_t>* box, |
40 uint8_t size, | 47 uint8_t size, |
41 uint8_t version) { | 48 uint8_t version) { |
42 DCHECK(box->size() == 0); | 49 DCHECK(box->size() == 0); |
43 | 50 |
44 box->reserve(size); | 51 box->reserve(size); |
45 // Add size. | 52 // Add size. |
46 box->push_back(0); | 53 box->push_back(0); |
47 box->push_back(0); | 54 box->push_back(0); |
48 box->push_back(0); | 55 box->push_back(0); |
49 box->push_back(size); | 56 box->push_back(size); |
50 // Add 'pssh'. | 57 // Add 'pssh'. |
51 box->push_back('p'); | 58 box->push_back('p'); |
52 box->push_back('s'); | 59 box->push_back('s'); |
53 box->push_back('s'); | 60 box->push_back('s'); |
54 box->push_back('h'); | 61 box->push_back('h'); |
55 // Add version. | 62 // Add version. |
56 box->push_back(version); | 63 box->push_back(version); |
57 // Add flags. | 64 // Add flags. |
58 box->push_back(0); | 65 box->push_back(0); |
59 box->push_back(0); | 66 box->push_back(0); |
60 box->push_back(0); | 67 box->push_back(0); |
61 // Add Clear Key SystemID. | 68 // Add Common Encryption SystemID. |
62 box->push_back(0x10); | 69 box->insert(box->end(), common_system_system_id_.begin(), |
63 box->push_back(0x77); | 70 common_system_system_id_.end()); |
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 } | 71 } |
79 | 72 |
80 std::vector<uint8_t> MakePSSHBox(uint8_t version) { | 73 std::vector<uint8_t> MakePSSHBox(uint8_t version) { |
81 std::vector<uint8_t> box; | 74 std::vector<uint8_t> box; |
82 uint8_t size = (version == 0) ? 32 : 36; | 75 uint8_t size = (version == 0) ? 32 : 36; |
83 InitializePSSHBox(&box, size, version); | 76 InitializePSSHBox(&box, size, version); |
84 if (version > 0) { | 77 if (version > 0) { |
85 // Add key_count (= 0). | 78 // Add key_count (= 0). |
86 box.push_back(0); | 79 box.push_back(0); |
87 box.push_back(0); | 80 box.push_back(0); |
(...skipping 17 matching lines...) Expand all Loading... |
105 uint8_t size = 52; | 98 uint8_t size = 52; |
106 InitializePSSHBox(&box, size, version); | 99 InitializePSSHBox(&box, size, version); |
107 | 100 |
108 // Add key_count (= 1). | 101 // Add key_count (= 1). |
109 box.push_back(0); | 102 box.push_back(0); |
110 box.push_back(0); | 103 box.push_back(0); |
111 box.push_back(0); | 104 box.push_back(0); |
112 box.push_back(1); | 105 box.push_back(1); |
113 | 106 |
114 // Add key1. | 107 // Add key1. |
115 for (int i = 0; i < 16; ++i) | 108 for (size_t i = 0; i < key1.size(); ++i) |
116 box.push_back(key1[i]); | 109 box.push_back(key1[i]); |
117 | 110 |
118 // Add data_size (= 0). | 111 // Add data_size (= 0). |
119 box.push_back(0); | 112 box.push_back(0); |
120 box.push_back(0); | 113 box.push_back(0); |
121 box.push_back(0); | 114 box.push_back(0); |
122 box.push_back(0); | 115 box.push_back(0); |
123 return box; | 116 return box; |
124 } | 117 } |
125 | 118 |
126 std::vector<uint8_t> MakePSSHBox(uint8_t version, | 119 std::vector<uint8_t> MakePSSHBox(uint8_t version, |
127 const std::vector<uint8_t>& key1, | 120 const std::vector<uint8_t>& key1, |
128 const std::vector<uint8_t>& key2) { | 121 const std::vector<uint8_t>& key2) { |
129 DCHECK(version > 0); | 122 DCHECK(version > 0); |
130 DCHECK(key1.size() == 16); | 123 DCHECK(key1.size() == 16); |
131 DCHECK(key2.size() == 16); | 124 DCHECK(key2.size() == 16); |
132 | 125 |
133 std::vector<uint8_t> box; | 126 std::vector<uint8_t> box; |
134 uint8_t size = 68; | 127 uint8_t size = 68; |
135 InitializePSSHBox(&box, size, version); | 128 InitializePSSHBox(&box, size, version); |
136 | 129 |
137 // Add key_count (= 2). | 130 // Add key_count (= 2). |
138 box.push_back(0); | 131 box.push_back(0); |
139 box.push_back(0); | 132 box.push_back(0); |
140 box.push_back(0); | 133 box.push_back(0); |
141 box.push_back(2); | 134 box.push_back(2); |
142 | 135 |
143 // Add key1. | 136 // Add key1. |
144 for (int i = 0; i < 16; ++i) | 137 for (size_t i = 0; i < key1.size(); ++i) |
145 box.push_back(key1[i]); | 138 box.push_back(key1[i]); |
146 | 139 |
147 // Add key2. | 140 // Add key2. |
148 for (int i = 0; i < 16; ++i) | 141 for (size_t i = 0; i < key2.size(); ++i) |
149 box.push_back(key2[i]); | 142 box.push_back(key2[i]); |
150 | 143 |
151 // Add data_size (= 0). | 144 // Add data_size (= 0). |
152 box.push_back(0); | 145 box.push_back(0); |
153 box.push_back(0); | 146 box.push_back(0); |
154 box.push_back(0); | 147 box.push_back(0); |
155 box.push_back(0); | 148 box.push_back(0); |
156 return box; | 149 return box; |
157 } | 150 } |
158 | 151 |
| 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 |
159 const std::vector<uint8_t>& Key1() { return key1_; } | 164 const std::vector<uint8_t>& Key1() { return key1_; } |
160 const std::vector<uint8_t>& Key2() { return key2_; } | 165 const std::vector<uint8_t>& Key2() { return key2_; } |
161 const std::vector<uint8_t>& Key3() { return key3_; } | 166 const std::vector<uint8_t>& Key3() { return key3_; } |
162 const std::vector<uint8_t>& Key4() { return key4_; } | 167 const std::vector<uint8_t>& Key4() { return key4_; } |
| 168 const std::vector<uint8_t>& CommonSystemSystemId() { |
| 169 return common_system_system_id_; |
| 170 } |
163 | 171 |
164 private: | 172 private: |
165 std::vector<uint8_t> key1_; | 173 std::vector<uint8_t> key1_; |
166 std::vector<uint8_t> key2_; | 174 std::vector<uint8_t> key2_; |
167 std::vector<uint8_t> key3_; | 175 std::vector<uint8_t> key3_; |
168 std::vector<uint8_t> key4_; | 176 std::vector<uint8_t> key4_; |
| 177 std::vector<uint8_t> common_system_system_id_; |
169 }; | 178 }; |
170 | 179 |
171 TEST_F(CencUtilsTest, EmptyPSSH) { | 180 TEST_F(CencUtilsTest, EmptyPSSH) { |
172 KeyIdList key_ids; | 181 KeyIdList key_ids; |
173 EXPECT_TRUE(ValidatePsshInput(std::vector<uint8_t>())); | 182 EXPECT_TRUE(ValidatePsshInput(std::vector<uint8_t>())); |
174 EXPECT_TRUE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids)); | 183 EXPECT_TRUE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids)); |
175 EXPECT_EQ(0u, key_ids.size()); | 184 EXPECT_EQ(0u, key_ids.size()); |
176 } | 185 } |
177 | 186 |
178 TEST_F(CencUtilsTest, PSSHVersion0) { | 187 TEST_F(CencUtilsTest, PSSHVersion0) { |
(...skipping 28 matching lines...) Expand all Loading... |
207 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); | 216 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); |
208 EXPECT_EQ(2u, key_ids.size()); | 217 EXPECT_EQ(2u, key_ids.size()); |
209 EXPECT_EQ(key_ids[0], Key1()); | 218 EXPECT_EQ(key_ids[0], Key1()); |
210 EXPECT_EQ(key_ids[1], Key2()); | 219 EXPECT_EQ(key_ids[1], Key2()); |
211 } | 220 } |
212 | 221 |
213 TEST_F(CencUtilsTest, PSSHVersion0Plus1) { | 222 TEST_F(CencUtilsTest, PSSHVersion0Plus1) { |
214 std::vector<uint8_t> box0 = MakePSSHBox(0); | 223 std::vector<uint8_t> box0 = MakePSSHBox(0); |
215 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); | 224 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); |
216 | 225 |
217 // Concatentate box1 into box0. | 226 // Concatentate box1 onto end of box0. |
218 for (const auto& value : box1) | 227 box0.insert(box0.end(), box1.begin(), box1.end()); |
219 box0.push_back(value); | |
220 | 228 |
221 KeyIdList key_ids; | 229 KeyIdList key_ids; |
222 EXPECT_TRUE(ValidatePsshInput(box0)); | 230 EXPECT_TRUE(ValidatePsshInput(box0)); |
223 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box0, &key_ids)); | 231 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box0, &key_ids)); |
224 EXPECT_EQ(1u, key_ids.size()); | 232 EXPECT_EQ(1u, key_ids.size()); |
225 EXPECT_EQ(key_ids[0], Key1()); | 233 EXPECT_EQ(key_ids[0], Key1()); |
226 } | 234 } |
227 | 235 |
228 TEST_F(CencUtilsTest, PSSHVersion1Plus0) { | 236 TEST_F(CencUtilsTest, PSSHVersion1Plus0) { |
229 std::vector<uint8_t> box0 = MakePSSHBox(0); | 237 std::vector<uint8_t> box0 = MakePSSHBox(0); |
230 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); | 238 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); |
231 | 239 |
232 // Concatentate box0 into box1. | 240 // Concatentate box0 onto end of box1. |
233 for (const auto& value : box0) | 241 box1.insert(box1.end(), box0.begin(), box0.end()); |
234 box1.push_back(value); | |
235 | 242 |
236 KeyIdList key_ids; | 243 KeyIdList key_ids; |
237 EXPECT_TRUE(ValidatePsshInput(box1)); | 244 EXPECT_TRUE(ValidatePsshInput(box1)); |
238 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids)); | 245 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids)); |
239 EXPECT_EQ(1u, key_ids.size()); | 246 EXPECT_EQ(1u, key_ids.size()); |
240 EXPECT_EQ(key_ids[0], Key1()); | 247 EXPECT_EQ(key_ids[0], Key1()); |
241 } | 248 } |
242 | 249 |
243 TEST_F(CencUtilsTest, MultiplePSSHVersion1) { | 250 TEST_F(CencUtilsTest, MultiplePSSHVersion1) { |
244 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 251 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
245 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); | 252 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); |
246 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4()); | 253 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4()); |
247 | 254 |
248 // Concatentate box1 into box. | 255 // Concatentate box1 and box2 onto end of box. |
249 for (const auto& value : box1) | 256 box.insert(box.end(), box1.begin(), box1.end()); |
250 box.push_back(value); | 257 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 | 258 |
255 KeyIdList key_ids; | 259 KeyIdList key_ids; |
256 EXPECT_TRUE(ValidatePsshInput(box)); | 260 EXPECT_TRUE(ValidatePsshInput(box)); |
257 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); | 261 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); |
258 EXPECT_EQ(4u, key_ids.size()); | 262 EXPECT_EQ(4u, key_ids.size()); |
259 EXPECT_EQ(key_ids[0], Key1()); | 263 EXPECT_EQ(key_ids[0], Key1()); |
260 EXPECT_EQ(key_ids[1], Key2()); | 264 EXPECT_EQ(key_ids[1], Key2()); |
261 EXPECT_EQ(key_ids[2], Key3()); | 265 EXPECT_EQ(key_ids[2], Key3()); |
262 EXPECT_EQ(key_ids[3], Key4()); | 266 EXPECT_EQ(key_ids[3], Key4()); |
263 } | 267 } |
264 | 268 |
265 TEST_F(CencUtilsTest, InvalidPSSH) { | 269 TEST_F(CencUtilsTest, InvalidPSSH) { |
266 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 270 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
267 KeyIdList key_ids; | 271 KeyIdList key_ids; |
268 for (uint32 i = 1; i < box.size(); ++i) { | 272 for (size_t i = 1; i < box.size(); ++i) { |
269 // Modify size of data passed to be less than real size. | 273 // Modify size of data passed to be less than real size. |
270 std::vector<uint8_t> truncated(&box[0], &box[0] + i); | 274 std::vector<uint8_t> truncated(&box[0], &box[0] + i); |
271 EXPECT_FALSE(ValidatePsshInput(truncated)); | 275 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i; |
272 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); | 276 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); |
273 // Modify starting point. | 277 // Modify starting point. |
274 std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i); | 278 std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i); |
275 EXPECT_FALSE(ValidatePsshInput(changed_offset)); | 279 EXPECT_FALSE(ValidatePsshInput(changed_offset)) << "Failed for offset " |
| 280 << i; |
276 EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids)); | 281 EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids)); |
277 } | 282 } |
278 } | 283 } |
279 | 284 |
280 TEST_F(CencUtilsTest, InvalidSystemID) { | 285 TEST_F(CencUtilsTest, InvalidSystemID) { |
281 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 286 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
282 | 287 |
283 // Modify the System ID. | 288 // Modify the System ID. |
284 ++box[20]; | 289 ++box[20]; |
285 | 290 |
286 KeyIdList key_ids; | 291 KeyIdList key_ids; |
287 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); | 292 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); |
288 EXPECT_EQ(0u, key_ids.size()); | 293 EXPECT_EQ(0u, key_ids.size()); |
289 } | 294 } |
290 | 295 |
291 TEST_F(CencUtilsTest, InvalidFlags) { | 296 TEST_F(CencUtilsTest, InvalidFlags) { |
292 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 297 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
293 | 298 |
294 // Modify flags. | 299 // Modify flags. |
295 box[10] = 3; | 300 box[10] = 3; |
296 | 301 |
297 KeyIdList key_ids; | 302 KeyIdList key_ids; |
298 // TODO(jrummell): This should fail as the 'pssh' box is skipped. | 303 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); |
299 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); | |
300 EXPECT_EQ(0u, key_ids.size()); | |
301 } | 304 } |
302 | 305 |
303 TEST_F(CencUtilsTest, LongSize) { | 306 TEST_F(CencUtilsTest, LongSize) { |
304 const uint8_t data[] = { | 307 const uint8_t data[] = { |
305 0x00, 0x00, 0x00, 0x01, // size = 1 | 308 0x00, 0x00, 0x00, 0x01, // size = 1 |
306 0x70, 0x73, 0x73, 0x68, // 'pssh' | 309 0x70, 0x73, 0x73, 0x68, // 'pssh' |
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // longsize | 310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // longsize |
308 0x01, // version | 311 0x01, // version |
309 0x00, 0x00, 0x00, // flags | 312 0x00, 0x00, 0x00, // flags |
310 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID | 313 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 | 369 0x00, 0x00, 0x00, 0x00 // datasize |
367 }; | 370 }; |
368 | 371 |
369 KeyIdList key_ids; | 372 KeyIdList key_ids; |
370 EXPECT_FALSE( | 373 EXPECT_FALSE( |
371 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); | 374 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); |
372 EXPECT_FALSE(GetKeyIdsForCommonSystemId( | 375 EXPECT_FALSE(GetKeyIdsForCommonSystemId( |
373 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); | 376 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); |
374 } | 377 } |
375 | 378 |
| 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 } |
376 } // namespace media | 515 } // namespace media |
OLD | NEW |