OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Utils provide logging functions and other JS functions commonly used by the | 5 // Utils provide logging functions and other JS functions commonly used by the |
6 // app and media players. | 6 // app and media players. |
7 var Utils = new function() { | 7 var Utils = new function() { |
8 this.titleChanged = false; | 8 this.titleChanged = false; |
9 }; | 9 }; |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // Encodes data (Uint8Array) into base64 string without trailing '='. | 49 // Encodes data (Uint8Array) into base64 string without trailing '='. |
50 // TODO(jrummell): Update once the EME spec is updated to say base64url | 50 // TODO(jrummell): Update once the EME spec is updated to say base64url |
51 // encoding. | 51 // encoding. |
52 function base64Encode(data) { | 52 function base64Encode(data) { |
53 var result = btoa(String.fromCharCode.apply(null, data)); | 53 var result = btoa(String.fromCharCode.apply(null, data)); |
54 return result.replace(/=+$/g, ''); | 54 return result.replace(/=+$/g, ''); |
55 } | 55 } |
56 | 56 |
57 // Creates a JWK from raw key ID and key. | 57 // Creates a JWK from raw key ID and key. |
58 function createJWK(keyId, key) { | 58 function createJWK(keyId, key) { |
59 var jwk = '{"kty":"oct","kid":"'; | 59 var jwk = '{"kty":"oct","alg":"A128KW","kid":"'; |
60 jwk += base64Encode(keyId); | 60 jwk += base64Encode(keyId); |
61 jwk += '","k":"'; | 61 jwk += '","k":"'; |
62 jwk += base64Encode(key); | 62 jwk += base64Encode(key); |
63 jwk += '"}'; | 63 jwk += '"}'; |
64 return jwk; | 64 return jwk; |
65 } | 65 } |
66 | 66 |
67 // Creates a JWK Set from an array of JWK(s). | 67 // Creates a JWK Set from an array of JWK(s). |
68 function createJWKSet() { | 68 function createJWKSet() { |
69 var jwkSet = '{"keys":['; | 69 var jwkSet = '{"keys":['; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 var time = Utils.getCurrentTimeString(); | 275 var time = Utils.getCurrentTimeString(); |
276 // Log to document. | 276 // Log to document. |
277 Utils.documentLog(arguments[0], time); | 277 Utils.documentLog(arguments[0], time); |
278 // Log to JS console. | 278 // Log to JS console. |
279 var logString = time + ' - '; | 279 var logString = time + ' - '; |
280 for (var i = 0; i < arguments.length; i++) { | 280 for (var i = 0; i < arguments.length; i++) { |
281 logString += ' ' + arguments[i]; | 281 logString += ' ' + arguments[i]; |
282 } | 282 } |
283 console.log(logString); | 283 console.log(logString); |
284 }; | 284 }; |
OLD | NEW |