Use standard base64 encoding in FairPlay license request (#1932)

Closes #1915
This commit is contained in:
bcupac
2019-05-09 18:55:38 +02:00
committed by Joey Parrish
parent 47daf49f31
commit b8f032a05e
3 changed files with 18 additions and 6 deletions
+14 -4
View File
@@ -26,6 +26,18 @@ goog.require('shaka.util.StringUtils');
* @exportDoc
*/
/**
* Convert a Uint8Array to a base64 string. The output will be standard alphabet
* as opposed to base64url safe alphabet.
* @param {!Uint8Array} u8Arr
* @return {string}
* @export
*/
shaka.util.Uint8ArrayUtils.toStandardBase64 = function(u8Arr) {
const bytes = shaka.util.StringUtils.fromCharCode(u8Arr);
return btoa(bytes);
};
/**
* Convert a Uint8Array to a base64 string. The output will always use the
@@ -37,14 +49,12 @@ goog.require('shaka.util.StringUtils');
* @export
*/
shaka.util.Uint8ArrayUtils.toBase64 = function(arr, padding) {
// btoa expects a "raw string" where each character is interpreted as a byte.
const bytes = shaka.util.StringUtils.fromCharCode(arr);
padding = (padding == undefined) ? true : padding;
const base64 = window.btoa(bytes).replace(/\+/g, '-').replace(/\//g, '_');
const base64 = shaka.util.Uint8ArrayUtils.toStandardBase64(arr)
.replace(/\+/g, '-').replace(/\//g, '_');
return padding ? base64 : base64.replace(/=*$/, '');
};
/**
* Convert a base64 string to a Uint8Array. Accepts either the standard
* alphabet or the alternate "base64url" alphabet.