import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var bV=function(a){a=_.Ri(a);const b=new Uint32Array(4);for(let c=0;4>c;c++)b[c]=a.getUint32(4*c);return b},dV=function(a,b){return c=>_.x(function*(){const d=c.request||null;if(d&&2===d.type&&d.keyInfo&&c.data){const e=d.uris[0];a.g.debug("Decrypting AES-128-encrypted video segment",e);c.data=yield cV(a,b,c.data,d.keyInfo,e)}return c})},cV=function(a,b,c,d,e){return _.x(function*(){let f=new ArrayBuffer(0);try{f=yield eV(a,b,d.url)}catch(g){return a.g.warn("Could not fetch AES key",
g),b.onError(new _.I(1,7,7104,null,g)),c}try{const g=a.l?new fV:new gV;yield g.importKey(f);return yield g.decrypt(c,d.iv)}catch(g){return a.g.warn("Could not decrypt segment data!",e,g),b.onError(new _.I(1,3,3103,null,g)),c}})},eV=function(a,b,c){return _.x(function*(){const d=_.mj(c),e=(new _.mi(c)).Xa.endsWith(".drmtoday.com");if(e){var f=b.getConfiguration();_.Am(d,f)}f=c+JSON.stringify(d.headers);if(a.j[f])return a.j[f];try{const g=yield b.getNetworkEngine().fetch(d).T;return a.j[f]=g.data}catch(g){throw e&&
1001===g.code&&412===g.data.status&&a.g.warn("Wrong DRMtoday credentials, server responded with 412."),g;}})},gV=class{constructor(){this.B=[0,1,2,4,8,16,32,64,128,27,54];this.C=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)];this.l=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)];this.A=new Uint32Array(256);this.o=new Uint32Array(256);this.w=new Uint32Array(0);this.h=this.a=this.j=this.f=null;{const c=this.A,d=this.o;var a=
this.C;const e=a[0],f=a[1],g=a[2];a=a[3];var b=this.l;const h=b[0],k=b[1],l=b[2];b=b[3];const m=new Uint32Array(256);let n=0,r=0,u;for(u=0;256>u;u++)m[u]=128>u?u<<1:u<<1^283;for(u=0;256>u;u++){let v=r^r<<1^r<<2^r<<3^r<<4;v=v>>>8^v&255^99;c[n]=v;d[v]=n;const y=m[n],A=m[y],D=m[A];let E=257*m[v]^16843008*v;e[n]=E<<24|E>>>8;f[n]=E<<16|E>>>16;g[n]=E<<8|E>>>24;a[n]=E;E=16843009*D^65537*A^257*y^16843008*n;h[v]=E<<24|E>>>8;k[v]=E<<16|E>>>16;l[v]=E<<8|E>>>24;b[v]=E;n?(n=y^m[m[m[D^y]]],r^=m[m[r]]):n=r=1}}}importKey(a){a=
bV(a);for(var b=!0,c=0;c<a.length&&b;)b=a[c]===this.w[c],c++;if(b)return new Promise(m=>m());this.w=a;this.a=a.length;if(4!==this.a&&6!==this.a&&8!==this.a)throw Error("Invalid aes key size\x3d"+this.a);this.h=4*(this.a+7);this.f=new Uint32Array(this.h);this.j=new Uint32Array(this.h);b=this.A;const d=this.B;var e=this.l;c=e[0];const f=e[1],g=e[2],h=e[3];let k=0,l=0;for(e=0;e<this.h;e++)e<this.a?k=this.f[e]=a[e]:(l=k,0===e%this.a?(l=l<<8|l>>>24,l=b[l>>>24]<<24|b[l>>>16&255]<<16|b[l>>>8&255]<<8|b[l&
255],l^=d[e/this.a|0]<<24):6<this.a&&4===e%this.a&&(l=b[l>>>24]<<24|b[l>>>16&255]<<16|b[l>>>8&255]<<8|b[l&255]),k=(this.f[e-this.a]^l)>>>0,this.f[e]=k);for(a=0;a<this.h;a++)e=this.h-a,l=a&3?this.f[e]:this.f[e-4],this.j[a]=4>a||4>=e?l:c[b[l>>>24]]^f[b[l>>>16&255]]^g[b[l>>>8&255]]^h[b[l&255]],this.j[a]>>>=0;return new Promise(m=>m())}decrypt(a,b){let c=0;const d=this.a+6,e=this.j,f=this.o;var g=this.l;const h=g[0],k=g[1],l=g[2];g=g[3];var m=bV(b);b=m[0];let n=m[1],r=m[2];m=m[3];a=_.Qi(a);const u=new Int32Array(a.length);
let v,y,A;let D,E,X,cd,gc,Ob,Vd,Pb,hc;const ic=this.F.bind(this);for(;c<a.length;){cd=ic(a[c]);gc=ic(a[c+1]);Ob=ic(a[c+2]);Vd=ic(a[c+3]);D=cd^e[0];E=Vd^e[1];X=Ob^e[2];var Gb=gc^e[3];Pb=4;for(hc=1;hc<d;hc++)v=h[D>>>24]^k[E>>16&255]^l[X>>8&255]^g[Gb&255]^e[Pb],y=h[E>>>24]^k[X>>16&255]^l[Gb>>8&255]^g[D&255]^e[Pb+1],A=h[X>>>24]^k[Gb>>16&255]^l[D>>8&255]^g[E&255]^e[Pb+2],Gb=h[Gb>>>24]^k[D>>16&255]^l[E>>8&255]^g[X&255]^e[Pb+3],D=v,E=y,X=A,Pb+=4;v=f[D>>>24]<<24^f[E>>16&255]<<16^f[X>>8&255]<<8^f[Gb&255]^
e[Pb];y=f[E>>>24]<<24^f[X>>16&255]<<16^f[Gb>>8&255]<<8^f[D&255]^e[Pb+1];A=f[X>>>24]<<24^f[Gb>>16&255]<<16^f[D>>8&255]<<8^f[E&255]^e[Pb+2];Gb=f[Gb>>>24]<<24^f[D>>16&255]<<16^f[E>>8&255]<<8^f[X&255]^e[Pb+3];Pb+=3;u[c]=ic(v^b);u[c+1]=ic(Gb^n);u[c+2]=ic(A^r);u[c+3]=ic(y^m);b=cd;n=gc;r=Ob;m=Vd;c+=4}return new Promise(hb=>{{var ua=u.buffer;const zb=ua.byteLength,Bc=zb&&(new DataView(ua)).getUint8(zb-1);ua=Bc?ua.slice(0,zb-Bc):ua}hb(ua)})}destroy(){this.B=this.j=this.f=this.l=this.C=this.o=this.A=this.h=
this.a=this.w=null;return new Promise(a=>a())}F(a){return a<<24|(a&65280)<<8|(a&16711680)>>8|a>>>24}};var fV=class{constructor(){this.a=null}importKey(a){const b=this;return _.x(function*(){b.a=yield crypto.subtle.importKey("raw",a,{name:"AES-CBC"},!1,["decrypt"])})}decrypt(a,b){const c=this;return _.x(function*(){return yield crypto.subtle.decrypt({name:"AES-CBC",iv:b},c.a,a)})}destroy(){this.a=null;return new Promise(a=>a())}};_.z("clpp.crypto.CryptoComponent",class extends _.Av{constructor(){super();this.j={};this.l=!1;this.g=new _.S("clpp.crypto")}f(){if(window.crypto&&crypto.subtle){var a=crypto.subtle.decrypt;a=typeof crypto.subtle.importKey===_.Yd&&typeof a===_.Yd}else a=!1;(this.l=a)||this.g.warn("No WebCrypto APIs found. Will fallback to software AES")}o(a){const b=dV(this,a);a.getNetworkEngine().Gc(b)}a(){this.j={}}id(){return"crypto"}});};f.call(g, window);