|
| 1 | +/** |
| 2 | + * The copyright in this software is being made available under the BSD License, |
| 3 | + * included below. This software may be subject to other third party and contributor |
| 4 | + * rights, including patent rights, and no such rights are granted under this license. |
| 5 | + * |
| 6 | + * Copyright (c) 2013, Dash Industry Forum. |
| 7 | + * All rights reserved. |
| 8 | + * |
| 9 | + * Redistribution and use in source and binary forms, with or without modification, |
| 10 | + * are permitted provided that the following conditions are met: |
| 11 | + * * Redistributions of source code must retain the above copyright notice, this |
| 12 | + * list of conditions and the following disclaimer. |
| 13 | + * * Redistributions in binary form must reproduce the above copyright notice, |
| 14 | + * this list of conditions and the following disclaimer in the documentation and/or |
| 15 | + * other materials provided with the distribution. |
| 16 | + * * Neither the name of Dash Industry Forum nor the names of its |
| 17 | + * contributors may be used to endorse or promote products derived from this software |
| 18 | + * without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY |
| 21 | + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 23 | + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 24 | + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 25 | + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. |
| 30 | + */ |
| 31 | + |
1 | 32 | /** |
2 | 33 | * Utility functions for DASH Certurl normalization. |
3 | | - * Shared by ContentProtection parsing and MediaPlayer.addCertUrls API. |
| 34 | + * Shared by ContentProtection parsing and protData handling. |
4 | 35 | * |
5 | 36 | * A Certurl entry may appear as: |
6 | 37 | * - String: 'https://example.com/cert' |
@@ -59,7 +90,26 @@ function dedupeCertUrls(list) { |
59 | 90 | return result; |
60 | 91 | } |
61 | 92 |
|
| 93 | +/** |
| 94 | + * Iterates over a ProtectionDataSet object and normalizes & deduplicates any certUrls arrays in-place. |
| 95 | + * Returns the same object reference for convenience. |
| 96 | + * @param {Object} protData - keySystem -> config object |
| 97 | + * @returns {Object} protData |
| 98 | + */ |
| 99 | +function sanitizeProtectionDataCertUrls(protData) { |
| 100 | + if (protData && typeof protData === 'object') { |
| 101 | + Object.keys(protData).forEach(keySystem => { |
| 102 | + const entry = protData[keySystem]; |
| 103 | + if (entry && Array.isArray(entry.certUrls)) { |
| 104 | + entry.certUrls = dedupeCertUrls(normalizeCertUrls(entry.certUrls)); |
| 105 | + } |
| 106 | + }); |
| 107 | + } |
| 108 | + return protData; |
| 109 | +} |
| 110 | + |
62 | 111 | export default { |
63 | 112 | normalizeCertUrls, |
64 | | - dedupeCertUrls |
| 113 | + dedupeCertUrls, |
| 114 | + sanitizeProtectionDataCertUrls |
65 | 115 | }; |
0 commit comments