Always use base64url encoding.

This fixes clearkey errors on newer versions of Chrome 42.

Change-Id: I3c0d7336fa21587fe730c747e8aea92657a6cf33
This commit is contained in:
Joey Parrish
2015-02-27 16:19:52 -08:00
committed by Gerrit Code Review
parent 50de57efad
commit 598e042b4a
2 changed files with 12 additions and 7 deletions
+6 -4
View File
@@ -26,25 +26,27 @@ goog.provide('shaka.util.StringUtils');
/**
* Convert a raw string to a base-64 string.
* Convert a raw string to a base64 string. The output will always use the
* alternate encoding/alphabet also known as "base64url".
* @param {string} str
* @param {boolean=} opt_padding If true, pad the output with equals signs.
* Defaults to true.
* @return {string}
*/
shaka.util.StringUtils.toBase64 = function(str, opt_padding) {
var base64 = window.btoa(str);
var padding = (opt_padding == undefined) ? true : opt_padding;
var base64 = window.btoa(str).replace(/\+/g, '-').replace(/\//g, '_');
return padding ? base64 : base64.replace(/=*$/, '');
};
/**
* Convert a base-64 string to a raw string.
* Convert a base64 string to a raw string. Accepts either the standard
* alphabet or the alternate "base64url" alphabet.
* @param {string} str
* @return {string}
*/
shaka.util.StringUtils.fromBase64 = function(str) {
return window.atob(str);
return window.atob(str.replace(/-/g, '+').replace(/_/g, '/'));
};
+6 -3
View File
@@ -55,7 +55,8 @@ shaka.util.Uint8ArrayUtils.fromString = function(str) {
/**
* Convert a Uint8Array to a base-64 string.
* Convert a Uint8Array to a base64 string. The output will always use the
* alternate encoding/alphabet also known as "base64url".
* @param {!Uint8Array} arr
* @param {boolean=} opt_padding If true, pad the output with equals signs.
* Defaults to true.
@@ -69,13 +70,15 @@ shaka.util.Uint8ArrayUtils.toBase64 = function(arr, opt_padding) {
/**
* Convert a base-64 string to a Uint8Array.
* Convert a base64 string to a Uint8Array. Accepts either the standard
* alphabet or the alternate "base64url" alphabet.
* @param {string} str
* @return {!Uint8Array}
* @export
*/
shaka.util.Uint8ArrayUtils.fromBase64 = function(str) {
return shaka.util.Uint8ArrayUtils.fromString(window.atob(str));
return shaka.util.Uint8ArrayUtils.fromString(
shaka.util.StringUtils.fromBase64(str));
};