1
1
// Refactored conversion functions
2
- const fromHexString = hexString => Uint8Array . from ( hexString . match ( / .{ 1 , 2 } / g) . map ( byte => parseInt ( byte , 16 ) ) ) ;
2
+ const hexStrToU8 = hexString => Uint8Array . from ( hexString . match ( / .{ 1 , 2 } / g) . map ( byte => parseInt ( byte , 16 ) ) ) ;
3
3
4
- const toHexString = bytes => bytes . reduce ( ( str , byte ) => str + byte . toString ( 16 ) . padStart ( 2 , '0' ) , '' ) ;
4
+ const u8ToHexStr = bytes => bytes . reduce ( ( str , byte ) => str + byte . toString ( 16 ) . padStart ( 2 , '0' ) , '' ) ;
5
5
6
- const b64ToHex = b64 => [ ...atob ( b64 ) ] . map ( c => c . charCodeAt ( 0 ) . toString ( 16 ) . padStart ( 2 , 0 ) ) . join ``
6
+ const b64ToHexStr = b64 => [ ...atob ( b64 ) ] . map ( c => c . charCodeAt ( 0 ) . toString ( 16 ) . padStart ( 2 , 0 ) ) . join ``
7
7
8
8
// initData to PSSH
9
9
function getPssh ( buffer ) {
10
- const bytes = fromHexString ( toHexString ( new Uint8Array ( buffer ) ) . match ( / 0 0 0 0 0 0 ..7 0 7 3 7 3 6 8 .* / ) [ 0 ] ) ;
10
+ const bytes = hexStrToU8 ( u8ToHexStr ( new Uint8Array ( buffer ) ) . match ( / 0 0 0 0 0 0 ..7 0 7 3 7 3 6 8 .* / ) [ 0 ] ) ;
11
11
return window . btoa ( String . fromCharCode ( ...bytes ) ) ;
12
12
}
13
13
@@ -16,7 +16,7 @@ function getClearkey(response) {
16
16
let obj = JSON . parse ( ( new TextDecoder ( "utf-8" ) ) . decode ( response ) )
17
17
obj = obj [ "keys" ] . map ( o => [ o [ "kid" ] , o [ "k" ] ] ) ;
18
18
obj = obj . map ( o => o . map ( a => a . replace ( / - / g, '+' ) . replace ( / _ / g, '/' ) + "==" ) )
19
- return obj . map ( o => `${ b64ToHex ( o [ 0 ] ) } :${ b64ToHex ( o [ 1 ] ) } ` ) . join ( "\n" )
19
+ return obj . map ( o => `${ b64ToHexStr ( o [ 0 ] ) } :${ b64ToHexStr ( o [ 1 ] ) } ` ) . join ( "\n" )
20
20
21
21
}
22
22
0 commit comments