/* MIT License MIT License MIT License MIT MIT License MIT License MIT License */ (function(ma,u){"object"===typeof exports?module.exports.printStackTrace=u():"function"===typeof define&&define.amd?define(u):ma.printStackTrace=u()})(this,function(){function ma(u){u=u||{guess:!0};var J=u.e||null,T=!!u.guess,U=u.mode||null;u=new ma.implementation;J=u.run(J,U);return T?u.guessAnonymousFunctions(J):J}ma.implementation=function(){};ma.implementation.prototype={run:function(u,J){u=u||this.createException();J=J||this.mode(u);return"other"===J?this.other(arguments.callee):this[J](u)}, createException:function(){try{this.undef()}catch(u){return u}},mode:function(u){return"undefined"!==typeof window&&-1u.stacktrace.split("\n").length?"opera9":"opera10a":u.message&&u.stack&&u.stacktrace?0>u.stacktrace.indexOf("called from line")? "opera10b":"opera11":u.stack&&!u.fileName?"chrome":"other"},instrumentFunction:function(u,J,T){u=u||window;var U=u[J];u[J]=function(){T.call(this,ma().slice(4));return u[J]._instrumented.apply(this,arguments)};u[J]._instrumented=U},deinstrumentFunction:function(u,J){u[J].constructor===Function&&u[J]._instrumented&&u[J]._instrumented.constructor===Function&&(u[J]=u[J]._instrumented)},chrome:function(u){return(u.stack+"\n").replace(/^[\s\S]+?\s+at\s+/," at ").replace(/^\s+(at eval )?at\s+/gm,"").replace(/^([^\(]+?)([\n$])/gm, "{anonymous}() ($1)$2").replace(/^Object.\s*\(([^\)]+)\)/gm,"{anonymous}() ($1)").replace(/^(.+) \((.+)\)$/gm,"$1@$2").split("\n").slice(0,-1)},safari:function(u){return u.stack.replace(/\[native code\]\n/m,"").replace(/^(?=\w+Error\:).*$\n/m,"").replace(/^@/gm,"{anonymous}()@").split("\n")},ie:function(u){return u.stack.replace(/^\s*at\s+(.*)$/gm,"$1").replace(/^Anonymous function\s+/gm,"{anonymous}() ").replace(/^(.+)\s+\((.+)\)$/gm,"$1@$2").split("\n").slice(1)},firefox:function(u){return u.stack.replace(/(?:\n@:0)?\s+$/m, "").replace(/^(?:\((\S*)\))?@/gm,"{anonymous}($1)@").split("\n")},opera11:function(u){var J=/^.*line (\d+), column (\d+)(?: in (.+))? in (\S+):$/;u=u.stacktrace.split("\n");for(var T=[],U=0,X=u.length;U/,"$1").replace(//,"{anonymous}");T.push(K+"@"+z+" -- "+u[U+1].replace(/^\s+/,""))}}return T},opera10b:function(u){var J=/^(.*)@(.+):(\d+)$/;u=u.stacktrace.split("\n"); for(var T=[],U=0,X=u.length;UT.length;){U=J.test(u.toString())?RegExp.$1||"{anonymous}":"{anonymous}"; try{X=K.call(u.arguments||[])}catch(z){X=["Cannot access arguments: "+z]}T[T.length]=U+"("+this.stringifyArguments(X)+")";try{u=u.caller}catch(ma){T[T.length]="Cannot access caller: "+ma;break}}return T},stringifyArguments:function(u){for(var J=[],T=Array.prototype.slice,U=0;UX.length?"["+this.stringifyArguments(X)+"]":"["+this.stringifyArguments(T.call(X,0,1))+"..."+this.stringifyArguments(T.call(X, -1))+"]":X.constructor===Object?"#object":X.constructor===Function?"#function":X.constructor===String?'"'+X+'"':X.constructor===Number?X:"?")}return J.join(",")},sourceCache:{},ajax:function(u){var J=this.createXMLHTTPObject();if(J)try{return J.open("GET",u,!1),J.send(null),J.responseText}catch(T){}return""},createXMLHTTPObject:function(){for(var u,J=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")}, function(){return new ActiveXObject("Microsoft.XMLHTTP")}],T=0;Tp||(0==d?(k+=Xb.charAt(p>>2),q=p&3,d=1):1==d?(k+=Xb.charAt(q<<2|p>>4),q=p&15,d=2):2==d?(k+=Xb.charAt(q),k+=Xb.charAt(p>>2),q=p&3,d=3):(k+=Xb.charAt(q<<2|p>>4),k+=Xb.charAt(p&15),d=0));1==d&&(k+=Xb.charAt(q<<2));return k}function J(){this.j=this.i=0;this.S=[]}function T(){var e=(new Date).getTime();Cb[Pa++]^=e&255;Cb[Pa++]^=e>>8&255;Cb[Pa++]^=e>>16&255;Cb[Pa++]^=e>>24&255;Pa>=Hd&&(Pa-= Hd)}function U(){}function X(e,k){return new B(e,k)}function K(e,k,g){for(var d="",q=0;d.length>24,(q&16711680)>>16,(q&65280)>>8,q&255]))),q+=1;return d}function z(){this.n=null;this.e=0;this.coeff=this.dmq1=this.dmp1=this.q=this.p=this.d=null}function Td(e,k,g){for(var d="",q=0;d.length>24,(q&16711680)>>16,(q&65280)>>8,q&255])),q+=1;return d}function sd(e){var k=[],g=H.getStartPosOfV_AtObj(e, 0),d=H.getPosOfNextSibling_AtObj(e,g),q=H.getPosOfNextSibling_AtObj(e,d),p=H.getPosOfNextSibling_AtObj(e,q),a=H.getPosOfNextSibling_AtObj(e,p),b=H.getPosOfNextSibling_AtObj(e,a),c=H.getPosOfNextSibling_AtObj(e,b),f=H.getPosOfNextSibling_AtObj(e,c),h=H.getPosOfNextSibling_AtObj(e,f);k.push(g,d,q,p,a,b,c,f,h);g=H.getHexOfV_AtObj(e,k[0]);d=H.getHexOfV_AtObj(e,k[1]);q=H.getHexOfV_AtObj(e,k[2]);p=H.getHexOfV_AtObj(e,k[3]);a=H.getHexOfV_AtObj(e,k[4]);b=H.getHexOfV_AtObj(e,k[5]);c=H.getHexOfV_AtObj(e,k[6]); f=H.getHexOfV_AtObj(e,k[7]);e=H.getHexOfV_AtObj(e,k[8]);k=[];k.push(g,d,q,p,a,b,c,f,e);return k}function Jb(e,k){for(var g="",d=k/4-e.length,q=0;q>24,(q&16711680)>>16,(q& 65280)>>8,q&255])))),q+=1;return d}function we(e,k,g){e=rstrtohex(e);e=O.crypto.Util.hashHex(e,k);void 0===g&&(g=-1);return this.signWithMessageHashPSS(e,k,g)}function de(e){for(var k in O.crypto.Util.DIGESTINFOHEAD){var g=O.crypto.Util.DIGESTINFOHEAD[k],d=g.length;if(e.substring(0,d)==g)return[k,e.substring(d)]}return[]}function ud(e,k){var g=X(e,16);var d=this.n.toString(16),q=this.e.toString(16),p=new z;p.setPublic(d,q);g=p.doPublic(g).toString(16).replace(/^1f+00/,"");d=de(g);0==d.length?g=!1: (g=d[1],d=O.crypto.Util.hashString(k,d[0]),g=g==d);return g}function Id(e,k){k=k.replace(Vd,"");k=k.replace(/[ \n]+/g,"");var g=X(k,16);if(g.bitLength()>this.n.bitLength())return 0;var g=this.doPublic(g).toString(16).replace(/^1f+00/,""),d=de(g);if(0==d.length)return!1;g=d[1];d=O.crypto.Util.hashString(e,d[0]);return g==d}function ee(e,k,g,d){e=rstrtohex(e);e=O.crypto.Util.hashHex(e,g);void 0===d&&(d=-1);return this.verifyWithMessageHashPSS(e,k,g,d)}function ga(){this.hex=this.subjectPublicKeyRSA_hE= this.subjectPublicKeyRSA_hN=this.subjectPublicKeyRSA=null;this.getSerialNumberHex=function(){return H.getDecendantHexVByNthList(this.hex,0,[0,1])};this.getIssuerHex=function(){return H.getDecendantHexTLVByNthList(this.hex,0,[0,3])};this.getIssuerString=function(){return ga.hex2dn(H.getDecendantHexTLVByNthList(this.hex,0,[0,3]))};this.getSubjectHex=function(){return H.getDecendantHexTLVByNthList(this.hex,0,[0,5])};this.getSubjectString=function(){return ga.hex2dn(H.getDecendantHexTLVByNthList(this.hex, 0,[0,5]))};this.getNotBefore=function(){var e=H.getDecendantHexVByNthList(this.hex,0,[0,4,0]),e=e.replace(/(..)/g,"%$1");return e=decodeURIComponent(e)};this.getNotAfter=function(){var e=H.getDecendantHexVByNthList(this.hex,0,[0,4,1]),e=e.replace(/(..)/g,"%$1");return e=decodeURIComponent(e)};this.readCertPEM=function(e){e=ga.pemToHex(e);var k=ga.getPublicKeyHexArrayFromCertHex(e),g=new z;g.setPublic(k[0],k[1]);this.subjectPublicKeyRSA=g;this.subjectPublicKeyRSA_hN=k[0];this.subjectPublicKeyRSA_hE= k[1];this.hex=e};this.readCertPEMWithoutRSAInit=function(e){e=ga.pemToHex(e);var k=ga.getPublicKeyHexArrayFromCertHex(e);this.subjectPublicKeyRSA.setPublic(k[0],k[1]);this.subjectPublicKeyRSA_hN=k[0];this.subjectPublicKeyRSA_hE=k[1];this.hex=e}}function ia(){return new B(null)}function Nb(e,k,g,d,q,p){for(;0<=--p;){var a=k*this[e++]+g[d]+q;q=Math.floor(a/67108864);g[d++]=a&67108863}return q}function xe(e,k,g,d,q,p){var a=k&32767;for(k>>=15;0<=--p;){var b=this[e]&32767,c=this[e++]>>15,f=k*b+c*a,b= a*b+((f&32767)<<15)+g[d]+(q&1073741823);q=(b>>>30)+(f>>>15)+k*c+(q>>>30);g[d++]=b&1073741823}return q}function fe(e,k,g,d,q,p){var a=k&16383;for(k>>=14;0<=--p;){var b=this[e]&16383,c=this[e++]>>14,f=k*b+c*a,b=a*b+((f&16383)<<14)+g[d]+q;q=(b>>28)+(f>>14)+k*c;g[d++]=b&268435455}return q}function $c(e,k){var g=ye[e.charCodeAt(k)];return null==g?-1:g}function Kc(e){var k=ia();k.fromInt(e);return k}function Jd(e){var k=1,g;0!=(g=e>>>16)&&(e=g,k+=16);0!=(g=e>>8)&&(e=g,k+=8);0!=(g=e>>4)&&(e=g,k+=4);0!=(g= e>>2)&&(e=g,k+=2);0!=e>>1&&(k+=1);return k}function zc(e){this.m=e}function Qa(e){this.m=e;this.mp=e.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<>>2]|=(g[q>>>2]>>>24-q%4*8&255)<<24-(k+q)%4*8;else for(q=0;q>>2]=g[q>>>2];this.sigBytes+=d;return this},clamp:function(){var d=this.words,g=this.sigBytes;d[g>>>2]&=4294967295<<32-g%4*8;d.length=e.ceil(g/4)},clone:function(){var d= q.clone.call(this);d.words=this.words.slice(0);return d},random:function(d){for(var g=[],k=0;k>>2]>>>24-k%4*8&255;g.push((q>>>4).toString(16));g.push((q&15).toString(16))}return g.join("")},parse:function(d){for(var e=d.length,g=[],k=0;k>>3]|=parseInt(d.substr(k,2),16)<<24-k%8*4;return new p.init(g,e/2)}},c=a.Latin1= {stringify:function(d){var e=d.words;d=d.sigBytes;for(var g=[],k=0;k>>2]>>>24-k%4*8&255));return g.join("")},parse:function(d){for(var e=d.length,g=[],k=0;k>>2]|=(d.charCodeAt(k)&255)<<24-k%4*8;return new p.init(g,e)}},f=a.Utf8={stringify:function(d){try{return decodeURIComponent(escape(c.stringify(d)))}catch(e){throw Error("Malformed UTF-8 data");}},parse:function(d){return c.parse(unescape(encodeURIComponent(d)))}},h=d.BufferedBlockAlgorithm=q.extend({reset:function(){this._data= new p.init;this._nDataBytes=0},_append:function(d){"string"==typeof d&&(d=f.parse(d));this._data.concat(d);this._nDataBytes+=d.sigBytes},_process:function(d){var g=this._data,k=g.words,q=g.sigBytes,a=this.blockSize,b=q/(4*a),b=d?e.ceil(b):e.max((b|0)-this._minBufferSize,0);d=b*a;q=e.min(4*d,q);if(d){for(var td=0;tda;)d(k)&&(8>a&&(q[a]=g(e.pow(k,0.5))),p[a]=g(e.pow(k,1/3)),a++),k++})();var a=[],k=k.SHA256=d.extend({_doReset:function(){this._hash=new g.init(q.slice(0))},_doProcessBlock:function(d,e){for(var g=this._hash.words,k=g[0],q=g[1],b=g[2],c=g[3],f=g[4], h=g[5],l=g[6],n=g[7],m=0;64>m;m++){if(16>m)a[m]=d[e+m]|0;else{var s=a[m-15],r=a[m-2];a[m]=((s<<25|s>>>7)^(s<<14|s>>>18)^s>>>3)+a[m-7]+((r<<15|r>>>17)^(r<<13|r>>>19)^r>>>10)+a[m-16]}s=n+((f<<26|f>>>6)^(f<<21|f>>>11)^(f<<7|f>>>25))+(f&h^~f&l)+p[m]+a[m];r=((k<<30|k>>>2)^(k<<19|k>>>13)^(k<<10|k>>>22))+(k&q^k&b^q&b);n=l;l=h;h=f;f=c+s|0;c=b;b=q;q=k;k=s+r|0}g[0]=g[0]+k|0;g[1]=g[1]+q|0;g[2]=g[2]+b|0;g[3]=g[3]+c|0;g[4]=g[4]+f|0;g[5]=g[5]+h|0;g[6]=g[6]+l|0;g[7]=g[7]+n|0},_doFinalize:function(){var d=this._data, g=d.words,k=8*this._nDataBytes,q=8*d.sigBytes;g[q>>>5]|=128<<24-q%32;g[(q+64>>>9<<4)+14]=e.floor(k/4294967296);g[(q+64>>>9<<4)+15]=k;d.sigBytes=4*g.length;this._process();return this._hash},clone:function(){var e=d.clone.call(this);e._hash=this._hash.clone();return e}});Ld.SHA256=d._createHelper(k);Ld.HmacSHA256=d._createHmacHelper(k)})(Math);r.CryptoJS=Ld;(function(){var e=Yb,k=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,d){e=this._hasher=new e.init;"string"==typeof d&&(d=k.parse(d)); var q=e.blockSize,p=4*q;d.sigBytes>p&&(d=e.finalize(d));d.clamp();for(var a=this._oKey=d.clone(),b=this._iKey=d.clone(),c=a.words,f=b.words,h=0;h>6)+Wb.charAt(g&63);k+1==e.length?(g=parseInt(e.substring(k,k+1),16),d+=Wb.charAt(g<<2)):k+2==e.length&&(g=parseInt(e.substring(k,k+2),16),d+=Wb.charAt(g>>2)+Wb.charAt((g&3)<<4));if(Gd)for(;0<(d.length&3);)d+=Gd;return d};J.prototype.init=function(e){var k, g,d;for(k=0;256>k;++k)this.S[k]=k;for(k=g=0;256>k;++k)g=g+this.S[k]+e[k%e.length]&255,d=this.S[k],this.S[k]=this.S[g],this.S[g]=d;this.j=this.i=0};J.prototype.next=function(){var e;this.i=this.i+1&255;this.j=this.j+this.S[this.i]&255;e=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=e;return this.S[e+this.S[this.i]&255]};var Hd=256,Ac,Cb,Pa;if(null==Cb){Cb=[];Pa=0;var cd;if("Netscape"==navigator.appName&&"5">navigator.appVersion&&window.crypto){var Nc=window.crypto.random(32);for(cd=0;cd< Nc.length;++cd)Cb[Pa++]=Nc.charCodeAt(cd)&255}for(;Pa>>8,Cb[Pa++]=cd&255;Pa=0;T()}U.prototype.nextBytes=function(e){var k;for(k=0;k>3;if(kq?g[--k]=q:127q?(g[--k]=q&63|128,g[--k]=q>>6|192):(g[--k]=q&63|128,g[--k]=q>>6&63|128,g[--k]=q>>12|224)}g[--k]=0;e=new U;for(d=[];2>3;if(e.length+2*Pb+2>d)throw"Message too long for RSA";var q="";for(g=0;gk.compareTo(e);)k=k.add(this.p);return k.subtract(e).multiply(this.coeff).mod(this.p).multiply(this.q).add(e)}; z.prototype.setPrivate=function(e,k,g){this.isPrivate=!0;"string"!==typeof e?(this.n=e,this.e=k,this.d=g):null!=e&&null!=k&&0>1;this.e=parseInt(k,16);for(var q=new B(k,16);;){for(;this.p=new B(e-d,1,g),0!=this.p.subtract(B.ONE).gcd(q).compareTo(B.ONE)||!this.p.isProbablePrime(10););for(;this.q=new B(d,1,g),0!=this.q.subtract(B.ONE).gcd(q).compareTo(B.ONE)|| !this.q.isProbablePrime(10););if(0>=this.p.compareTo(this.q)){var p=this.p;this.p=this.q;this.q=p}var p=this.p.subtract(B.ONE),a=this.q.subtract(B.ONE),b=p.multiply(a);if(0==b.gcd(q).compareTo(B.ONE)){this.n=this.p.multiply(this.q);this.d=q.modInverse(b);this.dmp1=this.d.mod(p);this.dmq1=this.d.mod(a);this.coeff=this.q.modInverse(this.p);break}}this.isPrivate=!0};z.prototype.decrypt=function(e){e=X(e,16);e=this.doPrivate(e);if(null==e)return null;a:{var k=this.n.bitLength()+7>>3;e=e.toByteArray(); for(var g=0;g=e.length){e=null;break a}for(k="";++gd?k+=String.fromCharCode(d):191d?(k+=String.fromCharCode((d&31)<<6|e[g+1]&63),++g):(k+=String.fromCharCode((d&15)<<12|(e[g+1]&63)<<6|e[g+2]&63),g+=2)}e=k}}return e};z.prototype.decryptOAEP=function(e,k){var g=X(e,16),g=this.doPrivate(g);if(null==g)return null;for(var d=g,q=this.n.bitLength()+7>>3,d=d.toByteArray(),g=0;ge)throw"key is too short for SigAlg: keylen="+g+","+k;k="00"+d;g="";e=e-4-k.length;for(d=0;dg)throw"invalid salt length";if(p>8*p-q&255);for(d=0;d this.n.bitLength())return 0;g=this.doPublic(g).toString(16).replace(/^1f+00/,"");g=de(g);return 0==g.length?!1:g[1]==e};z.prototype.verifyString=Id;z.prototype.verifyHexSignatureForMessage=ud;z.prototype.verify=Id;z.prototype.verifyHexSignatureForByteArrayMessage=ud;z.prototype.verifyWithMessageHashPSS=function(e,k,g,d){var q=new B(k,16);if(q.bitLength()>this.n.bitLength())return!1;k=function(d){return O.crypto.Util.hashHex(d,g)};e=hextorstr(e);var p=e.length,a=this.n.bitLength()-1,b=Math.ceil(a/ 8);if(-1===d||void 0===d)d=p;else if(-2===d)d=b-p-2;else if(-2>d)throw"invalid salt length";if(b>8*b-a&255;if(0!==(f.charCodeAt(0)&h))throw"bits beyond keysize not zero";for(var l=ve(c,f.length,k),a=[],q=0;q=c.compareTo(B.ZERO));k=b.modInverse(p).multiply(a.add(k.multiply(c))).mod(p);return O.crypto.ECDSA.biRSSigToASN1Sig(c,k)};this.sign=function(e,d){var k=this.ecparams.n,p=B.fromByteArrayUnsigned(e);do var a=this.getBigRandom(k),b=this.ecparams.G.multiply(a).getX().toBigInteger().mod(k);while(0>=b.compareTo(B.ZERO));k=a.modInverse(k).multiply(p.add(d.multiply(b))).mod(k);return this.serializeSig(b,k)};this.verifyWithMessageHash=function(e,d){return this.verifyHex(e,d,this.pubKeyHex)};this.verifyHex= function(e,d,k){var p;p=O.crypto.ECDSA.parseSigHex(d);d=p.r;p=p.s;k=ECPointFp.decodeFromHex(this.ecparams.curve,k);e=new B(e,16);return this.verifyRaw(e,d,p,k)};this.verify=function(e,d,k){var p;if(Bitcoin.Util.isArray(d))d=this.parseSig(d),p=d.r,d=d.s;else if("object"===typeof d&&d.r&&d.s)p=d.r,d=d.s;else throw"Invalid value for signature";if(!(k instanceof ECPointFp))if(Bitcoin.Util.isArray(k))k=ECPointFp.decodeFrom(this.ecparams.curve,k);else throw"Invalid format for pubkey value, must be byte array or ECPointFp"; e=B.fromByteArrayUnsigned(e);return this.verifyRaw(e,p,d,k)};this.verifyRaw=function(e,d,k,p){var a=this.ecparams.n,b=this.ecparams.G;if(0>d.compareTo(B.ONE)||0<=d.compareTo(a)||0>k.compareTo(B.ONE)||0<=k.compareTo(a))return!1;k=k.modInverse(a);e=e.multiply(k).mod(a);k=d.multiply(k).mod(a);return b.multiply(e).add(p.multiply(k)).getX().toBigInteger().mod(a).equals(d)};this.serializeSig=function(e,d){var k=e.toByteArraySigned(),p=d.toByteArraySigned(),a=[];a.push(2);a.push(k.length);a=a.concat(k); a.push(2);a.push(p.length);a=a.concat(p);a.unshift(a.length);a.unshift(48);return a};this.parseSig=function(e){var d;if(48!=e[0])throw Error("Signature not a valid DERSequence");d=2;if(2!=e[d])throw Error("First element in signature must be a DERInteger");var k=e.slice(d+2,d+2+e[d+1]);d+=2+e[d+1];if(2!=e[d])throw Error("Second element in signature must be a DERInteger");e=e.slice(d+2,d+2+e[d+1]);k=B.fromByteArrayUnsigned(k);e=B.fromByteArrayUnsigned(e);return{r:k,s:e}};this.parseSigCompact=function(e){if(65!== e.length)throw"Signature has the wrong length";var d=e[0]-27;if(0>d||7g?g+1:-2};this.getHexOfL_AtObj=function(e,k){var g=this.getByteLengthOfL_AtObj(e,k);return 1>g?"":e.substring(k+2,k+2+2*g)};this.getIntOfL_AtObj=function(e,k){var g=this.getHexOfL_AtObj(e,k);return""==g?-1:(8>parseInt(g.substring(0,1))?new B(g,16):new B(g.substring(2),16)).intValue()};this.getStartPosOfV_AtObj=function(e,k){var g=this.getByteLengthOfL_AtObj(e,k);return 0>g?g:k+2*(g+1)};this.getHexOfV_AtObj=function(e,k){var g=this.getStartPosOfV_AtObj(e, k),d=this.getIntOfL_AtObj(e,k);return e.substring(g,g+2*d)};this.getHexOfTLV_AtObj=function(e,k){var g=e.substr(k,2),d=this.getHexOfL_AtObj(e,k),q=this.getHexOfV_AtObj(e,k);return g+d+q};this.getPosOfNextSibling_AtObj=function(e,k){var g=this.getStartPosOfV_AtObj(e,k),d=this.getIntOfL_AtObj(e,k);return g+2*d};this.getPosArrayOfChildren_AtObj=function(e,k){var g=[],d=this.getStartPosOfV_AtObj(e,k);g.push(d);for(var q=this.getIntOfL_AtObj(e,k),p=d,a=0;;){p=this.getPosOfNextSibling_AtObj(e,p);if(null== p||p-d>=2*q)break;if(200<=a)break;g.push(p);a++}return g};this.getNthChildIndex_AtObj=function(e,k,g){return this.getPosArrayOfChildren_AtObj(e,k)[g]};this.getDecendantIndexByNthList=function(e,k,g){if(0==g.length)return k;var d=g.shift();k=this.getPosArrayOfChildren_AtObj(e,k);return this.getDecendantIndexByNthList(e,k[d],g)};this.getDecendantHexTLVByNthList=function(e,k,g){k=this.getDecendantIndexByNthList(e,k,g);return this.getHexOfTLV_AtObj(e,k)};this.getDecendantHexVByNthList=function(e,k,g){k= this.getDecendantIndexByNthList(e,k,g);return this.getHexOfV_AtObj(e,k)}};H.getVbyList=function(e,k,g,d){k=this.getDecendantIndexByNthList(e,k,g);if(void 0===k)throw"can't find nthList object";if(void 0!==d&&e.substr(k,2)!=d)throw"checking tag doesn't match: "+e.substr(k,2)+"!="+d;return this.getHexOfV_AtObj(e,k)};H.hextooidstr=function(e){var k=function(d,e){return d.length>=e?d:Array(e-d.length+1).join("0")+d},g=[],d=e.substr(0,2),d=parseInt(d,16);g[0]=new String(Math.floor(d/40));g[1]=new String(d% 40);var q=e.substr(2);e=[];for(d=0;dk.length?-1:"a003020102"==e.substring(k[0],k[0]+10)?6>k.length?-1:k[6]:5>k.length?-1:k[5]};ga.getPublicKeyHexArrayFromCertHex=function(e){var k=ga.getSubjectPublicKeyPosFromCertHex(e),g=H.getPosArrayOfChildren_AtObj(e,k);if(2!=g.length)return[];k=H.getHexOfV_AtObj(e,g[0]);e=H.getHexOfV_AtObj(e,g[1]);return null!=k&&null!=e?[k,e]:[]};ga.getHexTbsCertificateFromCert=function(e){return H.getStartPosOfV_AtObj(e,0)};ga.getPublicKeyHexArrayFromCertPEM=function(e){e=ga.pemToHex(e);return ga.getPublicKeyHexArrayFromCertHex(e)}; ga.hex2dn=function(e){for(var k="",g=H.getPosArrayOfChildren_AtObj(e,0),d=0;dg.length)throw"malformed X.509 certificate PEM (code:003)"; g=H.getPosArrayOfChildren_AtObj(e,g[6]);if(2!=g.length)throw"malformed X.509 certificate PEM (code:004)";var d=H.getPosArrayOfChildren_AtObj(e,g[0]);if(2!=d.length)throw"malformed X.509 certificate PEM (code:005)";k.algoid=H.getHexOfV_AtObj(e,d[0]);"06"==e.substr(d[1],2)?k.algparam=H.getHexOfV_AtObj(e,d[1]):"30"==e.substr(d[1],2)&&(k.algparam=H.getHexOfTLV_AtObj(e,d[1]));if("03"!=e.substr(g[1],2))throw"malformed X.509 certificate PEM (code:006)";e=H.getHexOfV_AtObj(e,g[1]);k.keyhex=e.substr(2);return k}; ga.getPublicKeyInfoPosOfCertHEX=function(e){var k=H.getPosArrayOfChildren_AtObj(e,0);if(3!=k.length)throw"malformed X.509 certificate PEM (code:001)";if("30"!=e.substr(k[0],2))throw"malformed X.509 certificate PEM (code:002)";e=H.getPosArrayOfChildren_AtObj(e,k[0]);if(7>e.length)throw"malformed X.509 certificate PEM (code:003)";return e[6]};ga.getV3ExtInfoListOfCertHex=function(e){var k=H.getPosArrayOfChildren_AtObj(e,0);if(3!=k.length)throw"malformed X.509 certificate PEM (code:001)";if("30"!=e.substr(k[0], 2))throw"malformed X.509 certificate PEM (code:002)";k=H.getPosArrayOfChildren_AtObj(e,k[0]);if(8>k.length)throw"malformed X.509 certificate PEM (code:003)";if("a3"!=e.substr(k[7],2))throw"malformed X.509 certificate PEM (code:004)";k=H.getPosArrayOfChildren_AtObj(e,k[7]);if(1!=k.length)throw"malformed X.509 certificate PEM (code:005)";if("30"!=e.substr(k[0],2))throw"malformed X.509 certificate PEM (code:006)";for(var k=H.getPosArrayOfChildren_AtObj(e,k[0]),g=k.length,d=Array(g),q=0;q=k.length)throw"malformed key usage value";e=parseInt(k.substr(0,2));k=parseInt(k.substr(2),16).toString(2);return k.substr(0,k.length-e)};ga.getExtKeyUsageString=function(e){e=ga.getExtKeyUsageBin(e);for(var k=[],g=0;g=Zb;++Zb)ye[Oc++]=Zb;Oc=97;for(Zb=10;36>Zb;++Zb)ye[Oc++]=Zb;Oc=65;for(Zb=10;36>Zb;++Zb)ye[Oc++]=Zb;zc.prototype.convert=function(e){return 0>e.s||0<=e.compareTo(this.m)?e.mod(this.m):e};zc.prototype.revert=function(e){return e};zc.prototype.reduce=function(e){e.divRemTo(this.m,null,e)};zc.prototype.mulTo=function(e,k,g){e.multiplyTo(k,g);this.reduce(g)};zc.prototype.sqrTo=function(e,k){e.squareTo(k);this.reduce(k)};Qa.prototype.convert=function(e){var k=ia();e.abs().dlShiftTo(this.m.t, k);k.divRemTo(this.m,null,k);0>e.s&&0>15)*this.mpl&this.um)<<15)&e.DM,g=k+this.m.t;for(e[g]+=this.m.am(0,d,e,k,0,this.m.t);e[g]>=e.DV;)e[g]-=e.DV,e[++g]++}e.clamp();e.drShiftTo(this.m.t,e);0<=e.compareTo(this.m)&&e.subTo(this.m,e)}; Qa.prototype.mulTo=function(e,k,g){e.multiplyTo(k,g);this.reduce(g)};Qa.prototype.sqrTo=function(e,k){e.squareTo(k);this.reduce(k)};B.prototype.copyTo=function(e){for(var k=this.t-1;0<=k;--k)e[k]=this[k];e.t=this.t;e.s=this.s};B.prototype.fromInt=function(e){this.t=1;this.s=0>e?-1:0;0e?this[0]=e+this.DV:this.t=0};B.prototype.fromString=function(e,k){var g;if(16==k)g=4;else if(8==k)g=3;else if(256==k)g=8;else if(2==k)g=1;else if(32==k)g=5;else if(4==k)g=2;else{this.fromRadix(e,k);return}this.s= this.t=0;for(var d=e.length,q=!1,p=0;0<=--d;){var a=8==g?e[d]&255:$c(e,d);0>a?"-"==e.charAt(d)&&(q=!0):(q=!1,0==p?this[this.t++]=a:p+g>this.DB?(this[this.t-1]|=(a&(1<>this.DB-p):this[this.t-1]|=a<=this.DB&&(p-=this.DB))}8==g&&0!=(e[0]&128)&&(this.s=-1,0>d|a,a=(this[b]&q)<=this.t)k.t=0;else{var d=e%this.DB,q=this.DB-d,p=(1<>d;for(var a=g+1;a>d;0>=this.DB;if(e.t>=this.DB;d+=this.s}else{for(d+=this.s;g>=this.DB;d-=e.s}k.s=0>d?-1:0;-1>d?k[g++]=this.DV+d:0=k.DV&&(e[g+k.t]-=k.DV,e[g+k.t+1]=1)}0< e.t&&(e[e.t-1]+=k.am(g,k[g],e,2*g,0,1));e.s=0;e.clamp()};B.prototype.divRemTo=function(e,k,g){var d=e.abs();if(!(0>=d.t)){var q=this.abs();if(q.t>this.F2:0),f=this.FV/c,c=(1<a&&B.ZERO.subTo(g,g)}}}};B.prototype.invDigit=function(){if(1>this.t)return 0;var e=this[0];if(0==(e&1))return 0;var k=e&3,k=k*(2-(e&15)*k)&15,k=k*(2-(e&255)*k)&255,k=k*(2- ((e&65535)*k&65535))&65535,k=k*(2-e*k%this.DV)%this.DV;return 0e)return B.ONE;var g=ia(),d=ia(),q=k.convert(this),p=Jd(e)-1;for(q.copyTo(g);0<=--p;)if(k.sqrTo(g,d),0<(e&1<this.s)return"-"+this.negate().toString(e);if(16==e)e=4;else if(8==e)e=3;else if(2==e)e=1;else if(32== e)e=5;else if(4==e)e=2;else return this.toRadix(e);var k=(1<>a)&&(d=!0,q=Xb.charAt(g));0<=p;)a>(a+=this.DB-e)):(g=this[p]>>(a-=e)&k,0>=a&&(a+=this.DB,--p)),0this.s?this.negate():this};B.prototype.compareTo=function(e){var k= this.s-e.s;if(0!=k)return k;var g=this.t,k=g-e.t;if(0!=k)return 0>this.s?-k:k;for(;0<=--g;)if(0!=(k=this[g]-e[g]))return k;return 0};B.prototype.bitLength=function(){return 0>=this.t?0:this.DB*(this.t-1)+Jd(this[this.t-1]^this.s&this.DM)};B.prototype.mod=function(e){var k=ia();this.abs().divRemTo(e,null,k);0>this.s&&0e||k.isEven()?new zc(k):new Qa(k);return this.exp(e,g)};B.ZERO=Kc(0);B.ONE=Kc(1);bd.prototype.convert= Kd;bd.prototype.revert=Kd;bd.prototype.mulTo=function(e,k,g){e.multiplyTo(k,g)};bd.prototype.sqrTo=function(e,k){e.squareTo(k)};Lc.prototype.convert=function(e){if(0>e.s||e.t>2*this.m.t)return e.mod(this.m);if(0>e.compareTo(this.m))return e;var k=ia();e.copyTo(k);this.reduce(k);return k};Lc.prototype.revert=function(e){return e};Lc.prototype.reduce=function(e){e.drShiftTo(this.m.t-1,this.r2);e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp());this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);for(this.m.multiplyLowerTo(this.q3, this.m.t+1,this.r2);0>e.compareTo(this.r2);)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);0<=e.compareTo(this.m);)e.subTo(this.m,e)};Lc.prototype.mulTo=function(e,k,g){e.multiplyTo(k,g);this.reduce(g)};Lc.prototype.sqrTo=function(e,k){e.squareTo(k);this.reduce(k)};var vb=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311, 313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],gf=67108864/vb[vb.length-1];B.prototype.chunkSize=function(e){return Math.floor(Math.LN2* this.DB/Math.log(e))};B.prototype.toRadix=function(e){null==e&&(e=10);if(0==this.signum()||2>e||36c?"-"==e.charAt(b)&&0==this.signum()&& (q=!0):(a=k*a+c,++p>=g&&(this.dMultiply(d),this.dAddOffset(a,0),a=p=0))}0e)this.fromInt(1);else for(this.fromNumber(e,g),this.testBit(e-1)||this.bitwiseTo(B.ONE.shiftLeft(e-1),Wd,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(k);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(B.ONE.shiftLeft(e-1),this);else{g=[];var d=e&7;g.length= (e>>3)+1;k.nextBytes(g);g[0]=0>=this.DB;if(e.t>=this.DB;d+=this.s}else{for(d+=this.s;g>=this.DB;d+=e.s}k.s=0>d?-1:0;0d&&(k[g++]=this.DV+d);k.t=g;k.clamp()};B.prototype.dMultiply=function(e){this[this.t]=this.am(0,e-1,this,0,0,this.t);++this.t;this.clamp()};B.prototype.dAddOffset=function(e,k){if(0!=e){for(;this.t<=k;)this[this.t++]=0;for(this[k]+=e;this[k]>=this.DV;)this[k]-= this.DV,++k>=this.t&&(this[this.t++]=0),++this[k]}};B.prototype.multiplyLowerTo=function(e,k,g){var d=Math.min(this.t+e.t,k);g.s=0;for(g.t=d;0=e)return 0;var k=this.DV%e,g=0>this.s?e-1:0;if(0=g)return!1;var d=k.shiftRight(g);e=e+1>>1;e>vb.length&&(e=vb.length);for(var q=ia(),p=0;pthis.s){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<>24};B.prototype.shortValue=function(){return 0== this.t?this.s:this[0]<<16>>16};B.prototype.signum=function(){return 0>this.s?-1:0>=this.t||1==this.t&&0>=this[0]?0:1};B.prototype.toByteArray=function(){var e=this.t,k=[];k[0]=this.s;var g=this.DB-e*this.DB%8,d,q=0;if(0>g)!=(this.s&this.DM)>>g&&(k[q++]=d|this.s<g?(d=(this[e]&(1<>(g+=this.DB-8)):(d=this[e]>>(g-=8)&255,0>=g&&(g+=this.DB,--e)),0!=(d&128)&&(d|=-256),0==q&&(this.s&128)!=(d&128)&&++q,0this.compareTo(e)?this:e};B.prototype.max=function(e){return 0e?this.rShiftTo(-e,k):this.lShiftTo(e,k);return k};B.prototype.shiftRight=function(e){var k=ia();0>e?this.lShiftTo(-e,k):this.rShiftTo(e,k);return k};B.prototype.getLowestSetBit=function(){for(var e=0;e>=16,g+=16);0==(e&255)&&(e>>=8,g+=8);0==(e&15)&&(e>>=4,g+= 4);0==(e&3)&&(e>>=2,g+=2);0==(e&1)&&++g;e=g}return k+e}return 0>this.s?this.t*this.DB:-1};B.prototype.bitCount=function(){for(var e=0,k=this.s&this.DM,g=0;g=this.t?0!=this.s:0!=(this[k]&1<=g)return q;d=18>g?1:48>g?3:144>g?4:768>g?5:6;p=8>g?new zc(k):k.isEven()?new Lc(k):new Qa(k);var a=[],b=3,c=d-1,f=(1<=c?l=e[h]>>g-c&f:(l=(e[h]&(1<>this.DB+g-c));for(b=d;0==(l&1);)l>>=1,--b;0>(g-=b)&&(g+=this.DB,--h);if(n)a[l].copyTo(q),n=!1;else{for(;1--g&&(g=this.DB-1,--h)}return p.revert(q)};B.prototype.modInverse=function(e){var k=e.isEven();if(this.isEven()&&k||0==e.signum())return B.ZERO;for(var g=e.clone(),d=this.clone(),q=Kc(1),p=Kc(0),a=Kc(0),b=Kc(1);0!=g.signum();){for(;g.isEven();)g.rShiftTo(1,g),k?(q.isEven()&&p.isEven()||(q.addTo(this,q),p.subTo(e,p)),q.rShiftTo(1,q)):p.isEven()||p.subTo(e,p),p.rShiftTo(1,p);for(;d.isEven();)d.rShiftTo(1, d),k?(a.isEven()&&b.isEven()||(a.addTo(this,a),b.subTo(e,b)),a.rShiftTo(1,a)):b.isEven()||b.subTo(e,b),b.rShiftTo(1,b);0<=g.compareTo(d)?(g.subTo(d,g),k&&q.subTo(a,q),p.subTo(b,p)):(d.subTo(g,d),k&&a.subTo(q,a),b.subTo(p,b))}if(0!=d.compareTo(B.ONE))return B.ZERO;if(0<=b.compareTo(e))return b.subtract(e);if(0>b.signum())b.addTo(e,b);else return b;return 0>b.signum()?b.add(e):b};B.prototype.pow=function(e){return this.exp(e,new bd)};B.prototype.gcd=function(e){var k=0>this.s?this.negate():this.clone(); e=0>e.s?e.negate():e.clone();if(0>k.compareTo(e)){var g=k,k=e;e=g}var g=k.getLowestSetBit(),d=e.getLowestSetBit();if(0>d)return k;g>16),e((a& 65280)>>8),e(a&255);2===b?(a=k(d.charAt(q))<<2|k(d.charAt(q+1))>>4,e(a&255)):1===b&&(a=k(d.charAt(q))<<10|k(d.charAt(q+1))<<4|k(d.charAt(q+2))>>2,e(a>>8&255),e(a&255));return c};e.fromByteArray=function(d){var e,g=d.length%3,k="",q,p;e=0;for(p=d.length-g;e>18&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q>>12&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q>> 6&63)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q&63),k+=q;switch(g){case 1:q=d[d.length-1];k+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q>>2);k+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q<<4&63);k+="==";break;case 2:q=(d[d.length-2]<<8)+d[d.length-1],k+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q>>10),k+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q>> 4&63),k+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q<<2&63),k+="="}return k}})(dd);r.ieee={read:function(e,k,g,d,q){var p;p=8*q-d-1;var a=(1<>1,c=-7;q=g?q-1:0;var f=g?-1:1,h=e[k+q];q+=f;g=h&(1<<-c)-1;h>>=-c;for(c+=p;0>=-c;for(c+=d;0>1,h=23===q?Math.pow(2,-24)-Math.pow(2,-77):0;p=d?0:p-1;var l=d?1:-1,m=0>k||0===k&&0>1/k?1:0;k=Math.abs(k);isNaN(k)||Infinity===k?(k=isNaN(k)?1:0,d=c):(d=Math.floor(Math.log(k)/Math.LN2),1>k*(a=Math.pow(2,-d))&&(d--,a*=2),k=1<=d+f?k+h/a:k+h*Math.pow(2,1-f),2<=k*a&&(d++,a/=2),d+f>=c?(k=0,d=c):1<=d+f?(k=(k*a-1)*Math.pow(2,q),d+=f):(k=k*Math.pow(2,f-1)*Math.pow(2,q),d=0));for(;8<=q;e[g+p]=k&255,p+=l,k/=256,q-=8);d=d<q&&(d= q)):d=q;q=k.length;h.assert(0===q%2,"Invalid hex string");d>q/2&&(d=q/2);for(q=0;qq&&(g=q)):g=q;d=String(d||"utf8").toLowerCase();switch(d){case "hex":e=h.hexWrite(this,e,k,g);break;case "utf8":case "utf-8":e=h.utf8Write(this,e,k,g);break;case "ascii":e=h.asciiWrite(this,e,k,g);break;case "binary":e=h.binaryWrite(this,e,k,g);break;case "base64":e=h.base64Write(this,e,k,g);break; case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":e=h.utf16leWrite(this,e,k,g);break;default:throw Error("Unknown encoding");}return e};h.prototype.toString=function(e,k,g){e=String(e||"utf8").toLowerCase();k=Number(k)||0;g=void 0===g?this.length:Number(g);if(g===k)return"";switch(e){case "hex":e=h.hexSlice(this,k,g);break;case "utf8":case "utf-8":e=h.utf8Slice(this,k,g);break;case "ascii":e=h.asciiSlice(this,k,g);break;case "binary":e=h.binarySlice(this,k,g);break;case "base64":e=h.base64Slice(this, k,g);break;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":e=this.slice(k,g);k="";for(g=0;g=g,"sourceEnd < sourceStart"),h.assert(0<=k&&kthis.length&&(d=this.length),e.length-kd||!h._useTypedArrays)for(var q=0;q=e[k]?(d+=h.decodeUtf8Char(q)+String.fromCharCode(e[k]),q=""):q+="%"+e[k].toString(16);return d+h.decodeUtf8Char(q)};h.asciiSlice=function(e,k,g){var d="";for(g=Math.min(e.length,g);kk)k=0;if(!g||0>g||g>d)g=d;for(d="";k=this.length))return this[e]};h.readUInt16=function(e,k,g,d){d||(h.assert("boolean"===typeof g,"missing or invalid endian"),h.assert(void 0!==k&&null!==k,"missing offset"),h.assert(k+1=d))return g?(g=e[k],k+1=d)){var q;g?(k+2>>0)):(k+1>>0);return q}};h.prototype.readUInt32LE=function(e,k){return h.readUInt32(this,e,!0,k)};h.prototype.readUInt32BE=function(e,k){return h.readUInt32(this,e,!1,k)};h.prototype.readInt8=function(e,k){k||(h.assert(void 0!==e&&null!==e,"missing offset"),h.assert(e=this.length))return this[e]&128?-1*(255-this[e]+1):this[e]};h.readInt16=function(e,k,g,d){d||(h.assert("boolean"===typeof g,"missing or invalid endian"), h.assert(void 0!==k&&null!==k,"missing offset"),h.assert(k+1=e.length))return e=h.readUInt16(e,k,g,!0),e&32768?-1*(65535-e+1):e};h.prototype.readInt16LE=function(e,k){return h.readInt16(this,e,!0,k)};h.prototype.readInt16BE=function(e,k){return h.readInt16(this,e,!1,k)};h.readInt32=function(e,k,g,d){d||(h.assert("boolean"===typeof g,"missing or invalid endian"),h.assert(void 0!==k&&null!==k,"missing offset"),h.assert(k+3=e.length))return e=h.readUInt32(e,k,g,!0),e&2147483648?-1*(4294967295-e+1):e};h.prototype.readInt32LE=function(e,k){return h.readInt32(this,e,!0,k)};h.prototype.readInt32BE=function(e,k){return h.readInt32(this,e,!1,k)};h.readFloat=function(e,k,g,d){d||(h.assert("boolean"===typeof g,"missing or invalid endian"),h.assert(k+3=this.length))return this[k]=e,k+1};h.writeUInt16=function(e,k,g,d,q){q||(h.assert(void 0!==k&&null!==k,"missing value"),h.assert("boolean"===typeof d,"missing or invalid endian"),h.assert(void 0!==g&&null!==g,"missing offset"),h.assert(g+1=a)){q=0;for(a=Math.min(a-g,2);q>>8*(d?q:1- q);return g+2}};h.prototype.writeUInt16LE=function(e,k,g){return h.writeUInt16(this,e,k,!0,g)};h.prototype.writeUInt16BE=function(e,k,g){return h.writeUInt16(this,e,k,!1,g)};h.writeUInt32=function(e,k,g,d,q){q||(h.assert(void 0!==k&&null!==k,"missing value"),h.assert("boolean"===typeof d,"missing or invalid endian"),h.assert(void 0!==g&&null!==g,"missing offset"),h.assert(g+3=a)){q=0;for(a=Math.min(a- g,4);q>>8*(d?q:3-q)&255;return g+4}};h.prototype.writeUInt32LE=function(e,k,g){return h.writeUInt32(this,e,k,!0,g)};h.prototype.writeUInt32BE=function(e,k,g){return h.writeUInt32(this,e,k,!1,g)};h.prototype.writeInt8=function(e,k,g){g||(h.assert(void 0!==e&&null!==e,"missing value"),h.assert(void 0!==k&&null!==k,"missing offset"),h.assert(k=this.length))return 0<=e?this.writeUInt8(e,k,g):this.writeUInt8(255+ e+1,k,g),k+1};h.writeInt16=function(e,k,g,d,q){q||(h.assert(void 0!==k&&null!==k,"missing value"),h.assert("boolean"===typeof d,"missing or invalid endian"),h.assert(void 0!==g&&null!==g,"missing offset"),h.assert(g+1=e.length))return 0<=k?h.writeUInt16(e,k,g,d,q):h.writeUInt16(e,65535+k+1,g,d,q),g+2};h.prototype.writeInt16LE=function(e,k,g){return h.writeInt16(this,e,k,!0,g)};h.prototype.writeInt16BE=function(e, k,g){return h.writeInt16(this,e,k,!1,g)};h.writeInt32=function(e,k,g,d,q){q||(h.assert(void 0!==k&&null!==k,"missing value"),h.assert("boolean"===typeof d,"missing or invalid endian"),h.assert(void 0!==g&&null!==g,"missing offset"),h.assert(g+3=e.length))return 0<=k?h.writeUInt32(e,k,g,d,q):h.writeUInt32(e,4294967295+k+1,g,d,q),g+4};h.prototype.writeInt32LE=function(e,k,g){return h.writeInt32(this,e,k, !0,g)};h.prototype.writeInt32BE=function(e,k,g){return h.writeInt32(this,e,k,!1,g)};h.writeFloat=function(e,k,g,d,q){q||(h.assert(void 0!==k&&null!==k,"missing value"),h.assert("boolean"===typeof d,"missing or invalid endian"),h.assert(void 0!==g&&null!==g,"missing offset"),h.assert(g+3=e.length))return Ma.write(e,k,g,d,23,4),g+4};h.prototype.writeFloatLE=function(e,k,g){return h.writeFloat(this, e,k,!0,g)};h.prototype.writeFloatBE=function(e,k,g){return h.writeFloat(this,e,k,!1,g)};h.writeDouble=function(e,k,g,d,q){q||(h.assert(void 0!==k&&null!==k,"missing value"),h.assert("boolean"===typeof d,"missing or invalid endian"),h.assert(void 0!==g&&null!==g,"missing offset"),h.assert(g+7=e.length))return Ma.write(e,k,g,d,52,8),g+8};h.prototype.writeDoubleLE=function(e,k,g){return h.writeDouble(this, e,k,!0,g)};h.prototype.writeDoubleBE=function(e,k,g){return h.writeDouble(this,e,k,!1,g)};h.prototype.fill=function(e,k,g){e||(e=0);k||(k=0);g||(g=this.length);h.assert(g>=k,"end < start");if(g!==k&&0!==this.length){h.assert(0<=k&&k"};h.prototype.toArrayBuffer=function(){if("undefined"!==typeof Uint8Array){if(h._useTypedArrays)return(new h(this)).buffer;for(var e=new Uint8Array(this.length),k=0,g=e.length;k=k)return k;if(0<=e)return e;e+=k;return 0<=e?e:0};h.coerce=function(e){e=~~Math.ceil(+e);return 0>e?0:e};h.isArray=function(e){return(Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)})(e)};h.isArrayish=function(e){return h.isArray(e)||h.isBuffer(e)|| e&&"object"===typeof e&&"number"===typeof e.length};h.toHex=function(e){return 16>e?"0"+e.toString(16):e.toString(16)};h.utf8ToBytes=function(e){for(var k=[],g=0;g=d)k.push(d);else{var q=g;55296<=d&&57343>=d&&g++;d=encodeURIComponent(e.slice(q,g+1)).substr(1).split("%");for(q=0;q>8,k%=256,d.push(k),d.push(g);return d};h.base64ToBytes=function(e){return dd.toByteArray(e)};h.blitBuffer=function(e,k,g,d){for(var q=0;q=k.length||q>=e.length);q++)k[q+g]=e[q];return q};h.decodeUtf8Char=function(e){try{return decodeURIComponent(e)}catch(k){return String.fromCharCode(65533)}};h.verifuint=function(e,k){h.assert("number"===typeof e,"cannot write a non-number as a number");h.assert(0<=e,"specified a negative value for writing an unsigned value"); h.assert(e<=k,"value is larger than maximum value for type");h.assert(Math.floor(e)===e,"value has a fractional component")};h.verifsint=function(e,k,g){h.assert("number"===typeof e,"cannot write a non-number as a number");h.assert(e<=k,"value larger than maximum allowed value");h.assert(e>=g,"value smaller than minimum allowed value");h.assert(Math.floor(e)===e,"value has a fractional component")};h.verifIEEE754=function(e,k,g){h.assert("number"===typeof e,"cannot write a non-number as a number"); h.assert(e<=k,"value larger than maximum allowed value");h.assert(e>=g,"value smaller than minimum allowed value")};h.assert=function(e,k){if(!e)throw Error(k||"Failed assertion");};var Pc=function(){};r.Log=Pc;Pc.LOG=0;var ed=a.printStackTrace,M={};r.NdnCommon=M;M.MAX_NDN_PACKET_SIZE=8800;M.getErrorWithStackTrace=function(e){return e+"\n"+ed({e:e}).join("\n")};M.checkIndexedDb=function(e){try{var k=new Dexie("test-Dexie-support");k.version(1).stores({});k.open();setTimeout(function(){try{e(k.isOpen())}catch(d){e(!1)}}, 200)}catch(g){e(!1)}};var M=a.NdnCommon,vd=function(e,k,g,d){d=d||{};this.face=e;this.callerOnData=k;this.callerOnTimeout=g;this.maxInterestLifetime=d.maxInterestLifetime||16E3};r.ExponentialReExpress=vd;vd.makeOnTimeout=function(e,k,g,d){var q=new vd(e,k,g,d);return function(d){q.onTimeout(d)}};vd.prototype.onTimeout=function(e){var k=e.getInterestLifetimeMilliseconds();if(null==k){if(this.callerOnTimeout)try{this.callerOnTimeout(e)}catch(g){console.log("Error in onTimeout: "+M.getErrorWithStackTrace(g))}}else if(k*= 2,k>this.maxInterestLifetime){if(this.callerOnTimeout)try{this.callerOnTimeout(e)}catch(d){console.log("Error in onTimeout: "+M.getErrorWithStackTrace(d))}}else{e=e.clone();e.setInterestLifetimeMilliseconds(k);var q=this;this.face.expressInterest(e,this.callerOnData,function(d){q.onTimeout(d)})}};var m=function k(g,d){null==d&&(d=!0);null==g?this.buffer=null:"object"===typeof g&&g instanceof k?this.buffer=g.buffer:"string"===typeof g?this.buffer=new h(g,"utf8"):d?this.buffer=new h(g):h.isBuffer(g)? this.buffer=g:this.buffer=new h(g);this.length=null!=this.buffer?this.buffer.length:0};r.Blob=m;m.prototype.size=function(){return null!=this.buffer?this.buffer.length:0};m.prototype.buf=function(){return this.buffer};m.prototype.isNull=function(){return null==this.buffer};m.prototype.toHex=function(){return null==this.buffer?"":this.buffer.toString("hex")};m.prototype.toString=function(){return null==this.buffer?"":this.buffer.toString("utf8")};m.prototype.equals=function(k){if(this.isNull())return k.isNull(); if(k.isNull())return!1;if(this.buffer!==k.buffer){if(this.buffer.length!=k.buffer.length)return!1;for(var g=0;g=g)){var d=2*this.array.length;g>d&&(d=g);g=new h(d);this.array.copy(g);this.array=g}};fb.prototype.copy=function(g,d){this.ensureLength(g.length+d);h.isBuffer(g)?g.copy(this.array,d):(new h(g)).copy(this.array,d);return d+g.length};fb.prototype.ensureLengthFromBack=function(g){if(!(this.array.length>=g)){var d=2*this.array.length; g>d&&(d=g);g=new h(d);this.array.copy(g,g.length-this.array.length);this.array=g}};fb.prototype.copyFromBack=function(g,d){this.ensureLengthFromBack(d);h.isBuffer(g)?g.copy(this.array,this.array.length-d):(new h(g)).copy(this.array,this.array.length-d)};fb.prototype.slice=function(g,d){return void 0==d?this.array.slice(g):this.array.slice(g,d)};var oa=function(g){this.target=g;this.changeCount=null==g?0:g.getChangeCount()};r.ChangeCounter=oa;oa.prototype.get=function(){return this.target};oa.prototype.set= function(g){this.target=g;this.changeCount=null==g?0:g.getChangeCount()};oa.prototype.checkChanged=function(){if(null==this.target)return!1;var g=this.target.getChangeCount();return this.changeCount!=g?(this.changeCount=g,!0):!1};var M=a.NdnCommon,b=function(g,d){this.value=g;this.isRejected=d};r.SyncPromise=b;b.prototype.then=function(g,d){if(this.isRejected)if(d)try{return d(this.value)}catch(q){return new b(q,!0)}else return this;else if(g)try{return g(this.value)}catch(a){return new b(a,!0)}else return this}; b.prototype.catch=function(g){return this.then(void 0,g)};b.resolve=function(g){return new b(g,!1)};b.reject=function(g){return new b(g,!0)};b.getValue=function(g){if(g instanceof b){if(g.isRejected)throw g.value;return g.value}throw Error("Cannot return immediately because promise is not a SyncPromise");};b.complete=function(g,d,q){var a;q?a=d:(q=d,a=null);if(g)q.then(function(d){try{g(d)}catch(q){console.log("Error in onComplete: "+M.getErrorWithStackTrace(q))}},function(d){if(a)try{a(d)}catch(g){console.log("Error in onError: "+ M.getErrorWithStackTrace(g))}else{if(q instanceof b)throw d;console.log("Uncaught exception from a Promise: "+M.getErrorWithStackTrace(d))}});else return b.getValue(q)};var L={};r.DataUtils=L;L.keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";L.stringtoBase64=function(g){var d="",q,a,b="",c,f,h="",l=0;do q=g.charCodeAt(l++),a=g.charCodeAt(l++),b=g.charCodeAt(l++),c=q>>2,q=(q&3)<<4|a>>4,f=(a&15)<<2|b>>6,h=b&63,isNaN(a)?f=h=64:isNaN(b)&&(h=64),d=d+L.keyStr.charAt(c)+L.keyStr.charAt(q)+ L.keyStr.charAt(f)+L.keyStr.charAt(h);while(l=d.length)return a;for(var b=p,c=!1,f="";;){if("\\"==d[b]){if(f+=d.substring(p,b),b=p=b+1,b>=d.length)break}else if(c)'"'==d[b]&& (f+=d.substring(p,b),p=b+1,c=!1);else if('"'==d[b])f+=d.substring(p,b),p=b+1,c=!0;else if(0<=" \t\n\r".indexOf(d[b]))break;b+=1;if(b>=d.length)break}f+=d.substring(p,b);a.push(f);if(b>=d.length)return a;p=b}};kc.prototype.parseLine=function(d,a){var p=d.indexOf(";");0<=p&&(d=d.substring(0,p).trim());if(0==d.length)return a;for(var p=kc.shlex_split(d),b=!1,c=!1,f=0;fa.getName().size()?r.getName().get(a.getName().size()):this.emptyComponent,G=!1;null===m?G=!0:0==a.getChildSelector()?0>x.compare(l)&&(G=!0):0=this.nextCleanupTime){for(;0d};Ra.PendingInterest=function(d,a){this.interest= d;this.face=a;var p=this.interest.getInterestLifetimeMilliseconds();if(null==p||0>p)p=4E3;this.timeoutMilliseconds=(new Date).getTime()+p};Ra.PendingInterest.prototype.getInterest=function(){return this.interest};Ra.PendingInterest.prototype.getFace=function(){return this.face};Ra.PendingInterest.prototype.isTimedOut=function(d){return d>=this.timeoutTimeMilliseconds};var D=a.Interest,C=a.KeyChain,lc=a.PipelineFixed,Va=a.PipelineCubic,Md=function(){};r.SegmentFetcher=Md;Md.ErrorCode={INTEREST_TIMEOUT:1, DATA_HAS_NO_SEGMENT:2,SEGMENT_VERIFICATION_FAILED:3,INVALID_KEYCHAIN:4,INVALID_PIPELINE:5};Md.DontVerifySegment=function(d){return!0};Md.fetch=function(d,a,p,b,c,f,h){null==f||void 0===f.pipeline||"cubic"===f.pipeline?null==p||p instanceof C?(new Va(a,d,f,p,b,c,h)).run():c(Md.ErrorCode.INVALID_KEYCHAIN,"validatorKeyChain should be either a KeyChain instance or null."):"fixed"===f.pipeline?null==p||p instanceof C?(new lc(a,d,f,p,b,c,h)).run():c(Md.ErrorCode.INVALID_KEYCHAIN,"validatorKeyChain should be either a KeyChain instance or null."): c(Md.ErrorCode.INVALID_PIPELINE,f.pipeline+" is not a valid pipeline type")};var D=a.Interest,M=a.NdnCommon,Y=function(d){this.baseInterest=d;this.numberOfSatisfiedSegments=this.nextSegmentNo=0;this.finalBlockId=Number.MAX_SAFE_INTEGER;this.versionNo=NaN;this.versionIsProvided=!1;0=this.pipeline.failedSegNo)return this.pipeline.onFailure(this.pipeline.failureErrorCode,this.pipeline.failureReason,this.onError);this.pipeline.hasFailure=!1}var l=this.segmentInfo[a];if(void 0!==l){d=Date.now()-l.timeSent;l=Date.now()-l.initTimeSent;1>1,1);0>=n&&this.handleFailure(-1, Y.ErrorCode.MISC,"nExpectedSamples is less than or equal to ZERO.");this.rttEstimator.addMeasurement(a,d,n)}this.rttEstimator.addDelayMeasurement(a,Math.max(d,l));this.pipeline.numberOfSatisfiedSegments++;if(this.pipeline.hasFinalBlockId&&this.pipeline.numberOfSatisfiedSegments>this.pipeline.finalBlockId){a=h.concat(this.pipeline.contentParts);this.cancelInFlightSegmentsGreaterThan(this.pipeline.finalBlockId);this.stats.avgRtt=this.rttEstimator.getAvgRtt().toPrecision(3);this.stats.avgJitter=this.rttEstimator.getAvgJitter().toPrecision(3); this.stats.nSegments=this.pipeline.numberOfSatisfiedSegments;this.stats.completionTime=Date.now()-this.stats.pipelineStartTime;try{this.pipeline.cancel(),this.printSummary(),this.onComplete(new m(a,!1))}catch(s){console.log("Error in onComplete: "+M.getErrorWithStackTrace(s))}}else this.nInFlight=Math.max(this.nInFlight-1,0),this.sendNextInterests()}}};lc.prototype.handleFailure=function(d,a,p){if(!this.pipeline.isStopped)if(-1===d)this.pipeline.onFailure(a,p,this.onError);else{if(0===d||this.pipeline.hasFinalBlockId&& d<=this.pipeline.finalBlockId)return this.pipeline.onFailure(a,p,this.onError);if(!this.pipeline.hasFinalBlockId)if(this.nInFlight--,0>=this.nInFlight)this.pipeline.onFailure(Y.ErrorCode.NO_FINALBLOCK,"Fetching terminated at segment "+d+" but no finalBlockId has been found",this.onError);else this.cancelInFlightSegmentsGreaterThan(d),this.pipeline.hasFailure=!0,this.pipeline.failedSegNo=d,this.pipeline.failureErrorCode=a,this.pipeline.failureReason=p}};lc.prototype.onValidationFailed=function(d,a){Y.reportError(this.onError, Y.ErrorCode.SEGMENT_VERIFICATION_FAILED,"Segment verification failed for "+d.getName().toUri()+" . Reason: "+a)};lc.prototype.printSummary=function(){if(!(2>f)){var d="",d=this.rttEstimator.getMinRtt()===Number.MAX_VALUE||this.rttEstimator.getMaxRtt()===Number.NEGATIVE_INFINITY?"stats unavailable":"min/avg/max = "+this.rttEstimator.getMinRtt().toPrecision(3)+"/"+this.rttEstimator.getAvgRtt().toPrecision(3)+"/"+this.rttEstimator.getMaxRtt().toPrecision(3)+" ms";console.log("Timeouts: "+this.stats.nTimeouts+ " Nacks: "+this.stats.nNacks+"\nRetransmitted segments: "+this.stats.nRetransmitted+"\nRTT "+d+"\nAverage jitter: "+this.rttEstimator.getAvgJitter().toPrecision(3)+" ms\nCompletion time: "+this.stats.completionTime+"ms")}};D=a.Interest;c=a.Name;m=a.Blob;C=a.KeyChain;M=a.NdnCommon;$b=a.RttEstimator;Y=a.Pipeline;f=a.Log.LOG;Va=function(d,a,p,b,c,f,h){this.pipeline=new Y(d);this.face=a;this.validatorKeyChain=b;this.onComplete=c;this.onError=f;this.initCwnd=Y.op("initCwnd",1,p);this.cwnd=Y.op("cwnd", this.initCwnd,p);this.ssthresh=Y.op("ssthresh",Number.MAX_VALUE,p);this.rtoCheckInterval=Y.op("rtoCheckInterval",10,p);this.disableCwa=Y.op("disableCwa",!1,p);this.maxRetriesOnTimeoutOrNack=Y.op("maxRetriesOnTimeoutOrNack",3,p);this.enableFastConv=Y.op("enableFastConv",!1,p);this.cubicBeta=Y.op("cubicBeta",0.7,p);this.wmax=Y.op("wmax",0,p);this.lastWmax=Y.op("lastWmax",0,p);this.lastDecrease=Date.now();this.cubic_c=0.4;this.nSent=this.nRetransmitted=this.nSkippedRetx=this.nNacks=this.nTimeouts=this.nLossDecr= this.nInFlight=this.recPoint=this.highInterest=this.highData=0;this.segmentInfo=[];this.retxQueue=[];this.retxCount=[];this.rttEstimator=new $b(p);this.stats=null!=h?h:{}};r.PipelineCubic=Va;Va.SegmentState={FirstTimeSent:1,InRetxQueue:2,Retransmitted:3};Va.prototype.increaseWindow=function(){if(this.cwndthis.pipeline.finalBlockId||!a&&this.pipeline.hasFailure)){if(a){if(void 0===this.retxCount[d])this.retxCount[d]=1;else if(this.retxCount[d]++,this.retxCount[d]>this.maxRetriesOnTimeoutOrNack)return this.handleFailure(d,Y.ErrorCode.MAX_NACK_TIMEOUT_RETRIES,"Reached the maximum number of retries ("+this.maxRetriesOnTimeoutOrNack+ ") while retrieving segment #"+d);1this.nInFlight)this.handleFailure(-1,Y.ErrorCode.MISC,"Number of in flight Interests is negative.");else for(var d=this.cwnd-this.nInFlight;0=this.pipeline.failedSegNo)return this.pipeline.onFailure(this.pipeline.failureErrorCode,this.pipeline.failureReason,this.onError, this.cancel.bind(this));this.pipeline.hasFailure=!1}var l=this.segmentInfo[a];if(void 0!==l){d=Date.now()-l.timeSent;var n=0;void 0!==l.initTimeSent&&(n=Date.now()-l.initTimeSent);1>1,1),0>=l&&this.handleFailure(-1, Y.ErrorCode.MISC,"nExpectedSamples is less than or equal to ZERO."),this.rttEstimator.addMeasurement(a,d,l));this.rttEstimator.addDelayMeasurement(a,Math.max(d,n));this.segmentInfo[a]=void 0;this.pipeline.numberOfSatisfiedSegments++;if(this.pipeline.hasFinalBlockId&&this.pipeline.numberOfSatisfiedSegments>this.pipeline.finalBlockId){a=h.concat(this.pipeline.contentParts);this.cancelInFlightSegmentsGreaterThan(this.pipeline.finalBlockId);this.stats.nTimeouts=this.nTimeouts;this.stats.nNacks=this.nNacks; this.stats.nRetransmitted=this.nRetransmitted;this.stats.avgRtt=this.rttEstimator.getAvgRtt().toPrecision(3);this.stats.avgJitter=this.rttEstimator.getAvgJitter().toPrecision(3);this.stats.nSegments=this.pipeline.numberOfSatisfiedSegments;this.stats.completionTime=Date.now()-this.stats.pipelineStartTime;try{this.cancel(),this.printSummary(),this.onComplete(new m(a,!1))}catch(s){this.handleFailure(-1,Y.ErrorCode.MISC,"Error in onComplete: "+M.getErrorWithStackTrace(s))}}else this.increaseWindow(), this.schedulePackets()}}};Va.prototype.checkRto=function(){if(!this.pipeline.isStopped){for(var d=!1,a=0;ap.rto&&(this.nTimeouts++,d=!0,this.onWarning(Y.ErrorCode.INTEREST_TIMEOUT,"handle timeout for segment "+a),this.enqueueForRetransmission(a))}d&&(this.recordTimeout(),this.schedulePackets());setTimeout(this.checkRto.bind(this),this.rtoCheckInterval)}}; Va.prototype.enqueueForRetransmission=function(d){0>=this.nInFlight?this.handleFailure(-1,Y.ErrorCode.MISC,"Number of in flight Interests <= 0."):(this.nInFlight--,this.retxQueue.push(d),this.segmentInfo[d].state=Va.SegmentState.InRetxQueue)};Va.prototype.recordTimeout=function(){if(this.disableCwa||this.highData>this.recPoint)this.recPoint=this.highInterest,this.decreaseWindow(),this.rttEstimator.backoffRto(),this.nLossDecr++,1f)){var d="",d=this.rttEstimator.getMinRtt()===Number.MAX_VALUE||this.rttEstimator.getMaxRtt()===Number.NEGATIVE_INFINITY?"stats unavailable":"min/avg/max = "+this.rttEstimator.getMinRtt().toPrecision(3)+"/"+this.rttEstimator.getAvgRtt().toPrecision(3)+"/"+this.rttEstimator.getMaxRtt().toPrecision(3)+" ms";console.log("Timeouts: "+this.nTimeouts+" (caused "+this.nLossDecr+" window decreases)\nNacks: "+this.nNacks+"\nRetransmitted segments: "+this.nRetransmitted+ " ("+(0==this.nSent?0:this.nRetransmitted/this.nSent*100)+"%), skipped: "+this.nSkippedRetx+"\nRTT "+d+"\nAverage jitter: "+this.rttEstimator.getAvgJitter().toPrecision(3)+" ms\nCompletion time: "+this.stats.completionTime+"ms")}};Y=a.Pipeline;$b=function(d){this.alpha=Y.op("alpha",0.125,d);this.beta=Y.op("beta",0.25,d);this.k=Y.op("k",8,d);this.initialRto=Y.op("initialRto",1E3,d);this.minRto=Y.op("minRto",200,d);this.maxRto=Y.op("maxRto",2E4,d);this.rtoBackoffMultiplier=Y.op("rtoBackoffMultiplier", 2,d);this.delayArr=[];this.rttVar=this.sRtt=NaN;this.rto=this.initialRto;this.rttMin=Number.MAX_VALUE;this.rttMax=Number.NEGATIVE_INFINITY;this.nRttSamples=this.rttAvg=0};r.RttEstimator=$b;$b.prototype.clamp=function(d,a,p){if(a=p&&console.log("ERROR: nExpectedSamples is less than or equal to ZERO");0===this.nRttSamples?(this.sRtt=a,this.rttVar=this.sRtt/2):(d=this.alpha/p,p=this.beta/p,this.rttVar=(1- p)*this.rttVar+p*Math.abs(this.sRtt-a),this.sRtt=(1-d)*this.sRtt+d*a);this.rto=this.sRtt+this.k*this.rttVar;this.rto=this.clamp(this.rto,this.minRto,this.maxRto);this.rttAvg=(this.nRttSamples*this.rttAvg+a)/(this.nRttSamples+1);this.rttMax=Math.max(a,this.rttMax);this.rttMin=Math.min(a,this.rttMin);this.nRttSamples++};$b.prototype.addDelayMeasurement=function(d,a){this.delayArr[d]=a};$b.prototype.getAvgJitter=function(){for(var d=0,a=0,p=0,b=0;b=this.matchers_.length)return 0==b;for(var f=this.matchers_[d];0<=c;){if(f.match(a,p,c)&&this.recursiveMatch_(d+1,a,p+c,b-c))return!0;--c}return!1};var $=a.NdnRegexMatcherBase,fd=function(d,a){$.call(this, d,$.NdnRegexExprType.BACKREF,a)};fd.prototype=new $;fd.prototype.name="NdnRegexBackrefMatcher";r.NdnRegexBackrefMatcher=fd;fd.prototype.lateCompile=function(){this.compile_()};fd.prototype.compile_=function(){if(2>this.expr_.length)throw new $.Error(Error("Unrecognized format: "+this.expr_));var d=this.expr_.length-1;if("("===this.expr_[0]&&")"===this.expr_[d])d=new mc(this.expr_.substring(1,d),this.backrefManager_),this.matchers_.push(d);else throw new $.Error(Error("Unrecognized format: "+this.expr_)); };var mc=a.NdnRegexPatternListMatcher,$=a.NdnRegexMatcherBase,gd=a.NdnRegexPseudoMatcher,xd=function(d,a,p){$.call(this,d,$.NdnRegexExprType.COMPONENT,a);void 0===p&&(p=!0);this.componentRegex_=null;this.pseudoMatchers_=[];this.isExactMatch_=p;this.compile_()};xd.prototype=new $;xd.prototype.name="NdnRegexComponentMatcher";r.NdnRegexComponentMatcher=xd;xd.prototype.match=function(d,a,p){this.matchResult_=[];if(""==this.expr_)return this.matchResult_.push(d.get(a)),!0;if(this.isExactMatch_){if(p=d.get(a).toEscapedString().match(this.componentRegex_), null!==p){for(var b=1;bthis.expr_.length)throw new $.Error(Error("Regexp compile error (cannot parse "+this.expr_+")"));if("<"===this.expr_[0])this.compileSingleComponent_();else if("["===this.expr_[0]){var d=this.expr_.length-1;if("]"!==this.expr_[d])throw new $.Error(Error("Regexp compile error (no matching ']' in "+this.expr_+")"));"^"===this.expr_[1]? (this.isInclusion_=!1,this.compileMultipleComponents_(2,d)):this.compileMultipleComponents_(1,d)}else throw new $.Error(Error("Regexp compile error (cannot parse "+this.expr_+")"));};Rc.prototype.extractComponent_=function(d){for(var a=1,p=0;a>p;){if(d>=this.expr_.length)throw new $.Error(Error("Error: angle brackets mismatch"));"<"===this.expr_[d]?a+=1:">"===this.expr_[d]&&(p+=1);d+=1}return d};Rc.prototype.compileSingleComponent_=function(){var d=this.extractComponent_(1);if(this.expr_.length!== d)throw new $.Error(Error("Component expr error "+this.expr_));component=new xd(this.expr_.substring(1,d-1),this.backrefManager_);this.components_.push(component)};Rc.prototype.compileMultipleComponents_=function(d,a){for(var p=d,b=d;p",d),b=this.extractRepetition_(d),this.matchers_.push(new Dc(this.expr_.substring(p,b),this.backrefManager_,c-p));else if("["===this.expr_[d])d+=1,c=d=this.extractSubPattern_("[","]", d),b=this.extractRepetition_(d),this.matchers_.push(new Dc(this.expr_.substring(p,b),this.backrefManager_,c-p));else throw new $.Error(Error("Unexpected syntax"));a[0]=b;return!0};mc.prototype.extractSubPattern_=function(d,a,p){for(var b=1,c=0;b>c;){if(p>=this.expr_.length)throw new $.Error(Error("Parenthesis mismatch"));d==this.expr_[p]&&(b+=1);a==this.expr_[p]&&(c+=1);p+=1}return p};mc.prototype.extractRepetition_=function(d){var a=this.expr_.length;if(d===a)return d;if("+"==this.expr_[d]||"?"== this.expr_[d]||"*"==this.expr_[d])return++d,d;if("{"==this.expr_[d]){for(;"}"!=this.expr_[d]&&(++d,d!==a););if(d===a)throw new $.Error(Error("Missing right brace bracket"));++d}return d};var fd=a.NdnRegexBackrefMatcher,Dc=a.NdnRegexRepeatMatcher,c=a.Name,$=a.NdnRegexMatcherBase,gd=function(){$.call(this,"",$.NdnRegexExprType.PSEUDO)};gd.prototype=new $;gd.prototype.name="NdnRegexPseudoMatcher";r.NdnRegexPseudoMatcher=gd;gd.prototype.compile_=function(){};gd.prototype.setMatchResult=function(d){this.matchResult_.push(new c.Component(d))}; gd.prototype.resetMatchResult=function(){this.matchResult_=[]};$=a.NdnRegexMatcherBase;Dc=function(d,a,b){$.call(this,d,$.NdnRegexExprType.REPEAT_PATTERN,a);this.repeatMax_=this.repeatMin_=0;this.indicator_=b;this.compile_()};Dc.prototype=new $;Dc.prototype.name="NdnRegexRepeatMatcher";r.NdnRegexRepeatMatcher=Dc;Dc.prototype.match=function(d,a,b){this.matchResult_=[];if(0===this.repeatMin_&&0===b)return!0;if(this.recursiveMatch2_(0,d,a,b)){for(var c=a;cc)throw new $.Error(Error("Error: RegexRepeatMatcher.ParseRepetition(): Wrong number "+this.expr_));this.repeatMin_=b;this.repeatMax_=c;return!0}return!1};Dc.prototype.recursiveMatch2_= function(d,a,b,c){var f=c,h=this.matchers_[0];if(0=this.repeatMax_||0===c&&d=this.repeatMin_)return!0;for(;0<=f;){if(h.match(a,b,f)&&this.recursiveMatch2_(d+1,a,b+f,c-f))return!0;--f}return!1};var fd=a.NdnRegexBackrefMatcher,Rc=a.NdnRegexComponentSetMatcher,c=a.Name,$=a.NdnRegexMatcherBase,Qc=a.NdnRegexBackrefManager,mc=a.NdnRegexPatternListMatcher,Za=function(d,a){$.call(this,d,$.NdnRegexExprType.TOP);void 0==a&&(a="");this.secondaryMatcher_=this.primaryMatcher_= null;this.primaryBackrefManager_=new Qc;this.secondaryBackrefManager_=new Qc;this.isSecondaryUsed_=!1;this.expand_=a;this.compile_()};Za.prototype=new $;Za.prototype.name="NdnRegexTopMatcher";r.NdnRegexTopMatcher=Za;Za.prototype.match=function(d,a,b){this.isSecondaryUsed_=!1;this.matchResult_=[];if(this.primaryMatcher_.match(d,0,d.size())){this.matchResult_=[];d=this.primaryMatcher_.getMatchResult();for(a=0;a";a&&(b+="$");return new Za(b)};Za.prototype.compile_=function(){var d=this.expr_,d="$"!=d[d.length-1]?d+"<.*>*": d.substring(0,d.length-1);"^"!=d[0]?this.secondaryMatcher_=new mc("<.*>*"+d,this.secondaryBackrefManager_):d=d.substring(1);this.primaryMatcher_=new mc(d,this.primaryBackrefManager_)};Za.getItemFromExpand_=function(d,a){var b=a[0];if("\\"==d[a[0]]){++a[0];if(a[0]>=d.length)throw new $.Error(Error("Wrong format of expand string!"));for(;a[0]=d[a[0]]&&"0"<=d[a[0]];)if(++a[0],a[0]>d.length)throw new $.Error(Error("Wrong format of expand string!"));if(a[0]>b+1)return d.substring(b,a[0])}else if("<"== d[a[0]]){++a[0];if(a[0]>=d.length)throw new $.Error(Error("Wrong format of expand string!"));for(var c=1,f=0;f"==d[a[0]]&&++f,++a[0],a[0]>=d.length)throw new $.Error(Error("Wrong format of expand string!"));return d.substring(b,a[0])}throw new $.Error(Error("Wrong format of expand string!"));};Za.convertSpecialChar_=function(d){newStr="";for(var a=0;af)throw Error("Name.Component other type code must be non-negative");this.otherTypeCode_=f}else this.otherTypeCode_=-1;this.type_=void 0==b?jb.GENERIC:b}};c.Component.prototype.getValue=function(){return this.value_};c.Component.prototype.getValueAsBuffer=function(){return this.value_.buf()};c.Component.prototype.getType= function(){return this.type_};c.Component.prototype.getOtherTypeCode=function(){return this.otherTypeCode_};Object.defineProperty(c.Component.prototype,"value",{get:function(){return this.getValueAsBuffer()}});c.Component.prototype.toEscapedString=function(){return this.type_===jb.IMPLICIT_SHA256_DIGEST?"sha256digest="+this.value_.toHex():this.type_===jb.PARAMETERS_SHA256_DIGEST?"params-sha256="+this.value_.toHex():(this.type_===jb.GENERIC?"":(this.type_===jb.OTHER_CODE?this.otherTypeCode_:this.type_)+ "=")+c.toEscapedString(this.value_.buf())};c.Component.prototype.isSegment=function(){return 1<=this.value_.size()&&0==this.value_.buf()[0]&&this.isGeneric()};c.Component.prototype.isSegmentOffset=function(){return 1<=this.value_.size()&&251==this.value_.buf()[0]&&this.isGeneric()};c.Component.prototype.isVersion=function(){return 1<=this.value_.size()&&253==this.value_.buf()[0]&&this.isGeneric()};c.Component.prototype.isTimestamp=function(){return 1<=this.value_.size()&&252==this.value_.buf()[0]&& this.isGeneric()};c.Component.prototype.isSequenceNumber=function(){return 1<=this.value_.size()&&254==this.value_.buf()[0]&&this.isGeneric()};c.Component.prototype.isGeneric=function(){return this.type_===jb.GENERIC};c.Component.prototype.isImplicitSha256Digest=function(){return this.type_===jb.IMPLICIT_SHA256_DIGEST};c.Component.prototype.isParametersSha256Digest=function(){return this.type_===jb.PARAMETERS_SHA256_DIGEST};c.Component.prototype.toNumber=function(){return L.bigEndianToUnsignedInt(this.value_.buf())}; c.Component.prototype.toNumberWithMarker=function(a){if(0==this.value_.size()||this.value_.buf()[0]!=a)throw Error("Name component does not begin with the expected marker");return L.bigEndianToUnsignedInt(this.value_.buf().slice(1))};c.Component.prototype.toSegment=function(){return this.toNumberWithMarker(0)};c.Component.prototype.toSegmentOffset=function(){return this.toNumberWithMarker(251)};c.Component.prototype.toVersion=function(){return this.toNumberWithMarker(253)};c.Component.prototype.toTimestamp= function(){return this.toNumberWithMarker(252)};c.Component.prototype.toSequenceNumber=function(){return this.toNumberWithMarker(254)};c.Component.fromNumber=function(a,b,f){var h=new qa(8);h.writeNonNegativeInteger(a);return new c.Component(new m(h.getOutput(),!1),b,f)};c.Component.fromNumberWithMarker=function(a,b){var f=new qa(9);f.writeNonNegativeInteger(a);f.writeNonNegativeInteger(b);return new c.Component(new m(f.getOutput(),!1))};c.Component.fromSegment=function(a){return c.Component.fromNumberWithMarker(a, 0)};c.Component.fromSegmentOffset=function(a){return c.Component.fromNumberWithMarker(a,251)};c.Component.fromVersion=function(a){return c.Component.fromNumberWithMarker(a,253)};c.Component.fromTimestamp=function(a){return c.Component.fromNumberWithMarker(a,252)};c.Component.fromSequenceNumber=function(a){return c.Component.fromNumberWithMarker(a,254)};c.Component.fromImplicitSha256Digest=function(a){digestBlob="object"===typeof a&&a instanceof m?a:new m(a,!0);if(32!==digestBlob.size())throw new S("Name.Component.fromImplicitSha256Digest: The digest length must be 32 bytes"); a=new c.Component(digestBlob);a.type_=jb.IMPLICIT_SHA256_DIGEST;return a};c.Component.fromParametersSha256Digest=function(a){digestBlob="object"===typeof a&&a instanceof m?a:new m(a,!0);if(32!==digestBlob.size())throw new S("Name.Component.fromParametersSha256Digest: The digest length must be 32 bytes");a=new c.Component(digestBlob);a.type_=jb.PARAMETERS_SHA256_DIGEST;return a};c.Component.prototype.getSuccessor=function(){for(var a=new h(this.value_.size()+1),b=!0,f=this.value_.size()-1;0<=f;--f)b? (a[f]=this.value_.buf()[f]+1&255,b=0===a[f]):a[f]=this.value_.buf()[f];b?a[a.length-1]=0:a=a.slice(0,this.value_.size());return new c.Component(new m(a,!1),this.type_,this.otherTypeCode_)};c.Component.prototype.equals=function(a){return"object"===typeof a&&a instanceof c.Component?this.type_===jb.OTHER_CODE?this.value_.equals(a.value_)&&a.type_===jb.OTHER_CODE&&this.otherTypeCode_==a.otherTypeCode_:this.value_.equals(a.value_)&&this.type_===a.type_:!1};c.Component.prototype.compare=function(a){var b= this.type_===jb.OTHER_CODE?this.otherTypeCode_:this.type_,f=a.type_===jb.OTHER_CODE?a.otherTypeCode_:a.type_;return bf?1:c.Component.compareBuffers(this.value_.buf(),a.value_.buf())};c.Component.compareBuffers=function(a,b){if(a.lengthb.length)return 1;for(var c=0;cb[c])return 1}return 0};c.prototype.getName=function(){return this.toUri()};c.createNameArray=function(a){a=a.trim();if(0>=a.length)return[];var b=a.indexOf(":"); if(0<=b){var f=a.indexOf("/");if(0>f||bb)return[];a=a.substr(b+1,a.length-b-1).trim()}else a=a.substr(1,a.length-1).trim();b=a.split("/");for(f=0;fa&&(a=this.components.length- -a);void 0==b&&(b=this.components.length-a);for(var f=new c,l=a+b,h=a;ha?this.getSubName(0,this.components.length+a):this.getSubName(0,a)};c.prototype.cut=function(a){return new c(this.components.slice(0,this.components.length-a))};c.prototype.size=function(){return this.components.length};c.prototype.get=function(a){if(0<=a){if(a>=this.components.length)throw Error("Name.get: Index is out of bounds"); return this.components[a]}if(a<-this.components.length)throw Error("Name.get: Index is out of bounds");return this.components[this.components.length- -a]};c.prototype.getComponentCount=function(){return this.components.length};c.prototype.getComponent=function(a){return new h(this.components[a].getValue().buf())};c.prototype.indexOfFileName=function(){for(var a=this.size()-1;0<=a;--a){var b=this.components[a].getValue().buf();if(!(0>=b.length||0==b[0]||192==b[0]||193==b[0]||245<=b[0]&&255>=b[0]))return a}return-1}; c.prototype.wireEncode=function(a){a=a||s.getDefaultWireFormat();return a.encodeName(this)};c.prototype.wireDecode=function(a,b){b=b||s.getDefaultWireFormat();"object"===typeof a&&a instanceof m?b.decodeName(this,a.buf(),!1):b.decodeName(this,a,!0)};c.prototype.compare=function(a,b,f,l,h){a instanceof c&&(f=a,a=0,b=this.size());void 0==l&&(l=0);void 0==h&&(h=f.size());0>a&&(a=this.size()- -a);0>l&&(l=f.size()- -l);b=Math.min(b,this.size()-a);h=Math.min(h,f.size()-l);for(var m=Math.min(b,h),n=0;n< m;++n){var s=this.components[a+n].compare(f.components[l+n]);if(0!=s)return s}return bh?1:0};c.prototype.equals=function(a){if(this.components.length!=a.components.length)return!1;for(var b=this.components.length-1;0<=b;--b)if(!this.components[b].equals(a.components[b]))return!1;return!0};c.prototype.equalsName=function(a){return this.equals(a)};c.prototype.getContentDigestValue=function(){for(var a=this.size()-1;0<=a;--a){var b=c.getComponentContentDigestValue(this.components[a]);if(null!= b)return b}return null};c.getComponentContentDigestValue=function(a){"object"==typeof a&&a instanceof c.Component&&(a=a.getValue().buf());return a.length==c.ContentDigestPrefix.length+32+c.ContentDigestSuffix.length&&L.arraysEqual(a.slice(0,c.ContentDigestPrefix.length),c.ContentDigestPrefix)&&L.arraysEqual(a.slice(a.length-c.ContentDigestSuffix.length,a.length),c.ContentDigestSuffix)?a.slice(c.ContentDigestPrefix.length,c.ContentDigestPrefix.length+32):null};c.ContentDigestPrefix=new h([193,46,77, 46,71,193,1,170,2,133]);c.ContentDigestSuffix=new h([0]);c.toEscapedString=function(a){"object"==typeof a&&a instanceof c.Component?a=a.getValue().buf():"object"===typeof a&&a instanceof m&&(a=a.buf());for(var b="",f=!1,l=0;l=f||65<=f&&90>=f||97<=f&&122>=f||43==f||45==f||46==f||95==f?b+String.fromCharCode(f):b+("%"+(16>f?"0":"")+f.toString(16).toUpperCase());else for(b="...",l=0;l=a.length?new m:new m(L.toNumbersFromString(a.substr(3,a.length-3)),!1):new m(L.toNumbersFromString(a),!1)};c.fromEscapedStringAsBuffer=function(a){return c.fromEscapedString(a).buf()};c.prototype.getSuccessor=function(){return 0==this.size()?new c("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"):this.getPrefix(-1).append(this.get(-1).getSuccessor())};c.prototype.match=function(a){var b=this.components; a=a.components;if(b.length>a.length)return!1;for(var c=b.length-1;0<=c;--c)if(!b[c].equals(a[c]))return!1;return!0};c.prototype.isPrefixOf=function(a){return this.match(a)};c.prototype.getChangeCount=function(){return this.changeCount};var qa=a.TlvEncoder,s=a.WireFormat,m=a.Blob,oa=a.ChangeCounter,c=a.Name,ta={KEYNAME:1,KEY_LOCATOR_DIGEST:2};r.KeyLocatorType=ta;var V=function td(a,b){"object"===typeof a&&a instanceof td?(this.type_=a.type_,this.keyName_=new oa(new c(a.getKeyName())),this.keyData_= a.keyData_):(this.type_=b,this.keyName_=new oa(new c),this.keyData_=new m,b==ta.KEYNAME?this.keyName_.set("object"===typeof a&&a instanceof c?new c(a):new c):b==ta.KEY_LOCATOR_DIGEST&&(this.keyData_=new m(a)));this.changeCount_=0};r.KeyLocator=V;V.prototype.getType=function(){return this.type_};V.prototype.getKeyName=function(){return this.keyName_.get()};V.prototype.getKeyData=function(){return this.keyData_};V.prototype.getKeyDataAsBuffer=function(){return this.getKeyData().buf()};V.prototype.setType= function(a){this.type_=a;++this.changeCount_};V.prototype.setKeyName=function(a){this.keyName_.set("object"===typeof a&&a instanceof c?new c(a):new c);++this.changeCount_};V.prototype.setKeyData=function(a){this.keyData_="object"===typeof a&&a instanceof m?a:new m(a);++this.changeCount_};V.prototype.clear=function(){this.type_=null;this.keyName_.set(new c);this.keyData_=new m;++this.changeCount_};V.prototype.equals=function(a){if(this.type_!=a.type_)return!1;if(this.type_==ta.KEYNAME){if(!this.getKeyName().equals(a.getKeyName()))return!1}else if(this.type_== ta.KEY_LOCATOR_DIGEST&&!this.getKeyData().equals(a.getKeyData()))return!1;return!0};V.canGetFromSignature=function(a){return a instanceof Ja||a instanceof Xa||a instanceof pb};V.getFromSignature=function(a){if(a instanceof Ja||a instanceof Xa||a instanceof pb)return a.getKeyLocator();throw Error("KeyLocator.getFromSignature: Signature type does not have a KeyLocator");};V.prototype.getChangeCount=function(){this.keyName_.checkChanged()&&++this.changeCount_;return this.changeCount_};Object.defineProperty(V.prototype, "type",{get:function(){return this.getType()},set:function(a){this.setType(a)}});Object.defineProperty(V.prototype,"keyData",{get:function(){return this.getKeyDataAsBuffer()},set:function(a){this.setKeyData(a)}});var Ja=a.Sha256WithRsaSignature,Xa=a.Sha256WithEcdsaSignature,pb=a.HmacWithSha256Signature,c=a.Name,Da={BLOB:0,LINK:1,KEY:2,NACK:3,OTHER_CODE:32767};r.ContentType=Da;var db=function Ye(a,b,c,f,l,h){if(b)throw Error("MetaInfo constructor: timestamp support has been removed.");if(f)throw Error("MetaInfo constructor: locator support has been removed."); if("object"===typeof a&&a instanceof Ye)this.publisher_=a.publisher_,this.type_=a.type_,this.otherTypeCode_=a.otherTypeCode_,this.freshnessPeriod_=a.freshnessPeriod_,this.finalBlockId_=a.finalBlockId_;else{if(a)throw Error("MetaInfo constructor: publisher support has been removed.");this.type=null==c||0>c?Da.BLOB:c;this.otherTypeCode_=-1;this.freshnessSeconds=l;this.setFinalBlockId(h)}this.changeCount_=0};r.MetaInfo=db;db.prototype.getType=function(){return this.type_};db.prototype.getOtherTypeCode= function(){return this.otherTypeCode_};db.prototype.getFreshnessPeriod=function(){return this.freshnessPeriod_};db.prototype.getFinalBlockId=function(){return this.finalBlockId_};db.prototype.getFinalBlockID=function(){return this.getFinalBlockId()};db.prototype.getFinalBlockIDAsBuffer=function(){return this.finalBlockId_.getValue().buf()};db.prototype.setType=function(a){this.type_=null==a||0>a?Da.BLOB:a;++this.changeCount_};db.prototype.setOtherTypeCode=function(a){if(0>a)throw Error("MetaInfo other type code must be non-negative"); this.otherTypeCode_=a;++this.changeCount_};db.prototype.setFreshnessPeriod=function(a){this.freshnessPeriod_=null==a||0>a?null:a;++this.changeCount_};db.prototype.setFinalBlockId=function(a){this.finalBlockId_="object"===typeof a&&a instanceof c.Component?a:new c.Component(a);++this.changeCount_};db.prototype.setFinalBlockID=function(a){this.setFinalBlockId(a)};db.prototype.clear=function(){this.type=Da.BLOB;this.otherTypeCode_=-1;this.freshnessSeconds=null;this.finalBlockId_=new c.Component;++this.changeCount_}; db.prototype.getChangeCount=function(){return this.changeCount_};Object.defineProperty(db.prototype,"type",{get:function(){return this.getType()},set:function(a){this.setType(a)}});Object.defineProperty(db.prototype,"freshnessSeconds",{get:function(){return null==this.freshnessPeriod_||0>this.freshnessPeriod_?null:this.freshnessPeriod_/1E3},set:function(a){this.freshnessPeriod_=null==a||0>a?null:1E3*a;++this.changeCount_}});Object.defineProperty(db.prototype,"finalBlockID",{get:function(){return this.getFinalBlockIDAsBuffer()}, set:function(a){this.setFinalBlockId(a)}});var m=a.Blob,oa=a.ChangeCounter,V=a.KeyLocator,Ea=a.ValidityPeriod,Xa=function Ze(a){"object"===typeof a&&a instanceof Ze?(this.keyLocator_=new oa(new V(a.getKeyLocator())),this.validityPeriod_=new oa(new Ea(a.getValidityPeriod())),this.signature_=a.signature_):(this.keyLocator_=new oa(new V),this.validityPeriod_=new oa(new Ea),this.signature_=new m);this.changeCount_=0};r.Sha256WithEcdsaSignature=Xa;Xa.prototype.clone=function(){return new Xa(this)};Xa.prototype.getKeyLocator= function(){return this.keyLocator_.get()};Xa.prototype.getValidityPeriod=function(){return this.validityPeriod_.get()};Xa.prototype.getSignature=function(){return this.signature_};Xa.prototype.setKeyLocator=function(a){this.keyLocator_.set("object"===typeof a&&a instanceof V?new V(a):new V);++this.changeCount_};Xa.prototype.setValidityPeriod=function(a){this.validityPeriod_.set("object"===typeof a&&a instanceof Ea?new Ea(a):new Ea);++this.changeCount_};Xa.prototype.setSignature=function(a){this.signature_= "object"===typeof a&&a instanceof m?a:new m(a);++this.changeCount_};Xa.prototype.getChangeCount=function(){var a=this.keyLocator_.checkChanged();(a=this.validityPeriod_.checkChanged()||a)&&++this.changeCount_;return this.changeCount_};m=a.Blob;oa=a.ChangeCounter;V=a.KeyLocator;Ea=a.ValidityPeriod;Ja=function $e(a){"object"===typeof a&&a instanceof $e?(this.keyLocator_=new oa(new V(a.getKeyLocator())),this.validityPeriod_=new oa(new Ea(a.getValidityPeriod())),this.signature_=a.signature_):(this.keyLocator_= new oa(new V),this.validityPeriod_=new oa(new Ea),this.signature_=new m);this.changeCount_=0};r.Sha256WithRsaSignature=Ja;Ja.prototype.clone=function(){return new Ja(this)};Ja.prototype.getKeyLocator=function(){return this.keyLocator_.get()};Ja.prototype.getValidityPeriod=function(){return this.validityPeriod_.get()};Ja.prototype.getSignature=function(){return this.signature_};Ja.prototype.getSignatureAsBuffer=function(){return this.signature_.buf()};Ja.prototype.setKeyLocator=function(a){this.keyLocator_.set("object"=== typeof a&&a instanceof V?new V(a):new V);++this.changeCount_};Ja.prototype.setValidityPeriod=function(a){this.validityPeriod_.set("object"===typeof a&&a instanceof Ea?new Ea(a):new Ea);++this.changeCount_};Ja.prototype.setSignature=function(a){this.signature_="object"===typeof a&&a instanceof m?a:new m(a);++this.changeCount_};Ja.prototype.getChangeCount=function(){var a=this.keyLocator_.checkChanged();(a=this.validityPeriod_.checkChanged()||a)&&++this.changeCount_;return this.changeCount_};Object.defineProperty(Ja.prototype, "keyLocator",{get:function(){return this.getKeyLocator()},set:function(a){this.setKeyLocator(a)}});Object.defineProperty(Ja.prototype,"signature",{get:function(){return this.getSignatureAsBuffer()},set:function(a){this.setSignature(a)}});var m=a.Blob,ac=function af(a){"object"===typeof a&&a instanceof af?(this.signature_=a.signature_,this.signatureInfoEncoding_=a.signatureInfoEncoding_,this.typeCode_=a.typeCode_):(this.signature_=new m,this.signatureInfoEncoding_=new m,this.typeCode_=null);this.changeCount_= 0};r.GenericSignature=ac;ac.prototype.clone=function(){return new ac(this)};ac.prototype.getSignature=function(){return this.signature_};ac.prototype.getSignatureAsBuffer=function(){return this.signature_.buf()};ac.prototype.getSignatureInfoEncoding=function(){return this.signatureInfoEncoding_};ac.prototype.getTypeCode=function(){return this.typeCode_};ac.prototype.setSignature=function(a){this.signature_="object"===typeof a&&a instanceof m?a:new m(a);++this.changeCount_};ac.prototype.setSignatureInfoEncoding= function(a,b){this.signatureInfoEncoding_="object"===typeof a&&a instanceof m?a:new m(a);this.typeCode_=b;++this.changeCount_};ac.prototype.getChangeCount=function(){return this.changeCount_};Object.defineProperty(ac.prototype,"signature",{get:function(){return this.getSignatureAsBuffer()},set:function(a){this.setSignature(a)}});m=a.Blob;oa=a.ChangeCounter;V=a.KeyLocator;pb=function ef(a){"object"===typeof a&&a instanceof ef?(this.keyLocator_=new oa(new V(a.getKeyLocator())),this.signature_=a.signature_): (this.keyLocator_=new oa(new V),this.signature_=new m);this.changeCount_=0};r.HmacWithSha256Signature=pb;pb.prototype.clone=function(){return new pb(this)};pb.prototype.getKeyLocator=function(){return this.keyLocator_.get()};pb.prototype.getSignature=function(){return this.signature_};pb.prototype.getSignatureAsBuffer=function(){return this.signature_.buf()};pb.prototype.setKeyLocator=function(a){this.keyLocator_.set("object"===typeof a&&a instanceof V?new V(a):new V);++this.changeCount_};pb.prototype.setSignature= function(a){this.signature_="object"===typeof a&&a instanceof m?a:new m(a);++this.changeCount_};pb.prototype.getChangeCount=function(){this.keyLocator_.checkChanged()&&++this.changeCount_;return this.changeCount_};Object.defineProperty(pb.prototype,"keyLocator",{get:function(){return this.getKeyLocator()},set:function(a){this.setKeyLocator(a)}});Object.defineProperty(pb.prototype,"signature",{get:function(){return this.getSignatureAsBuffer()},set:function(a){this.setSignature(a)}});var m=a.Blob,xb= function bf(a){this.signature_="object"===typeof a&&a instanceof bf?a.signature_:new m;this.changeCount_=0};r.DigestSha256Signature=xb;xb.prototype.clone=function(){return new xb(this)};xb.prototype.getSignature=function(){return this.signature_};xb.prototype.setSignature=function(a){this.signature_="object"===typeof a&&a instanceof m?a:new m(a);++this.changeCount_};xb.prototype.getChangeCount=function(){return this.changeCount_};Object.defineProperty(xb.prototype,"signature",{get:function(){return this.getSignature()}, set:function(a){this.setSignature(a)}});var m=a.Blob,cb=a.SignedBlob,oa=a.ChangeCounter,c=a.Name,Ja=a.Sha256WithRsaSignature,db=a.MetaInfo,Ec=a.IncomingFaceId,hd=a.CongestionMark,s=a.WireFormat,W=a,R=function cf(a,b,f){a instanceof cf?(this.name_=new oa(new c(a.getName())),this.metaInfo_=new oa(new db(a.getMetaInfo())),this.signature_=new oa(a.getSignature().clone()),this.content_=a.content_,this.defaultWireEncoding_=a.getDefaultWireEncoding(),this.defaultFullName_=new c(a.defaultFullName_),this.defaultWireEncodingFormat_= a.defaultWireEncodingFormat_):(this.name_="string"===typeof a?new oa(new c(a)):new oa("object"===typeof a&&a instanceof c?new c(a):new c),"object"===typeof b&&b instanceof db?(a=b,b=f):a=null,this.metaInfo_=new oa("object"===typeof a&&a instanceof db?new db(a):new db),this.content_="object"===typeof b&&b instanceof m?b:new m(b,!0),this.signature_=new oa(new Ja),this.defaultWireEncoding_=new cb,this.defaultFullName_=new c,this.defaultWireEncodingFormat_=null);this.changeCount_=this.getDefaultWireEncodingChangeCount_= 0;this.lpPacket_=null};r.Data=R;R.prototype.getName=function(){return this.name_.get()};R.prototype.getMetaInfo=function(){return this.metaInfo_.get()};R.prototype.getSignature=function(){return this.signature_.get()};R.prototype.getContent=function(){return this.content_};R.prototype.getContentAsBuffer=function(){return this.content_.buf()};R.prototype.getDefaultWireEncoding=function(){this.getDefaultWireEncodingChangeCount_!=this.getChangeCount()&&(this.defaultWireEncoding_=new cb,this.defaultWireEncodingFormat_= null,this.getDefaultWireEncodingChangeCount_=this.getChangeCount());return this.defaultWireEncoding_};R.prototype.getDefaultWireEncodingFormat=function(){return this.defaultWireEncodingFormat_};R.prototype.getIncomingFaceId=function(){var a=null===this.lpPacket_?null:Ec.getFirstHeader(this.lpPacket_);return null===a?null:a.getFaceId()};R.prototype.getCongestionMark=function(){var a=null===this.lpPacket_?null:hd.getFirstHeader(this.lpPacket_);return null===a?0:a.getCongestionMark()};R.prototype.getFullName= function(a){a=a||s.getDefaultWireFormat();if(!this.getDefaultWireEncoding().isNull()&&0f)throw Error("Invalid signing string cannot represent SigningInfo");var A=signingString.substring(0,f),f=signingString.substring(f+1);if("id"==A)f==ze.getDigestSha256Identity().toUri()?this.setSha256Signing():this.setSigningIdentity(new c(f));else if("key"==A)this.setSigningKeyName(new c(f));else if("cert"== A)this.setSigningCertificateName(new c(f));else throw Error("Invalid signing string scheme");}}else throw Error("SigningInfo: Unrecognized type");};r.SigningInfo=Z;Z.SignerType=function(){};Z.SignerType.NULL=0;Z.SignerType.ID=1;Z.SignerType.KEY=2;Z.SignerType.CERT=3;Z.SignerType.SHA256=4;Z.prototype.setSigningIdentity=function(a){this.reset(Z.SignerType.ID);this.name_=new c(a);return this};Z.prototype.setSigningKeyName=function(a){this.reset(Z.SignerType.KEY);this.name_=new c(a);return this};Z.prototype.setSigningCertificateName= function(a){this.reset(Z.SignerType.CERT);this.name_=new c(a);return this};Z.prototype.setSha256Signing=function(){this.reset(Z.SignerType.SHA256);this.digestAlgorithm_=Ga.SHA256;return this};Z.prototype.setPibIdentity=function(a){this.reset(Z.SignerType.ID);null!=a&&(this.name_=a.getName());this.identity_=a;return this};Z.prototype.setPibKey=function(a){this.reset(Z.SignerType.KEY);null!=a&&(this.name_=a.getName());this.key_=a;return this};Z.prototype.getSignerType=function(){return this.type_}; Z.prototype.getSignerName=function(){return this.name_};Z.prototype.getPibIdentity=function(){if(this.type_!=Z.SignerType.ID)throw Error("getPibIdentity: The signer type is not SignerType.ID");return this.identity_};Z.prototype.getPibKey=function(){if(this.type_!=Z.SignerType.KEY)throw Error("getPibKey: The signer type is not SignerType.KEY");return this.key_};Z.prototype.setDigestAlgorithm=function(a){this.digestAlgorithm_=a;return this};Z.prototype.getDigestAlgorithm=function(){return this.digestAlgorithm_}; Z.prototype.setValidityPeriod=function(a){this.validityPeriod_=new Ea(a);return this};Z.prototype.getValidityPeriod=function(){return this.validityPeriod_};Z.prototype.toString=function(){if(this.type_==Z.SignerType.NULL)return"";if(this.type_==Z.SignerType.ID)return"id:"+this.getSignerName().toUri();if(this.type_==Z.SignerType.KEY)return"key:"+this.getSignerName().toUri();if(this.type_==Z.SignerType.CERT)return"cert:"+this.getSignerName().toUri();if(this.type_==Z.SignerType.SHA256)return"id:"+Z.getDigestSha256Identity().toUri(); throw Error("Unknown signer type");};Z.getDigestSha256Identity=function(){return new c("/localhost/identity/digest-sha256")};Z.prototype.reset=function(a){if(a!=Z.SignerType.NULL&&a!=Z.SignerType.ID&&a!=Z.SignerType.KEY&&a!=Z.SignerType.CERT&&a!=Z.SignerType.SHA256)throw Error("SigningInfo: The signerType is not valid");this.type_=a;this.name_=new c;this.key_=this.identity_=null;this.validityPeriod_=new Ea};Ea=function ff(a,b){this.changeCount_=0;"object"===typeof a&&a instanceof ff?(validityPeriod= a,this.notBefore_=validityPeriod.notBefore_,this.notAfter_=validityPeriod.notAfter_):void 0!=b?(notBefore=a,this.setPeriod(notBefore,b)):this.clear()};r.ValidityPeriod=Ea;Ea.prototype.hasPeriod=function(){return!(this.notBefore_===Number.MAX_VALUE&&this.notAfter_===-Number.MAX_VALUE)};Ea.prototype.getNotBefore=function(){return this.notBefore_};Ea.prototype.getNotAfter=function(){return this.notAfter_};Ea.prototype.clear=function(){this.notBefore_=Number.MAX_VALUE;this.notAfter_=-Number.MAX_VALUE; ++this.changeCount_};Ea.prototype.setPeriod=function(a,b){this.notBefore_=Math.round(1E3*Math.ceil(Math.round(a)/1E3));this.notAfter_=Math.round(1E3*Math.floor(Math.round(b)/1E3));++this.changeCount_;return this};Ea.prototype.isValid=function(a){void 0==a&&(a=Math.round(1E3*Math.ceil(Math.round((new Date).getTime())/1E3)));return this.notBefore_<=a&&a<=this.notAfter_};Ea.canGetFromSignature=function(a){return void 0!=a.constructor&&("Sha256WithRsaSignature"===a.constructor.name||"Sha256WithEcdsaSignature"=== a.constructor.name)};Ea.getFromSignature=function(a){if(void 0==a.constructor||"Sha256WithRsaSignature"!==a.constructor.name&&"Sha256WithEcdsaSignature"!==a.constructor.name)throw Error("ValidityPeriod.getFromSignature: Signature type does not have a ValidityPeriod");return a.getValidityPeriod()};Ea.prototype.getChangeCount=function(){return this.changeCount_};var W=a,b=a.SyncPromise,m=a.Blob,s=a.WireFormat,ea=a.KeyType,Ga=a.DigestAlgorithm,Gb=a.UseSubtleCrypto,N=a.CertificateV2,Aa=a.PublicKey,Sa= function(){};r.VerificationHelpers=Sa;Sa.verifySignaturePromise=function(a,c,f,A,v){"boolean"===typeof A&&(v=A,A=void 0);a instanceof m&&(a=a.buf());c instanceof m&&(c=c.buf());if(!(f instanceof Aa))try{f instanceof m||(f=new m(f)),f=new Aa(f)}catch(w){return b.reject(Error("verifySignaturePromise: Error decoding public key DER: "+w))}void 0==A&&(A=Ga.SHA256);if(A==Ga.SHA256)if(f.getKeyType()==ea.RSA){if(Gb()&&!v){var $a={name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};return crypto.subtle.importKey("spki", f.getKeyDer().buf().buffer,$a,!0,["verify"]).then(function(A){return crypto.subtle.verify($a,A,c,a)})}try{null===Sa.verifyUsesString_&&Sa.setVerifyUsesString_();for(var t=f.getKeyDer().buf().toString("base64"),y="-----BEGIN PUBLIC KEY-----\n",l=0;la.getName().size())return null;try{return b.decodeSignatureInfoAndValue(a.getName().get(-2).getValue().buf(), a.getName().get(-1).getValue().buf(),!1)}catch(c){return null}};Sa.verifyUsesString_=null;Sa.setVerifyUsesString_=function(){var a=W.createHash("sha256").digest();Sa.verifyUsesString_="string"===typeof a};var zd=a.constants,W=a,m=a.Blob,l=a.DerNode,x=a.SecurityException,Mc=a.UnrecognizedKeyFormatException,ea=a.KeyType,fa=a.EncryptAlgorithmType,b=a.SyncPromise,Gb=a.UseSubtleCrypto,Ga=a.DigestAlgorithm,Aa=function Te(a){if(a){this.keyDer=a;var A=null;try{var b=l.parse(a.buf(),0).getChildren(),A=l.getSequence(b, 0).getChildren()[0].toVal()}catch(w){throw new Mc(Error("PublicKey.decodeKeyType: Error decoding the public key: "+w.message));}A==Te.RSA_ENCRYPTION_OID?this.keyType=ea.RSA:A==Te.EC_ENCRYPTION_OID&&(this.keyType=ea.EC)}else this.keyDer=new m,this.keyType=null};r.PublicKey=Aa;Aa.prototype.toDer=function(){return l.parse(this.keyDer.buf())};Aa.prototype.getKeyType=function(){return this.keyType};Aa.prototype.getDigest=function(a){void 0==a&&(a=Ga.SHA256);if(a==Ga.SHA256)return a=W.createHash("sha256"), a.update(this.keyDer.buf()),new m(a.digest(),!1);throw new x(Error("Wrong format!"));};Aa.prototype.getKeyDer=function(){return this.keyDer};Aa.prototype.encryptPromise=function(a,c,A){"object"===typeof a&&a instanceof m&&(a=a.buf());if(Gb()&&!A&&c!=fa.RsaPkcs)return c==fa.RsaOaep?this.keyType!=ea.RSA?Promise.reject(Error("The key type must be RSA")):crypto.subtle.importKey("spki",this.keyDer.buf(),{name:"RSA-OAEP",hash:{name:"SHA-1"}},!1,["encrypt"]).then(function(A){return crypto.subtle.encrypt({name:"RSA-OAEP"}, A,a)}).then(function(a){return Promise.resolve(new m(new Uint8Array(a),!1))}):Promise.reject(Error("unsupported padding scheme"));var v=this.keyDer.buf().toString("base64");A="-----BEGIN PUBLIC KEY-----\n";for(var w=0;wthis.getNotAfter()};Ba.prototype.isInValidityPeriod=function(a){return this.getSignature().getValidityPeriod().isValid(a)};Ba.prototype.toDer=function(){var a= new l.DerSequence,b=new l.DerSequence,A=new l.DerGeneralizedTime(this.getNotBefore()),v=new l.DerGeneralizedTime(this.getNotAfter());b.addChild(A);b.addChild(v);a.addChild(b);A=new l.DerSequence;for(b=0;bb)return!1;for(b=0;b=a.size()?!1:!0};Na.prototype.setPublicKeyName=function(){this.publicKeyName=Na.certificateNameToPublicKeyName(this.getName())};var c=a.Name,x=a.SecurityException,b=a.SyncPromise, ba=function(){};r.IdentityStorage=ba;ba.prototype.doesIdentityExistPromise=function(a,A){return b.reject(Error("IdentityStorage.doesIdentityExistPromise is not implemented"))};ba.prototype.doesIdentityExist=function(a){return b.getValue(this.doesIdentityExistPromise(a,!0))};ba.prototype.addIdentityPromise=function(a,A){return b.reject(Error("IdentityStorage.addIdentityPromise is not implemented"))};ba.prototype.addIdentity=function(a){return b.getValue(this.addIdentityPromise(a,!0))};ba.prototype.revokeIdentity= function(){return b.reject(Error("IdentityStorage.revokeIdentity is not implemented"))};ba.prototype.getNewKeyNamePromise=function(a,A,v){for(var w=Math.floor((new Date).getTime()/1E3);w<=ba.lastTimestamp;)w+=1;ba.lastTimestamp=w;w=""+w;A=A?"ksk-"+w:"dsk-"+w;var $a=(new c(a)).append(A);return this.doesKeyExistPromise($a,v).then(function(a){if(a)throw new x(Error("Key name already exists"));return b.resolve($a)})};ba.prototype.getNewKeyName=function(a,A){return b.getValue(this.getNewKeyNamePromise(a, A,!0))};ba.prototype.doesKeyExistPromise=function(a,A){return b.reject(Error("IdentityStorage.doesKeyExistPromise is not implemented"))};ba.prototype.doesKeyExist=function(a){return b.getValue(this.doesKeyExistPromise(a,!0))};ba.prototype.addKeyPromise=function(a,A,v,w){return b.reject(Error("IdentityStorage.addKeyPromise is not implemented"))};ba.prototype.addKey=function(a,A,v){return b.getValue(this.addKeyPromise(a,A,v,!0))};ba.prototype.getKeyPromise=function(a,A){return b.reject(Error("IdentityStorage.getKeyPromise is not implemented"))}; ba.prototype.getKey=function(a){return b.getValue(this.getKeyPromise(a,!0))};ba.prototype.activateKey=function(a){throw Error("IdentityStorage.activateKey is not implemented");};ba.prototype.deactivateKey=function(a){throw Error("IdentityStorage.deactivateKey is not implemented");};ba.prototype.doesCertificateExistPromise=function(a,A){return b.reject(Error("IdentityStorage.doesCertificateExistPromise is not implemented"))};ba.prototype.doesCertificateExist=function(a){return b.getValue(this.doesCertificateExistPromise(a, !0))};ba.prototype.addCertificatePromise=function(a,A){return b.reject(Error("IdentityStorage.addCertificatePromise is not implemented"))};ba.prototype.addCertificate=function(a){return b.getValue(this.addCertificatePromise(a,!0))};ba.prototype.getCertificatePromise=function(a,A){return b.reject(Error("IdentityStorage.getCertificatePromise is not implemented"))};ba.prototype.getCertificate=function(a){return b.getValue(this.getValuePromise(a,!0))};ba.prototype.getTpmLocatorPromise=function(a){return b.reject(Error("IdentityStorage.getTpmLocatorPromise is not implemented"))}; ba.prototype.getTpmLocator=function(){return b.getValue(this.getTpmLocatorPromise(!0))};ba.prototype.getDefaultIdentityPromise=function(a){return b.reject(Error("IdentityStorage.getDefaultIdentityPromise is not implemented"))};ba.prototype.getDefaultIdentity=function(){return b.getValue(this.getDefaultIdentityPromise(!0))};ba.prototype.getDefaultKeyNameForIdentityPromise=function(a,A){return b.reject(Error("IdentityStorage.getDefaultKeyNameForIdentityPromise is not implemented"))};ba.prototype.getDefaultKeyNameForIdentity= function(a){return b.getValue(this.getDefaultKeyNameForIdentityPromise(a,!0))};ba.prototype.getDefaultCertificateNameForIdentityPromise=function(a,b){var v=this;return this.getDefaultKeyNameForIdentityPromise(a).then(function(a){return v.getDefaultCertificateNameForKeyPromise(a)})};ba.prototype.getDefaultCertificateNameForIdentity=function(a){return b.getValue(this.getDefaultCertificateNameForIdentityPromise(a,!0))};ba.prototype.getDefaultCertificateNameForKeyPromise=function(a,A){return b.reject(Error("IdentityStorage.getDefaultCertificateNameForKeyPromise is not implemented"))}; ba.prototype.getDefaultCertificateNameForKey=function(a){return b.getValue(this.getDefaultCertificateNameForKeyPromise(a,!0))};ba.prototype.getAllIdentitiesPromise=function(a,A,v){return b.reject(Error("IdentityStorage.getAllIdentitiesPromise is not implemented"))};ba.prototype.getAllKeyNamesOfIdentityPromise=function(a,A,v,w){return b.reject(Error("IdentityStorage.getAllKeyNamesOfIdentityPromise is not implemented"))};ba.prototype.getAllCertificateNamesOfKeyPromise=function(a,A,v,w){return b.reject(Error("IdentityStorage.getAllCertificateNamesOfKeyPromise is not implemented"))}; ba.prototype.getAllKeyNamesOfIdentity=function(a,A,v){return b.getValue(this.getAllKeyNamesOfIdentityPromise(a,A,v,!0))};ba.prototype.setDefaultIdentityPromise=function(a,A){return b.reject(Error("IdentityStorage.setDefaultIdentityPromise is not implemented"))};ba.prototype.setDefaultIdentity=function(a){return b.getValue(this.setDefaultIdentityPromise(a,!0))};ba.prototype.setDefaultKeyNameForIdentityPromise=function(a,A,v){return b.reject(Error("IdentityStorage.setDefaultKeyNameForIdentityPromise is not implemented"))}; ba.prototype.setDefaultKeyNameForIdentity=function(a,A){return b.getValue(this.setDefaultKeyNameForIdentityPromise(a,A,!0))};ba.prototype.setDefaultCertificateNameForKeyPromise=function(a,A,v){return b.reject(Error("IdentityStorage.setDefaultCertificateNameForKeyPromise is not implemented"))};ba.prototype.setDefaultCertificateNameForKey=function(a,A){return b.getValue(this.setDefaultCertificateNameForKeyPromise(a,A,!0))};ba.prototype.getDefaultCertificatePromise=function(a){var A=this;return this.getDefaultIdentityPromise(a).then(function(b){return A.getDefaultCertificateNameForIdentityPromise(b, a)},function(a){return b.resolve(null)}).then(function(v){return null==v?b.resolve(null):A.getCertificatePromise(v,a)})};ba.prototype.getDefaultCertificate=function(){return b.getValue(this.getDefaultCertificatePromise(!0))};ba.prototype.deleteCertificateInfoPromise=function(a,A){return b.reject(Error("IdentityStorage.deleteCertificateInfoPromise is not implemented"))};ba.prototype.deleteCertificateInfo=function(a){return b.getValue(this.deleteCertificateInfoPromise(a,!0))};ba.prototype.deletePublicKeyInfoPromise= function(a,A){return b.reject(Error("IdentityStorage.deletePublicKeyInfoPromise is not implemented"))};ba.prototype.deletePublicKeyInfo=function(a){return b.getValue(this.deletePublicKeyInfoPromise(a,!0))};ba.prototype.deleteIdentityInfoPromise=function(a,A){return b.reject(Error("IdentityStorage.deleteIdentityInfoPromise is not implemented"))};ba.prototype.deleteIdentityInfo=function(a){return b.getValue(this.deleteIdentityInfoPromise(a,!0))};ba.lastTimestamp=Math.floor((new Date).getTime()/1E3); new ba;var c=a.Name,m=a.Blob,x=a.SecurityException,Na=a.IdentityCertificate,b=a.SyncPromise,ba=a.IdentityStorage,zb=function(){ba.call(this);this.identityStore={};this.defaultIdentity="";this.keyStore={};this.certificateStore={}};zb.prototype=new ba;zb.prototype.name="MemoryIdentityStorage";r.MemoryIdentityStorage=zb;zb.prototype.doesIdentityExistPromise=function(a){return b.resolve(void 0!==this.identityStore[a.toUri()])};zb.prototype.addIdentityPromise=function(a){a=a.toUri();void 0===this.identityStore[a]&& (this.identityStore[a]={defaultKey:null});return b.resolve()};zb.prototype.doesKeyExistPromise=function(a){return b.resolve(void 0!==this.keyStore[a.toUri()])};zb.prototype.addKeyPromise=function(a,A,v){if(0===a.size()||this.doesKeyExist(a))return b.resolve();var w=a.getSubName(0,a.size()-1);this.addIdentity(w);this.keyStore[a.toUri()]={keyType:A,keyDer:new m(v),defaultCertificate:null};return b.resolve()};zb.prototype.getKeyPromise=function(a){if(0===a.size())return b.reject(new x(Error("MemoryIdentityStorage.getKeyPromise: Empty keyName"))); a=a.toUri();a=this.keyStore[a];return void 0===a?b.reject(new x(Error("MemoryIdentityStorage.getKeyPromise: The key does not exist"))):b.resolve(a.keyDer)};zb.prototype.doesCertificateExistPromise=function(a){return b.resolve(void 0!==this.certificateStore[a.toUri()])};zb.prototype.addCertificatePromise=function(a){var A=a.getName(),v=a.getPublicKeyName();this.addKey(v,a.getPublicKeyInfo().getKeyType(),a.getPublicKeyInfo().getKeyDer());if(this.doesCertificateExist(A))return b.resolve();this.certificateStore[A.toUri()]= a.wireEncode();return b.resolve()};zb.prototype.getCertificatePromise=function(a){a=a.toUri();if(void 0===this.certificateStore[a])return b.reject(new x(Error("MemoryIdentityStorage.getCertificatePromise: The certificate does not exist")));var A=new Na;try{A.wireDecode(this.certificateStore[a])}catch(v){return b.reject(new x(Error("MemoryIdentityStorage.getCertificatePromise: The certificate cannot be decoded")))}return b.resolve(A)};ba.prototype.getTpmLocatorPromise=function(a){return b.resolve("tpm-memory:")}; zb.prototype.getDefaultIdentityPromise=function(){return 0===this.defaultIdentity.length?b.reject(new x(Error("MemoryIdentityStorage.getDefaultIdentity: The default identity is not defined"))):b.resolve(new c(this.defaultIdentity))};zb.prototype.getDefaultKeyNameForIdentityPromise=function(a){a=a.toUri();return void 0!==this.identityStore[a]?null!=this.identityStore[a].defaultKey?b.resolve(this.identityStore[a].defaultKey):b.reject(new x(Error("No default key set."))):b.reject(new x(Error("Identity not found.")))}; zb.prototype.getDefaultCertificateNameForKeyPromise=function(a){a=a.toUri();return void 0!==this.keyStore[a]?null!=this.keyStore[a].defaultCertificate?b.resolve(this.keyStore[a].defaultCertificate):b.reject(new x(Error("No default certificate set."))):b.reject(new x(Error("Key not found.")))};zb.prototype.setDefaultIdentityPromise=function(a){a=a.toUri();this.defaultIdentity=void 0!==this.identityStore[a]?a:"";return b.resolve()};zb.prototype.setDefaultKeyNameForIdentityPromise=function(a,A){A=A instanceof c?A:null;var v=a.getPrefix(-1);if(null!=A&&0=v.length?b.resolve():c.privateKeyStorage.deleteKeyPairPromise(v[A]).then(function(){return a(A+1)})}return a(0)})});return b.complete(v, w,f)};ja.prototype.setDefaultIdentityPromise=function(a,b){return this.identityStorage.setDefaultIdentityPromise(a,b)};ja.prototype.setDefaultIdentity=function(a,v,w){return b.complete(v,w,this.identityStorage.setDefaultIdentityPromise(a,!v))};ja.prototype.getDefaultIdentityPromise=function(a){return this.identityStorage.getDefaultIdentityPromise(a)};ja.prototype.getDefaultIdentity=function(a,v){return b.complete(a,v,this.identityStorage.getDefaultIdentityPromise(!a))};ja.prototype.getDefaultCertificatePromise= function(a){return this.identityStorage.getDefaultCertificatePromise(a)};ja.prototype.generateRSAKeyPair=function(a,v,w){return b.getValue(this.generateKeyPairPromise(a,v,new bc(w),!0))};ja.prototype.setDefaultKeyForIdentity=function(a,v,w,f){f="function"===typeof v?w:f;w="function"===typeof v?v:w;v="function"!==typeof v&&v?v:new c;return b.complete(w,f,this.identityStorage.setDefaultKeyNameForIdentityPromise(a,v,!w))};ja.prototype.getDefaultKeyNameForIdentity=function(a,v,w){return b.complete(v, w,this.identityStorage.getDefaultKeyNameForIdentityPromise(a,!v))};ja.prototype.generateRSAKeyPairAsDefaultPromise=function(a,v,w,c){var t,f=this;return this.generateKeyPairPromise(a,v,new bc(w)).then(function(a){t=a;return f.identityStorage.setDefaultKeyNameForIdentityPromise(t)}).then(function(){return b.resolve(t)})};ja.prototype.generateRSAKeyPairAsDefault=function(a,v,w){return b.getValue(this.generateRSAKeyPairAsDefaultPromise(a,v,w,!0))};ja.prototype.getPublicKey=function(a,v,w){return b.complete(v, w,this.identityStorage.getKeyPromise(a,!v).then(function(a){return b.resolve(new Aa(a))}))};ja.prototype.prepareUnsignedIdentityCertificate=function(a,v,w,f,t,y,l,ya,h){v instanceof Aa||(h=ya,ya=l,l=y,y=t,t=f,f=w,w=v,v=null);var m=l,n=ya;l=m instanceof c?m:null;"function"===typeof m?(ya=m,h=n):"function"===typeof n?ya=n:h=ya=null;a=null==v?this.prepareUnsignedIdentityCertificatePromise(a,w,f,t,y,l,!ya):this.prepareUnsignedIdentityCertificatePromise(a,v,w,f,t,y,l,!ya);return b.complete(ya,h,a)};ja.prototype.prepareUnsignedIdentityCertificatePromise= function(a,v,w,f,t,y,l,h){v instanceof Aa||(h=l,l=y,y=t,t=f,f=w,w=v,v=null);var m=l;l=m instanceof c?m:null;return(null==v?this.identityStorage.getKeyPromise(a,"boolean"===typeof m?m:"boolean"===typeof h?h:!1).then(function(a){v=new Aa(a);return b.resolve()}):b.resolve()).then(function(){return b.resolve(ja.prepareUnsignedIdentityCertificateHelper_(a,v,w,f,t,y,l))})};ja.prepareUnsignedIdentityCertificateHelper_=function(a,b,w,f,t,y,l){if(1>a.size())return null;var h=a.get(-1).toEscapedString();if(4> h.length)return null;keyIdPrefix=h.substr(0,4);if("ksk-"!=keyIdPrefix&&"dsk-"!=keyIdPrefix)return null;var h=new Na,m=new c;if(null==l)w.match(a)?m.append(w).append("KEY").append(a.getSubName(w.size())).append("ID-CERT").appendVersion((new Date).getTime()):m.append(a.getPrefix(-1)).append("KEY").append(a.get(-1)).append("ID-CERT").appendVersion((new Date).getTime());else if(l.match(a)&&!l.equals(a))m.append(l).append("KEY").append(a.getSubName(l.size())).append("ID-CERT").appendVersion((new Date).getTime()); else return null;h.setName(m);h.setNotBefore(f);h.setNotAfter(t);h.setPublicKeyInfo(b);if(null==y||0===y.length)h.addSubjectDescription(new kd("2.5.4.41",a.getPrefix(-1).toUri()));else for(a=0;athis.certificateNameUris_.indexOf(c)&&this.certificateNameUris_.push(c);this.certificates_[c]=new N(a);return this.pibImpl_.addCertificatePromise(a,v)};Uc.prototype.removePromise=function(a,v){if(!N.isValidName(a)||!N.extractKeyNameFromCertName(a).equals(this.keyName_))return b.reject(Error("Certificate name `"+a.toUri()+"` is invalid or does not match key name"));var c=a.toUri(),f=this.certificateNameUris_.indexOf(c);0<=f&&this.certificateNameUris_.splice(f,1);delete this.certificates_[c]; return this.pibImpl_.removeCertificatePromise(a,v)};Uc.prototype.getPromise=function(a,v){var c=a.toUri(),f=this.certificates_[c];if(void 0!=f)return b.resolve(new N(f));if(!N.isValidName(a)||!N.extractKeyNameFromCertName(a).equals(this.keyName_))return b.reject(Error("Certificate name `"+a.toUri()+"` is invalid or does not match key name"));var t=this;return this.pibImpl_.getCertificatePromise(a,v).then(function(a){t.certificates_[c]=a;return b.resolve(new N(a))})};var c=a.Name,Rb=a.PibIdentity, qc=a.PibIdentityImpl,b=a.SyncPromise,Hc=function(a,b){this.identities_={};this.pibImpl_=a;if(null==a)throw Error("The pibImpl is null");this.identityNameUris_=[];for(var c in b)this.identityNameUris_.push(b[c].toUri())};r.PibIdentityContainer=Hc;Hc.makePromise=function(a,c){return null==a?b.reject(Error("The pibImpl is null")):a.getIdentitiesPromise(c).then(function(c){return b.resolve(new Hc(a,c))})};Hc.prototype.size=function(){return this.identityNameUris_.length};Hc.prototype.addPromise=function(a, b){var c=a.toUri();if(0>this.identityNameUris_.indexOf(c)){var f=this;this.identityNameUris_.push(c);return qc.makePromise(a,this.pibImpl_,!0,b).then(function(t){f.identities_[c]=t;return f.getPromise(a,b)})}return this.getPromise(a,b)};Hc.prototype.removePromise=function(a,b){var c=a.toUri(),f=this.identityNameUris_.indexOf(c);0<=f&&this.identityNameUris_.splice(f,1);delete this.identities_[c];return this.pibImpl_.removeIdentityPromise(a,b)};Hc.prototype.getPromise=function(a,c){var w=a.toUri(), f=this.identities_[w];if(void 0==f){var t=this;return qc.makePromise(a,this.pibImpl_,!1,c).then(function(a){t.identities_[w]=a;return b.resolve(new Rb(a))})}return b.resolve(new Rb(f))};Hc.prototype.resetPromise=function(a){var c=this;this.identities_={};return this.pibImpl_.getIdentitiesPromise(a).then(function(a){c.identityNameUris_=[];for(var A in a)c.identityNameUris_.push(a[A].toUri());return b.resolve()})};b=a.SyncPromise;Rb=function(a){this.impl_=a};r.PibIdentity=Rb;Rb.prototype.getName=function(){return this.lock_().getName()}; Rb.prototype.getKeyPromise=function(a,c){try{return this.lock_().getKeyPromise(a,c)}catch(w){return b.reject(w)}};Rb.prototype.getKey=function(a,c,w){return b.complete(c,w,this.getKeyPromise(a,!c))};Rb.prototype.getDefaultKeyPromise=function(a){try{return this.lock_().getDefaultKeyPromise(a)}catch(c){return b.reject(c)}};Rb.prototype.getDefaultKey=function(a,c){return b.complete(a,c,this.getDefaultKeyPromise(!a))};Rb.prototype.addKeyPromise_=function(a,c,w){try{return this.lock_().addKeyPromise(a, c,w)}catch(f){return b.reject(f)}};Rb.prototype.removeKeyPromise_=function(a,c){try{return this.lock_().removeKeyPromise(a,c)}catch(w){return b.reject(w)}};Rb.prototype.setDefaultKeyPromise_=function(a,c,w){try{return this.lock_().setDefaultKeyPromise(a,c,w)}catch(f){return b.reject(f)}};Rb.prototype.getKeys_=function(){return this.lock_().keys_};Rb.prototype.lock_=function(){if(null==this.impl_)throw Error("Invalid key instance");return this.impl_};var b=a.SyncPromise,ca=function(){};r.PibImpl=ca; ca.Error=function(a){if(a)return a.__proto__=ca.Error.prototype,a};ca.Error.prototype=Error();ca.Error.prototype.name="PibImplError";ca.prototype.setTpmLocatorPromise=function(a,c){return b.reject(Error("PibImpl.setTpmLocatorPromise is not implemented"))};ca.prototype.getTpmLocatorPromise=function(a){return b.reject(Error("PibImpl.getTpmLocatorPromise is not implemented"))};ca.prototype.hasIdentityPromise=function(a,c){return b.reject(Error("PibImpl.hasIdentityPromise is not implemented"))};ca.prototype.addIdentityPromise= function(a,c){return b.reject(Error("PibImpl.addIdentityPromise is not implemented"))};ca.prototype.removeIdentityPromise=function(a,c){return b.reject(Error("PibImpl.removeIdentityPromise is not implemented"))};ca.prototype.clearIdentitiesPromise=function(a){return b.reject(Error("PibImpl.clearIdentitiesPromise is not implemented"))};ca.prototype.getIdentitiesPromise=function(a){return b.reject(Error("PibImpl.getIdentitiesPromise is not implemented"))};ca.prototype.setDefaultIdentityPromise=function(a, c){return b.reject(Error("PibImpl.setDefaultIdentityPromise is not implemented"))};ca.prototype.getDefaultIdentityPromise=function(a){return b.reject(Error("PibImpl.getDefaultIdentityPromise is not implemented"))};ca.prototype.hasKeyPromise=function(a,c){return b.reject(Error("PibImpl.hasKeyPromise is not implemented"))};ca.prototype.addKeyPromise=function(a,c,w,f){return b.reject(Error("PibImpl.addKeyPromise is not implemented"))};ca.prototype.removeKeyPromise=function(a,c){return b.reject(Error("PibImpl.removeKeyPromise is not implemented"))}; ca.prototype.getKeyBitsPromise=function(a,c){return b.reject(Error("PibImpl.getKeyBitsPromise is not implemented"))};ca.prototype.getKeysOfIdentityPromise=function(a,c){return b.reject(Error("PibImpl.getKeysOfIdentityPromise is not implemented"))};ca.prototype.setDefaultKeyOfIdentityPromise=function(a,c,w){return b.reject(Error("PibImpl.setDefaultKeyOfIdentityPromise is not implemented"))};ca.prototype.getDefaultKeyOfIdentityPromise=function(a,c){return b.reject(Error("PibImpl.getDefaultKeyOfIdentityPromise is not implemented"))}; ca.prototype.hasCertificatePromise=function(a,c){return b.reject(Error("PibImpl.hasCertificatePromise is not implemented"))};ca.prototype.addCertificatePromise=function(a,c){return b.reject(Error("PibImpl.addCertificatePromise is not implemented"))};ca.prototype.removeCertificatePromise=function(a,c){return b.reject(Error("PibImpl.removeCertificatePromise is not implemented"))};ca.prototype.getCertificatePromise=function(a,c){return b.reject(Error("PibImpl.getCertificatePromise is not implemented"))}; ca.prototype.getCertificatesOfKeyPromise=function(a,c){return b.reject(Error("PibImpl.getCertificatesOfKeyPromise is not implemented"))};ca.prototype.setDefaultCertificateOfKeyPromise=function(a,c,w){return b.reject(Error("PibImpl.setDefaultCertificateOfKeyPromise is not implemented"))};ca.prototype.getDefaultCertificateOfKeyPromise=function(a,c){return b.reject(Error("PibImpl.getDefaultCertificateOfKeyPromise is not implemented"))};var ab=function(){ca.call(this);this.database=new Dexie("pib");this.database.version(1).stores({globals:"key", identities:"identityNameUri",keys:"keyNameUri",certificates:"certificateNameUri"});this.database.open()};ab.prototype=new ca;ab.prototype.name="PibIndexedDb";r.PibIndexedDb=ab;ab.getScheme=function(){return"pib-indexeddb"};ab.prototype.setTpmLocatorPromise=function(a,b){return b?Promise.reject(new ca.Error(Error("PibIndexedDb.setTpmLocatorPromise is only supported for async"))):this.database.globals.put({key:"tpmLocator",value:a})};ab.prototype.getTpmLocatorPromise=function(a){return a?Promise.reject(new ca.Error(Error("PibIndexedDb.getTpmLocatorPromise is only supported for async"))): this.database.globals.get("tpmLocator").then(function(a){return a?Promise.resolve(a.value):Promise.resolve("")})};ab.prototype.hasIdentityPromise=function(a,b){return b?Promise.reject(new ca.Error(Error("PibIndexedDb.hasIdentityPromise is only supported for async"))):this.database.identities.where("identityNameUri").equals(a.toUri()).count().then(function(a){return Promise.resolve(0this.keyNameUris_.indexOf(f)&&this.keyNameUris_.push(f);var t=this;return Tb.makePromise(c,a,this.pibImpl_,w).then(function(a){t.keys_[f]=a;return t.getPromise(c,w)})};Vc.prototype.removePromise=function(a,c){if(!this.identityName_.equals(pa.extractIdentityFromKeyName(a)))return b.reject(Error("Key name `"+ a.toUri()+"` does not match identity `"+this.identityName_.toUri()+"`"));var w=a.toUri(),f=this.keyNameUris_.indexOf(w);0<=f&&this.keyNameUris_.splice(f,1);delete this.keys_[w];return this.pibImpl_.removeKeyPromise(a,c)};Vc.prototype.getPromise=function(a,c){if(!this.identityName_.equals(pa.extractIdentityFromKeyName(a)))return b.reject(Error("Key name `"+a.toUri()+"` does not match identity `"+this.identityName_.toUri()+"`"));var w=a.toUri(),f=this.keys_[w];if(void 0==f){var t=this;return Tb.makePromise(a, this.pibImpl_,c).then(function(a){t.keys_[w]=a;return b.resolve(new pa(a))})}return b.resolve(new pa(f))};Vc.prototype.getKeyNames=function(){var a=[],b;for(b in this.keys_)a.push(new c(b));return a};c=a.Name;N=a.CertificateV2;b=a.SyncPromise;pa=function(a){this.impl_=a};r.PibKey=pa;pa.prototype.getName=function(){return this.lock_().getName()};pa.prototype.getIdentityName=function(){return this.lock_().getIdentityName()};pa.prototype.getKeyType=function(){return this.lock_().getKeyType()};pa.prototype.getPublicKey= function(){return this.lock_().getPublicKey()};pa.prototype.getCertificatePromise=function(a,c){try{return this.lock_().getCertificatePromise(a,c)}catch(w){return b.reject(w)}};pa.prototype.getCertificate=function(a,c,w){return b.complete(c,w,this.getCertificatePromise(a,!c))};pa.prototype.getDefaultCertificatePromise=function(a){try{return this.lock_().getDefaultCertificatePromise(a)}catch(c){return b.reject(c)}};pa.prototype.getDefaultCertificate=function(a,c){return b.complete(a,c,this.getDefaultCertificatePromise(!a))}; pa.constructKeyName=function(a,b){var w=new c(a);w.append(N.KEY_COMPONENT).append(b);return w};pa.isValidKeyName=function(a){return a.size()>N.MIN_KEY_NAME_LENGTH&&a.get(-N.MIN_KEY_NAME_LENGTH).equals(N.KEY_COMPONENT)};pa.extractIdentityFromKeyName=function(a){if(!pa.isValidKeyName(a))throw Error("Key name `"+a.toUri()+"` does not follow the naming conventions");return a.getPrefix(-N.MIN_KEY_NAME_LENGTH)};pa.prototype.addCertificatePromise_=function(a,b){return this.lock_().addCertificatePromise(a, b)};pa.prototype.removeCertificatePromise_=function(a,b){return this.lock_().removeCertificatePromise(a,b)};pa.prototype.setDefaultCertificatePromise_=function(a,b){return this.lock_().setDefaultCertificatePromise(a,b)};pa.prototype.getCertificates_=function(){return this.lock_().certificates_};pa.prototype.lock_=function(){if(null==this.impl_)throw Error("Invalid key instance");return this.impl_};var c=a.Name,m=a.Blob,N=a.CertificateV2,ka=a.Pib,pa=a.PibKey,b=a.SyncPromise,ca=a.PibImpl,wa=function(){ca.call(this); this.tpmLocator_="";this.defaultIdentityName_=null;this.identityNames_=[];this.defaultKeyNames_={};this.keys_={};this.defaultCertificateNames_={};this.certificates_={}};wa.prototype=new ca;wa.prototype.name="PibMemory";r.PibMemory=wa;wa.getScheme=function(){return"pib-memory"};wa.prototype.setTpmLocatorPromise=function(a){this.tpmLocator_=a;return b.resolve()};wa.prototype.getTpmLocatorPromise=function(){return b.resolve(this.tpmLocator_)};wa.prototype.hasIdentityPromise=function(a){return b.resolve(this.hasIdentity_(a))}; wa.prototype.hasIdentity_=function(a){for(var b in this.identityNames_)if(this.identityNames_[b].equals(a))return!0;return!1};wa.prototype.addIdentityPromise=function(a){this.addIdentity_(a);return b.resolve()};wa.prototype.addIdentity_=function(a){a=new c(a);this.hasIdentity_(a)||this.identityNames_.push(a);null===this.defaultIdentityName_&&(this.defaultIdentityName_=a)};wa.prototype.removeIdentityPromise=function(a){for(var c=this.identityNames_.length-1;0<=c;--c)this.identityNames_[c].equals(a)&& this.identityNames_.splice(c,1);null!==this.defaultIdentityName_&&a.equals(this.defaultIdentityName_)&&(this.defaultIdentityName_=null);a=this.getKeysOfIdentity_(a);for(c in a)this.removeKey_(a[c]);return b.resolve()};wa.prototype.clearIdentitiesPromise=function(){this.defaultIdentityName_=null;this.identityNames_=[];this.defaultKeyNames_={};this.keys_={};this.defaultCertificateNames_={};this.certificates_={};return b.resolve()};wa.prototype.getIdentitiesPromise=function(){var a=[],v;for(v in this.identityNames_)a.push(new c(this.identityNames_[v])); return b.resolve(a)};wa.prototype.setDefaultIdentityPromise=function(a){this.addIdentity_(a);this.defaultIdentityName_=new c(a);return b.resolve()};wa.prototype.getDefaultIdentityPromise=function(){return null!==this.defaultIdentityName_?b.resolve(new c(this.defaultIdentityName_)):b.reject(new ka.Error(Error("No default identity")))};wa.prototype.hasKeyPromise=function(a){return b.resolve(this.hasKey_(a))};wa.prototype.hasKey_=function(a){return a.toUri()in this.keys_};wa.prototype.addKeyPromise= function(a,c,w){this.addKey_(a,c,w);return b.resolve()};wa.prototype.addKey_=function(a,b,w){this.addIdentity_(a);b=new c(b);this.keys_[b.toUri()]=new m(w,!0);a=a.toUri();a in this.defaultKeyNames_||(this.defaultKeyNames_[a]=b)};wa.prototype.removeKeyPromise=function(a){this.removeKey_(a);return b.resolve()};wa.prototype.removeKey_=function(a){var b=pa.extractIdentityFromKeyName(a);delete this.keys_[a.toUri()];delete this.defaultKeyNames_[b.toUri()];a=this.getCertificatesOfKey_(a);for(var c in a)this.removeCertificate_(a[c])}; wa.prototype.getKeyBitsPromise=function(a){if(!this.hasKey_(a))return b.reject(new ka.Error(Error("Key `"+a.toUri()+"` not found")));a=this.keys_[a.toUri()];return b.resolve(a)};wa.prototype.getKeysOfIdentityPromise=function(a){return b.resolve(this.getKeysOfIdentity_(a))};wa.prototype.getKeysOfIdentity_=function(a){var b=[],w;for(w in this.keys_){var f=new c(w);a.equals(pa.extractIdentityFromKeyName(f))&&b.push(f)}return b};wa.prototype.setDefaultKeyOfIdentityPromise=function(a,v){if(!this.hasKey_(v))return b.reject(new ka.Error(Error("Key `"+ v.toUri()+"` not found")));this.defaultKeyNames_[a.toUri()]=new c(v);return b.resolve()};wa.prototype.getDefaultKeyOfIdentityPromise=function(a){var v=this.defaultKeyNames_[a.toUri()];return void 0==v?b.reject(new ka.Error(Error("No default key for identity `"+a.toUri()+"`"))):b.resolve(new c(v))};wa.prototype.hasCertificatePromise=function(a){return b.resolve(this.hasCertificate_(a))};wa.prototype.hasCertificate_=function(a){return a.toUri()in this.certificates_};wa.prototype.addCertificatePromise= function(a){var v=new c(a.getName()),w=a.getKeyName(),f=a.getIdentity();this.addKey_(f,w,a.getContent().buf());this.certificates_[v.toUri()]=new N(a);a=w.toUri();a in this.defaultCertificateNames_||(this.defaultCertificateNames_[a]=v);return b.resolve()};wa.prototype.removeCertificatePromise=function(a){this.removeCertificate_(a);return b.resolve()};wa.prototype.removeCertificate_=function(a){delete this.certificates_[a.toUri()];var b=N.extractKeyNameFromCertName(a).toUri(),c=this.defaultCertificateNames_[b]; void 0!=c&&c.equals(a)&&delete this.defaultCertificateNames_[b]};wa.prototype.getCertificatePromise=function(a){return this.hasCertificate_(a)?b.resolve(new N(this.certificates_[a.toUri()])):b.reject(new ka.Error(Error("Certificate `"+a.toUri()+"` does not exist")))};wa.prototype.getCertificatesOfKeyPromise=function(a){return b.resolve(this.getCertificatesOfKey_(a))};wa.prototype.getCertificatesOfKey_=function(a){var b=[],w;for(w in this.certificates_)N.extractKeyNameFromCertName(this.certificates_[w].getName()).equals(a)&& b.push(new c(w));return b};wa.prototype.setDefaultCertificateOfKeyPromise=function(a,v){if(!this.hasCertificate_(v))return b.reject(new ka.Error(Error("Certificate `"+v.toUri()+"` does not exist")));this.defaultCertificateNames_[a.toUri()]=new c(v);return b.resolve()};wa.prototype.getDefaultCertificateOfKeyPromise=function(a){var c=this.defaultCertificateNames_[a.toUri()];if(void 0==c)return b.reject(new ka.Error(Error("No default certificate for key `"+a.toUri()+"`")));a=this.certificates_[c.toUri()]; return b.resolve(new N(a))};Bd=a.ConfigFile;b=a.SyncPromise;ka=function(a,b,c){this.defaultIdentity_=null;this.scheme_=a;this.location_=b;this.identities_=null;this.pibImpl_=c;this.initializeTpmLocator_=this.initializePibLocator_=this.initializeTpm_=null;this.isInitialized_=this.initializeAllowReset_=!1;if(null==c)throw Error("The pibImpl is null");};r.Pib=ka;ka.Error=function(a){if(a)return a.__proto__=ka.Error.prototype,a};ka.Error.prototype=Error();ka.Error.prototype.name="PibError";ka.prototype.getScheme= function(){return this.scheme_};ka.prototype.getPibLocator=function(){return this.scheme_+":"+this.location_};ka.prototype.setTpmLocatorPromise=function(a,b){var c=this;return this.initializePromise_(b).then(function(){return c.doSetTpmLocatorPromise_(a,b)})};ka.prototype.doSetTpmLocatorPromise_=function(a,c){var w=this;return this.pibImpl_.getTpmLocatorPromise(c).then(function(f){return a==f?b.resolve():w.resetPromise_(c).then(function(){return w.pibImpl_.setTpmLocatorPromise(a,c)})})};ka.prototype.getTpmLocatorPromise= function(a){var c=this;return this.initializePromise_(a).then(function(){return c.pibImpl_.getTpmLocatorPromise(a)}).then(function(a){return""==a?b.reject(new ka.Error(Error("TPM info does not exist"))):b.resolve(a)})};ka.prototype.getIdentityPromise=function(a,b){var c=this;return this.initializePromise_(b).then(function(){return c.identities_.getPromise(a,b)})};ka.prototype.getIdentity=function(a,c,w){return b.complete(c,w,this.getIdentityPromise(a,!c))};ka.prototype.getDefaultIdentityPromise=function(a){if(null== this.defaultIdentity_){var c=this;return this.initializePromise_(a).then(function(){return c.pibImpl_.getDefaultIdentityPromise(a)}).then(function(b){return c.identities_.getPromise(b,a)}).then(function(a){c.defaultIdentity_=a;return b.resolve(c.defaultIdentity_)})}return b.resolve(this.defaultIdentity_)};ka.prototype.getDefaultIdentity=function(a,c){return b.complete(a,c,this.getDefaultIdentityPromise(!a))};ka.prototype.resetPromise_=function(a){var b=this;return this.pibImpl_.clearIdentitiesPromise(a).then(function(){return b.pibImpl_.setTpmLocatorPromise("", a)}).then(function(){b.defaultIdentity_=null;return Hc.makePromise(b.pibImpl_,a)}).then(function(c){b.identities_=c;return b.identities_.resetPromise(a)})};ka.prototype.addIdentityPromise_=function(a,b){var c=this;return this.initializePromise_(b).then(function(){return c.identities_.addPromise(a,b)})};ka.prototype.removeIdentityPromise_=function(a,b){null!=this.defaultIdentity_&&this.defaultIdentity_.getName().equals(a)&&(this.defaultIdentity_=null);var c=this;return this.initializePromise_(b).then(function(){return c.identities_.removePromise(a, b)})};ka.prototype.setDefaultIdentityPromise_=function(a,c){var w=this;return this.initializePromise_(c).then(function(){return w.identities_.addPromise(a,c)}).then(function(b){w.defaultIdentity_=b;return w.pibImpl_.setDefaultIdentityPromise(a)}).then(function(){return b.resolve(w.defaultIdentity_)})};ka.prototype.initializePromise_=function(a){if(this.isInitialized_)return b.resolve();var c=this;return Hc.makePromise(this.pibImpl_,a).then(function(w){c.identities_=w;return null!=c.initializeTpm_? c.initializeFromLocatorsPromise_(a):b.resolve()}).then(function(){c.isInitialized_=!0;return b.resolve()})};ka.prototype.initializeFromLocatorsPromise_=function(a){var c=[null],w=[null];C.parseAndCheckPibLocator_(this.initializePibLocator_,c,w);var f=c[0]+":"+w[0],t,y=this;return this.pibImpl_.getTpmLocatorPromise(a).then(function(c){var v=[null],w=[null];C.parseAndCheckTpmLocator_(y.initializeTpmLocator_,v,w);t=v[0]+":"+w[0];var v=!1,l;Bd&&(l=new Bd);if(Bd&&f==C.getDefaultPibLocator_(l))""!=c&&c!= C.getDefaultTpmLocator_(l)&&(v=!0,t=C.getDefaultTpmLocator_(l));else if(""!=c&&c!=t)if(y.initializeAllowReset_)v=!0;else return b.reject(new ke(Error("The supplied TPM locator does not match the TPM locator in the PIB: "+c+" != "+t)));return v?y.resetPromise_(a):b.resolve()}).then(function(){C.setUpTpm_(y.initializeTpm_,t);y.initializeTpm_.isInitialized_=!0;return y.doSetTpmLocatorPromise_(t,a)})};var C=a.KeyChain,ke=a.LocatorMismatchError,Hc=a.PibIdentityContainer,c=a.Name,ka=a.Pib,Vc=a.PibKeyContainer, b=a.SyncPromise,qc=function(){};r.PibIdentityImpl=qc;qc.makePromise=function(a,v,w,f){var t=new qc;return Vc.makePromise(a,v,f).then(function(y){t.defaultKey_=null;t.identityName_=new c(a);t.keys_=y;t.pibImpl_=v;return null==v?b.reject(Error("The pibImpl is null")):w?v.addIdentityPromise(t.identityName_,f).then(function(){return b.resolve(t)}):v.hasIdentityPromise(t.identityName_,f).then(function(a){return a?b.resolve(t):b.reject(new ka.Error(Error("Identity "+t.identityName_.toUri()+" does not exist")))})})}; qc.prototype.getName=function(){return this.identityName_};qc.prototype.addKeyPromise=function(a,b,c){return this.keys_.addPromise(a,b,c)};qc.prototype.removeKeyPromise=function(a,b){null!==this.defaultKey_&&this.defaultKey_.getName().equals(a)&&(this.defaultKey_=null);return this.keys_.removePromise(a,b)};qc.prototype.getKeyPromise=function(a,b){return this.keys_.getPromise(a,b)};qc.prototype.setDefaultKeyPromise=function(a,v,w){var f=this;if(a instanceof c){var t=a,y=v;return this.keys_.getPromise(t, y).then(function(a){f.defaultKey_=a;return f.pibImpl_.setDefaultKeyOfIdentityPromise(f.identityName_,t,y)}).then(function(){return b.resolve(f.defaultKey_)})}t=v;y=w;return this.addKeyPromise(a,t,y).then(function(){return f.setDefaultKeyPromise(t,y)})};qc.prototype.getDefaultKeyPromise=function(a){var c=this;return null===this.defaultKey_?this.pibImpl_.getDefaultKeyOfIdentityPromise(this.identityName_,a).then(function(b){return c.keys_.getPromise(b,a)}).then(function(a){c.defaultKey_=a;return b.resolve(c.defaultKey_)}): b.resolve(this.defaultKey_)};c=a.Name;Aa=a.PublicKey;m=a.Blob;ka=a.Pib;pa=a.PibKey;ca=a.PibImpl;Uc=a.PibCertificateContainer;b=a.SyncPromise;Tb=function(){};r.PibKeyImpl=Tb;Tb.makePromise=function(a,v,f,l){var t=new Tb;t.defaultCertificate_=null;if(v instanceof ca){var y=v,h=f;return null==y?b.reject(Error("The pibImpl is null")):Uc.makePromise(a,y,h).then(function(b){t.identityName_=pa.extractIdentityFromKeyName(a);t.keyName_=new c(a);t.pibImpl_=y;t.certificates_=b;return t.pibImpl_.getKeyBitsPromise(t.keyName_, h)}).then(function(a){t.keyEncoding_=a;try{publicKey=new Aa(t.keyEncoding_)}catch(c){return b.reject(new ka.Error(Error("Error decoding public key")))}t.keyType_=publicKey.getKeyType();return b.resolve(t)})}y=f;h=l;return null==y?b.reject(Error("The pibImpl is null")):Uc.makePromise(a,y,h).then(function(f){t.identityName_=pa.extractIdentityFromKeyName(a);t.keyName_=new c(a);t.keyEncoding_=new m(v,!0);t.pibImpl_=y;t.certificates_=f;try{publicKey=new Aa(t.keyEncoding_),t.keyType_=publicKey.getKeyType()}catch(w){return b.reject(Error("Invalid key encoding"))}return t.pibImpl_.addKeyPromise(t.identityName_, t.keyName_,v,h)}).then(function(){return b.resolve(t)})};Tb.prototype.getName=function(){return this.keyName_};Tb.prototype.getIdentityName=function(){return this.identityName_};Tb.prototype.getKeyType=function(){return this.keyType_};Tb.prototype.getPublicKey=function(){return this.keyEncoding_};Tb.prototype.addCertificatePromise=function(a,b){return this.certificates_.addPromise(a,b)};Tb.prototype.removeCertificatePromise=function(a,b){null!==this.defaultCertificate_&&this.defaultCertificate_.getName().equals(a)&& (this.defaultCertificate_=null);return this.certificates_.removePromise(a,b)};Tb.prototype.getCertificatePromise=function(a,b){return this.certificates_.getPromise(a,b)};Tb.prototype.setDefaultCertificatePromise=function(a,v){var f=this,l;return b.resolve().then(function(){return a instanceof c?b.resolve(a):f.addCertificatePromise(a).then(function(){return b.resolve(a.getName())})}).then(function(a){l=a;return f.certificates_.getPromise(l,v)}).then(function(a){f.defaultCertificate_=a;return f.pibImpl_.setDefaultCertificateOfKeyPromise(f.keyName_, l,v)}).then(function(){return b.resolve(f.defaultCertificate_)})};Tb.prototype.getDefaultCertificatePromise=function(a){var c=this;return null===this.defaultCertificate_?this.pibImpl_.getDefaultCertificateOfKeyPromise(this.keyName_,a).then(function(a){c.defaultCertificate_=a;return b.resolve(c.defaultCertificate_)}):b.resolve(c.defaultCertificate_)};var Oe=function(a,b,c,f,t){this.interest=a;this.onVerified=b;this.onValidationFailed=c;this.retry=f;this.stepCount=t};r.ValidationRequest=Oe;var W=a, m=a.Blob,L=a.DataUtils,x=a.SecurityException,xb=a.DigestSha256Signature,Ja=a.Sha256WithRsaSignature,Xa=a.Sha256WithEcdsaSignature,Sa=a.VerificationHelpers,Ga=a.DigestAlgorithm,Aa=a.PublicKey,b=a.SyncPromise,ob=function(){};r.PolicyManager=ob;ob.prototype.skipVerifyAndTrust=function(a){throw Error("PolicyManager.skipVerifyAndTrust is not implemented");};ob.prototype.requireVerify=function(a){throw Error("PolicyManager.requireVerify is not implemented");};ob.prototype.checkVerificationPolicy=function(a, b,c,f,t){throw Error("PolicyManager.checkVerificationPolicy is not implemented");};ob.prototype.checkSigningPolicy=function(a,b){throw Error("PolicyManager.checkSigningPolicy is not implemented");};ob.prototype.inferSigningIdentity=function(a){throw Error("PolicyManager.inferSigningIdentity is not implemented");};ob.verifyUsesString_=null;ob.setVerifyUsesString_=function(){var a=W.createHash("sha256").digest();ob.verifyUsesString_="string"===typeof a};ob.verifySignature=function(a,c,f,l){if(a instanceof Ja||a instanceof Xa)if(f.isNull())l(!1);else{var t;try{t=new Aa(f)}catch(y){throw new x(Error("PolicyManager.verify: Error decoding public key: "+y));}b.complete(l,Sa.verifySignaturePromise(c.signedBuf(),a.getSignature(),t,Ga.SHA256,!l))}else if(a instanceof xb)l(Sa.verifyDigest(c.signedBuf(),a.getSignature(),Ga.SHA256));else throw new x(Error("PolicyManager.verify: Signature type is unknown"));};var Na=a.IdentityCertificate,ld=function(){this.cache={}};r.CertificateCache=ld;ld.prototype.insertCertificate= function(a){var b=a.getName().getPrefix(-1);this.cache[b.toUri()]=a.wireEncode()};ld.prototype.deleteCertificate=function(a){delete this.cache[a.toUri()]};ld.prototype.getCertificate=function(a){a=this.cache[a.toUri()];if(void 0===a)return null;var b=new Na;b.wireDecode(a);return b};ld.prototype.reset=function(){this.cache={}};var le=Qb=a,c=a.Name,R=a.Data,D=a.Interest,V=a.KeyLocator,ta=a.KeyLocatorType,m=a.Blob,Na=a.IdentityCertificate,N=a.CertificateV2,dc=a.CertificateCacheV2,kc=a.BoostInfoParser, Za=a.NdnRegexTopMatcher,ld=a.CertificateCache,Oe=a.ValidationRequest,x=a.SecurityException,s=a.WireFormat,ob=a.PolicyManager,M=a.NdnCommon,za=function(a,b,c,f,t,y){ob.call(this);void 0==b&&(b=null);void 0==c&&(c=5);void 0==f&&(f=3E3);void 0==t&&(t=36E5);void 0==y&&(y=1E3);null==b&&(b=new ld);b instanceof ld?(this.isSecurityV1_=!0,this.certificateCache_=b,this.certificateCacheV2_=null):(this.isSecurityV1_=!1,this.certificateCache_=null,this.certificateCacheV2_=b);this.maxDepth=c;this.keyGraceInterval= f;this.keyTimestampTtl=t;this.maxTrackedKeys=y;this.reset();null!=a&&""!=a&&this.load(a)};za.prototype=new ob;za.prototype.name="ConfigPolicyManager";r.ConfigPolicyManager=za;za.prototype.reset=function(){this.isSecurityV1_?this.certificateCache_.reset():this.certificateCacheV2_.clear();this.fixedCertificateCache={};this.keyTimestamps={};this.requiresVerification=!0;this.config=new kc;this.refreshManager=new za.TrustAnchorRefreshManager(this.isSecurityV1_)};za.prototype.load=function(a,b){this.reset(); this.config.read(a,b);this.loadTrustAnchorCertificates()};za.prototype.requireVerify=function(a){return this.requiresVerification};za.prototype.checkSigningPolicy=function(a,b){return!0};za.prototype.skipVerifyAndTrust=function(a){return!this.requiresVerification};za.prototype.checkVerificationPolicy=function(a,b,c,f,t){var y=a.getName(),l="data";a instanceof D&&(y=y.getPrefix(-4),l="interest");t=za.extractSignature(a,t);if(null==t){try{f(a,"Cannot extract the signature from "+a.getName().toUri())}catch(h){console.log("Error in onValidationFailed: "+ M.getErrorWithStackTrace(h))}return null}var m=["unknown"],y=this.getCertificateInterest_(b,l,y,t,m);if(null==y){try{f(a,m[0])}catch(n){console.log("Error in onValidationFailed: "+M.getErrorWithStackTrace(n))}return null}if(0this.maxDepth)return t[0]="The verification stepCount "+a+" exceeded the maxDepth "+this.maxDepth,null;var y;try{y= this.findMatchingRule(c,b)}catch(l){return null}if(null==y)return t[0]="No matching rule found for "+c.toUri(),null;if(!V.canGetFromSignature(f))return t[0]="The signature type does not support a KeyLocator",null;a=a=V.getFromSignature(f);a=a.getKeyName();if(0==a.size())return t[0]="The signature KeyLocator doesn't have a key name",null;if(!this.checkSignatureMatch(a,c,y,t))return null;this.refreshManager.refreshAnchors();this.isSecurityV1_?(c=this.refreshManager.getCertificate(a),null==c&&(c=this.certificateCache_.getCertificate(a))): (c=this.refreshManager.getCertificateV2(a),null==c&&(c=this.certificateCacheV2_.find(a)));return null==c?new D(a):new D};za.prototype.loadTrustAnchorCertificates=function(){for(var a=this.config.getRoot().get("validator/trust-anchor"),b=0;b]*)(<>*)");if(f.match(a)){a=f.expand("\\1").append(f.expand("\\2"));if(za.matchesRelation(b,a,"is-prefix-of"))return!0;l[0]='The hierarchical objectName "'+b.toUri()+'" is not a prefix of "'+a.toUri()+'"';return!1}if(!this.isSecurityV1_&& (f=new Za("^(<>*)<>$"),f.match(a))){a=f.expand("\\1");if(za.matchesRelation(b,a,"is-prefix-of"))return!0;l[0]='The hierarchical objectName "'+b.toUri()+'" is not a prefix of "'+a.toUri()+'"';return!1}l[0]='The hierarchical identityRegex "^([^]*)(<>*)" does not match signatureName "'+a.toUri()+'"';return!1}if("customized"==t){var y=f.get("key-locator")[0];f=y.getFirstValue("relation");if(null!=f){b=new c(y.get("name")[0].getValue());if(za.matchesRelation(a,b,f))return!0; l[0]='The custom signatureName "'+a.toUri()+'" does not match matchName "'+b.toUri()+'" using relation '+f;return!1}var h=y.getFirstValue("regex");if(null!=h){if((new Za(simpleKeyRegex)).match(a))return!0;l[0]='The custom signatureName "'+a.toUri()+'" does not regex match simpleKeyRegex "'+h+'"';return!1}f=y.get("hyper-relation");if(1<=f.length){f=f[0];var h=f.getFirstValue("k-regex"),ya=f.getFirstValue("k-expand"),y=f.getFirstValue("p-regex"),m=f.getFirstValue("p-expand");f=f.getFirstValue("h-relation"); if(null!=h&&null!=ya&&null!=y&&null!=m&&null!=f){t=new Za(h);if(!t.match(a))return l[0]='The custom hyper-relation signatureName "'+a.toUri()+'" does not match the keyRegex "'+h+'"',!1;a=t.expand(ya);t=new Za(y);if(!t.match(b))return l[0]='The custom hyper-relation objectName "'+b.toUri()+'" does not match the nameRegex "'+y+'"',!1;b=t.expand(m);if(za.matchesRelation(b,a,f))return!0;l[0]='The custom hyper-relation nameMatch "'+b.toUri()+'" does not match the keyMatchPrefix "'+a.toUri()+'" using relation '+ f;return!1}}}l[0]="Unrecognized checkerType: "+t;return!1};za.prototype.lookupCertificate=function(a,b){if(!this.isSecurityV1_)throw new x(Error("lookupCertificate: For security v2, use lookupCertificateV2()"));var f;f=this.fixedCertificateCache[a];if(void 0===f){if(b)f=za.TrustAnchorRefreshManager.loadIdentityCertificateFromFile(a);else{var l=new h(a,"base64");f=new Na;f.wireDecode(l)}l=f.getName().getPrefix(-1).toUri();this.fixedCertificateCache[a]=l;this.certificateCache_.insertCertificate(f)}else f= this.certificateCache_.getCertificate(new c(f));return f};za.prototype.lookupCertificateV2=function(a,b){if(this.isSecurityV1_)throw new x(Error("lookupCertificateV2: For security v1, use lookupCertificate()"));var f;f=this.fixedCertificateCache[a];if(void 0===f){if(b)f=za.TrustAnchorRefreshManager.loadCertificateV2FromFile(a);else{var l=new h(a,"base64");f=new N;f.wireDecode(l)}l=f.getName().getPrefix(-1).toUri();this.fixedCertificateCache[a]=l;this.certificateCacheV2_.insert(f)}else f=this.certificateCacheV2_.find(new c(f)); return f};za.prototype.findMatchingRule=function(a,b){for(var f=this.config.getRoot().get("validator/rule"),l=0;la-this.keyGraceInterval&&bthis.keyTimestampTtl?f.push(h):m=this.maxTrackedKeys){for(t=0;tthis.maxTrackedKeys&&delete this.keyTimestamps[l]}};za.prototype.verify=function(a,b,c){var f=V.getFromSignature(a);if(f.getType()==ta.KEYNAME){var f=f.getKeyName(),t;if(this.isSecurityV1_){var y=this.refreshManager.getCertificate(f);null==y&&(y=this.certificateCache_.getCertificate(f));if(null==y){c(!1, "Cannot find a certificate with name "+f.toUri());return}t=y.getPublicKeyInfo().getKeyDer();if(t.isNull()){c(!1,"There is no public key in the certificate with name "+y.getName().toUri());return}}else{y=this.refreshManager.getCertificateV2(f);null==y&&(y=this.certificateCacheV2_.find(f));if(null==y){c(!1,"Cannot find a certificate with name "+f.toUri());return}try{t=y.getPublicKey()}catch(l){c(!1,"There is no public key in the certificate with name "+y.getName().toUri());return}}ob.verifySignature(a, b,t,function(a){a?c(!0):c(!1,"The signature did not verify with the given public key")})}else c(!1,"The KeyLocator does not have a key name")};za.TrustAnchorRefreshManager=function(a){this.isSecurityV1_=a;this.certificateCache_=new ld;this.certificateCacheV2_=new dc;this.refreshDirectories={}};za.TrustAnchorRefreshManager.loadIdentityCertificateFromFile=function(a){a=Qb.readFileSync(a).toString();a=new h(a,"base64");var b=new Na;b.wireDecode(new m(a,!1));return b};za.TrustAnchorRefreshManager.loadCertificateV2FromFile= function(a){a=Qb.readFileSync(a).toString();a=new h(a,"base64");var b=new N;b.wireDecode(new m(a,!1));return b};za.TrustAnchorRefreshManager.prototype.getCertificate=function(a){if(!this.isSecurityV1_)throw new x(Error("getCertificate: For security v2, use getCertificateV2()"));return this.certificateCache_.getCertificate(a)};za.TrustAnchorRefreshManager.prototype.getCertificateV2=function(a){if(this.isSecurityV1_)throw new x(Error("getCertificateV2: For security v1, use getCertificate()"));return this.certificateCacheV2_.find(a)}; za.TrustAnchorRefreshManager.prototype.addDirectory=function(a,b){var c;try{c=Qb.readdirSync(a)}catch(f){throw new x(Error("Cannot list files in directory "+a));}for(var t=[],y=0;ya.getName().size()){try{f(a,"The signed interest has less than 2 components: "+a.getName().toUri())}catch(l){console.log("Error in onValidationFailed: "+M.getErrorWithStackTrace(l))}return}var h;try{h=t.decodeSignatureInfoAndValue(a.getName().get(-2).getValue().buf(),a.getName().get(-1).getValue().buf(),!1)}catch(ya){try{f(a,"Error decoding the signed interest signature: "+ya)}catch(m){console.log("Error in onValidationFailed: "+M.getErrorWithStackTrace(m))}return}this.verify(h, a.wireEncode(),function(b,t){if(b)try{c(a)}catch(v){console.log("Error in onVerified: "+M.getErrorWithStackTrace(v))}else try{f(a,t)}catch(l){console.log("Error in onValidationFailed: "+M.getErrorWithStackTrace(l))}})}else throw new x(Error("checkVerificationPolicy: unrecognized type for dataOrInterest"));return null};Wc.prototype.checkSigningPolicy=function(a,b){return!0};Wc.prototype.inferSigningIdentity=function(a){return new c};Wc.prototype.verify=function(a,b,c){if(V.canGetFromSignature(a))this.getPublicKeyDer(V.getFromSignature(a), function(f,l){if(f.isNull())c(!1,l);else try{ob.verifySignature(a,b,f,function(a){a?c(!0):c(!1,"The signature did not verify with the given public key")})}catch(h){c(!1,"Error in verifySignature: "+h)}});else try{ob.verifySignature(a,b,null,function(a){a?c(!0):c(!1,"The signature did not verify with the given public key")})}catch(f){c(!1,"Error in verifySignature: "+f)}};Wc.prototype.getPublicKeyDer=function(a,c){if(a.getType()==ta.KEYNAME&&null!=this.identityStorage_){var f;try{f=Na.certificateNameToPublicKeyName(a.getKeyName())}catch(l){c(new m, "Cannot get a public key name from the certificate named: "+a.getKeyName().toUri());return}b.complete(c,function(a){c(new m,"The identityStorage doesn't have the key named "+f.toUri())},this.identityStorage_.getKeyPromise(f,!c))}else a.getType()==ta.KEYNAME&&null!=this.pibImpl_?b.complete(c,function(a){c(new m,"The identityStorage doesn't have the key named "+f.toUri())},this.pibImpl_.getKeyBitsPromise(a.getKeyName(),!c)):c(new m,"The signature KeyLocator doesn't have a key name")};var W=a,c=a.Name, m=a.Blob,yb=a.KeyIdType,pa=a.PibKey,eb=a.Tpm,b=a.SyncPromise,Ha=function(){};r.TpmBackEnd=Ha;Ha.Error=function(a){if(a)return a.__proto__=Ha.Error.prototype,a};Ha.Error.prototype=Error();Ha.Error.prototype.name="TpmBackEndError";Ha.prototype.hasKeyPromise=function(a,b){return this.doHasKeyPromise_(a,b)};Ha.prototype.getKeyHandlePromise=function(a,b){return this.doGetKeyHandlePromise_(a,b)};Ha.prototype.createKeyPromise=function(a,f,w){var l=this;return b.resolve().then(function(){if(f.getKeyIdType()== yb.USER_SPECIFIED){var t=pa.constructKeyName(a,f.getKeyId());return l.hasKeyPromise(t,w).then(function(a){return a?b.reject(new eb.Error(Error("Key `"+t.toUri()+"` already exists"))):b.resolve()})}if(f.getKeyIdType()==yb.SHA256)return b.resolve();if(f.getKeyIdType()==yb.RANDOM){var y,h=function(){var f=W.randomBytes(8);y=new c.Component(new m(f,!1));f=pa.constructKeyName(a,y);return l.hasKeyPromise(f,w).then(function(a){return a?h():b.resolve()})};return h().then(function(){f.setKeyId(y);return b.resolve()})}return b.reject(new eb.Error(Error("Unsupported key id type")))}).then(function(){return l.doCreateKeyPromise_(a, f,w)})};Ha.prototype.deleteKeyPromise=function(a,b){return this.doDeleteKeyPromise_(a,b)};Ha.prototype.exportKeyPromise=function(a,c,f){var l=this;return this.hasKeyPromise(a,f).then(function(t){return t?l.doExportKeyPromise_(a,c,f):b.reject(new Ha.Error(Error("Key `"+a.toUri()+"` does not exist")))})};Ha.prototype.importKeyPromise=function(a,c,f,l){var t=this;return this.hasKeyPromise(a,l).then(function(y){return y?b.reject(new Ha.Error(Error("Key `"+a.toUri()+"` already exists"))):t.doImportKeyPromise_(a, c,f,l)})};Ha.setKeyName=function(a,b,f){if(f.getKeyIdType()==yb.USER_SPECIFIED)f=f.getKeyId();else if(f.getKeyIdType()==yb.SHA256)f=W.createHash("sha256"),f.update(a.derivePublicKey().buf()),f=c.Component(new m(f.digest(),!1));else if(f.getKeyIdType()==yb.RANDOM){if(0==f.getKeyId().getValue().size())throw new Ha.Error(Error("setKeyName: The keyId is empty for type RANDOM"));f=f.getKeyId()}else throw new Ha.Error(Error("setKeyName: unrecognized params.getKeyIdType()"));a.setKeyName(pa.constructKeyName(b, f))};Ha.prototype.doHasKeyPromise_=function(a,c){return b.reject(Error("TpmBackEnd.doHasKeyPromise_ is not implemented"))};Ha.prototype.doGetKeyHandlePromise_=function(a,c){return b.reject(Error("TpmBackEnd.doGetKeyHandlePromise_ is not implemented"))};Ha.prototype.doCreateKeyPromise_=function(a,c,f){return b.reject(Error("TpmBackEnd.doCreateKeyPromise_ is not implemented"))};Ha.prototype.doDeleteKeyPromise_=function(a,c){return b.reject(Error("TpmBackEnd.doDeleteKeyPromise_ is not implemented"))}; Ha.prototype.doExportKeyPromise_=function(a,c,f){return b.reject(Error("TpmBackEnd.doExportKeyPromise_ is not implemented"))};Ha.prototype.doImportKeyPromise_=function(a,c,f,l){return b.reject(Error("TpmBackEnd.doImportKeyPromise_ is not implemented"))};var b=a.SyncPromise,Q=a.TpmPrivateKey,md=a.TpmKeyHandleMemory,Ha=a.TpmBackEnd,cc=function(){Ha.call(this);this.keys_={}};cc.prototype=new Ha;cc.prototype.name="TpmBackEndMemory";r.TpmBackEndMemory=cc;cc.getScheme=function(){return"tpm-memory"};cc.prototype.doHasKeyPromise_= function(a,c){return b.resolve(a.toUri()in this.keys_)};cc.prototype.doGetKeyHandlePromise_=function(a,c){var f=this.keys_[a.toUri()];return void 0==f?b.resolve(null):b.resolve(new md(f))};cc.prototype.doCreateKeyPromise_=function(a,c,f){var l=this;return Q.generatePrivateKeyPromise(c,f).then(function(f){var w=new md(f);Ha.setKeyName(w,a,c);l.keys_[w.getKeyName().toUri()]=f;return b.resolve(w)},function(a){return b.reject(new Ha.Error(Error("Error in TpmPrivateKey.generatePrivateKey: "+a)))})};cc.prototype.doDeleteKeyPromise_= function(a,c){delete this.keys_[a.toUri()];return b.resolve()};Ha.prototype.doExportKeyPromise_=function(a,c,f){a=a.toUri();if(!(a in this.keys_))return b.reject(new Ha.Error(Error("exportKey: The key does not exist")));try{return null!=c?b.resolve(this.keys_[a].toEncryptedPkcs8(c)):b.resolve(this.keys_[a].toPkcs8())}catch(l){return b.reject(new Ha.Error(Error("Error in toPkcs8: "+l)))}};cc.prototype.doImportKeyPromise_=function(a,c,f,l){try{var t=new Q;null!=f?t.loadEncryptedPkcs8(c,f):t.loadPkcs8(c); this.keys_[a.toUri()]=t;return b.resolve()}catch(y){return b.reject(new Ha.Error(Error("Cannot import private key: "+y)))}};var c=a.Name,b=a.SyncPromise,rc=function(){this.keyName_=new c};r.TpmKeyHandle=rc;rc.prototype.signPromise=function(a,b,c){return this.doSignPromise_(a,b,c)};rc.prototype.decryptPromise=function(a,b){return this.doDecryptPromise_(a,b)};rc.prototype.derivePublicKey=function(a){return this.doDerivePublicKey_(a)};rc.prototype.setKeyName=function(a){this.keyName_=new c(a)};rc.prototype.getKeyName= function(){return this.keyName_};rc.prototype.doSignPromise_=function(a,c,f){return b.reject(Error("TpmKeyHandle.doSignPromise_ is not implemented"))};rc.prototype.doDecryptPromise_=function(a,c){return b.reject(Error("TpmKeyHandle.doDecryptPromise_ is not implemented"))};rc.prototype.doDerivePublicKey_=function(a){return b.reject(Error("TpmKeyHandle.doDerivePublicKey_ is not implemented"))};m=a.Blob;b=a.SyncPromise;Ga=a.DigestAlgorithm;Q=a.TpmPrivateKey;Ha=a.TpmBackEnd;rc=a.TpmKeyHandle;md=function(a){rc.call(this); if(null==a)throw Error("The key is null");this.key_=a};md.prototype=new rc;md.prototype.name="TpmKeyHandleMemory";r.TpmKeyHandleMemory=md;md.prototype.doSignPromise_=function(a,c,f){return a==Ga.SHA256?this.key_.signPromise(c,a,f).catch(function(a){return b.reject(new Ha.Error(Error("Error in TpmPrivateKey.sign: "+a)))}):b.resolve(new m)};md.prototype.doDecryptPromise_=function(a,c){return this.key_.decryptPromise(a,c).catch(function(a){return b.reject(new Ha.Error(Error("Error in TpmPrivateKey.decrypt: "+ a)))})};md.prototype.doDerivePublicKey_=function(){try{return this.key_.derivePublicKey()}catch(a){throw new Ha.Error(Error("Error in TpmPrivateKey.derivePublicKey: "+a));}};var zd=a.constants,W=a,ea=a.KeyType,fa=a.EncryptAlgorithmType,Ga=a.DigestAlgorithm,L=a.DataUtils,b=a.SyncPromise,l=a.DerNode,Zd=a.DerNode.DerSequence,nd=a.DerNode.DerInteger,mb=a.OID,m=a.Blob,Gb=a.UseSubtleCrypto,Fc=null;try{Fc=a}catch(nf){}Q=function(){this.decryptSubtleKey_=this.subtleKey_=this.privateKey_=this.keyType_=null}; r.TpmPrivateKey=Q;Q.Error=function(a){if(a)return a.__proto__=Q.Error.prototype,a};Q.Error.prototype=Error();Q.Error.prototype.name="TpmPrivateKeyError";Q.prototype.loadPkcs1=function(a,b){a instanceof m&&(a=a.buf());if(void 0==b)try{var c=l.parse(a).getChildren();b=9==c.length&&c[0]instanceof nd&&0==c[0].toVal()&&c[1]instanceof nd&&c[2]instanceof nd&&c[3]instanceof nd&&c[4]instanceof nd&&c[5]instanceof nd&&c[6]instanceof nd&&c[7]instanceof nd&&c[8]instanceof nd?ea.RSA:ea.EC}catch(f){b=ea.EC}if(b== ea.EC){for(var c=a.toString("base64"),t="-----BEGIN EC PRIVATE KEY-----\n",y=0;yb.size()?!1:this.checkNames(b.getPrefix(-2),c,f):this.checkNames(b,c,f)};Bb.create=function(a){var b=a.getFirstValue("type");if(null==b)throw new sa(Error("Expected "));if("customized"==b.toLowerCase())return Bb.createCustomizedChecker_(a); if("hierarchical"==b.toLowerCase())return Bb.createHierarchicalChecker_(a);throw new sa(Error("Unsupported checker type: "+b));};Bb.prototype.checkNames=function(a,b,c){throw Error("ConfigChecker.checkNames is not implemented");};Bb.createCustomizedChecker_=function(a){keyLocatorSection=a.get("key-locator");if(1!=keyLocatorSection.length)throw new sa(Error("Expected one "));return Bb.createKeyLocatorChecker_(keyLocatorSection[0])};Bb.createHierarchicalChecker_=function(a){return new $d("^(<>*)$", "\\1","^(<>*)<>$","\\1",Ya.Relation.IS_PREFIX_OF)};Bb.createKeyLocatorChecker_=function(a){var b=a.getFirstValue("type");if(null==b)throw new sa(Error("Expected "));if("name"==b.toLowerCase())return Bb.createKeyLocatorNameChecker_(a);throw new sa(Error("Unsupported checker.key-locator.type: "+b));};Bb.createKeyLocatorNameChecker_=function(a){var b=a.getFirstValue("name");if(null!=b){b=new c(b);a=a.getFirstValue("relation");if(null==a)throw new sa(Error("Expected ")); y=Ya.getNameRelationFromString(a);return new me(b,y)}b=a.getFirstValue("regex");if(null!=b)try{return new ne(b)}catch(f){throw new sa(Error("Invalid checker.key-locator.regex: "+b));}a=a.get("hyper-relation");if(1==a.length){var l=a[0];a=l.getFirstValue("k-regex");if(null==a)throw new sa(Error("Expected "));b=l.getFirstValue("k-expand");if(null==b)throw new sa(Error("Expected "));var t=l.getFirstValue("p-regex");if(null==t)throw new sa(Error("Expected "));l=l.getFirstValue("p-expand");if(null==l)throw new sa(Error("Expected "));var y=Ya.getNameRelationFromString(y);try{return new $d(t,l,a,b,y)}catch(h){throw new sa(Error("Invalid regex for key-locator.hyper-relation"));}}throw new sa(Error("Unsupported checker.key-locator")); };var me=function(a,b){Bb.call(this);this.name_=a;this.relation_=b};me.prototype=new Bb;me.prototype.name="ConfigNameRelationChecker";r.ConfigNameRelationChecker=me;me.prototype.checkNames=function(a,b,c){var f=pa.extractIdentityFromKeyName(b),t=Ya.checkNameRelation(this.relation_,this.name_,f);t||c.fail(new I(I.POLICY_ERROR,"KeyLocator check failed: name relation "+this.name_.toUri()+" "+Ya.toString(this.relation_)+" for packet "+a.toUri()+" is invalid (KeyLocator="+b.toUri()+", identity="+f.toUri()+ ")"));return t};var ne=function(a){Bb.call(this);this.regex_=new Za(a)};ne.prototype=new Bb;ne.prototype.name="ConfigRegexChecker";r.ConfigRegexChecker=ne;ne.prototype.checkNames=function(a,b,c){var f=this.regex_.match(b);f||c.fail(new I(I.POLICY_ERROR,"KeyLocator check failed: regex "+this.regex_.getExpr()+" for packet "+a.toUri()+" is invalid (KeyLocator="+b.toUri()+")"));return f};var $d=function(a,b,c,f,t){Bb.call(this);this.packetNameRegex_=new Za(a);this.packetNameExpansion_=b;this.keyNameRegex_= new Za(c);this.keyNameExpansion_=f;this.hyperRelation_=t};$d.prototype=new Bb;$d.prototype.name="ConfigHyperRelationChecker";r.ConfigHyperRelationChecker=$d;$d.prototype.checkNames=function(a,b,c){if(!this.packetNameRegex_.match(a))return c.fail(new I(I.POLICY_ERROR,"The packet "+a.toUri()+" (KeyLocator="+b.toUri()+") does not match the hyper relation packet name regex "+this.packetNameRegex_.getExpr())),!1;if(!this.keyNameRegex_.match(b))return c.fail(new I(I.POLICY_ERROR,"The packet "+a.toUri()+ " (KeyLocator="+b.toUri()+") does not match the hyper relation key name regex "+this.keyNameRegex_.getExpr())),!1;var f=this.keyNameRegex_.expand(this.keyNameExpansion_),t=this.packetNameRegex_.expand(this.packetNameExpansion_),l=Ya.checkNameRelation(this.hyperRelation_,f,t);l||c.fail(new I(I.POLICY_ERROR,"KeyLocator check failed: hyper relation "+Ya.toString(this.hyperRelation_)+" packet name match="+t.toUri()+", key name match="+f.toUri()+" of packet "+a.toUri()+" (KeyLocator="+b.toUri()+") is invalid")); return l};var c=a.Name,Ya=a.ConfigNameRelation,Za=a.NdnRegexTopMatcher,sa=a.ValidatorConfigError,tc=function(){};r.ConfigFilter=tc;tc.prototype.match=function(a,b){return a?2>b.size()?!1:this.matchName(b.getPrefix(-2)):this.matchName(b)};tc.create=function(a){var b=a.getFirstValue("type");if(null==b)throw new sa(Error("Expected "));if("name"==b.toLowerCase())return tc.createNameFilter_(a);throw new sa(Error("Unsupported filter.type: "+b));};tc.prototype.matchName=function(a){throw Error("ConfigFilter.matchName is not implemented"); };tc.createNameFilter_=function(a){var b=a.getFirstValue("name");if(null!=b){b=new c(b);a=a.getFirstValue("relation");if(null==a)throw new sa(Error("Expected "));a=Ya.getNameRelationFromString(a);return new oe(b,a)}b=a.getFirstValue("regex");if(null!=b)try{return new pe(b)}catch(f){throw new sa(Error("Wrong filter.regex: "+b));}throw new sa(Error("Wrong filter(name) properties"));};var oe=function(a,b){tc.call(this);this.name_=new c(a);this.relation_=b};oe.prototype=new tc;oe.prototype.name= "ConfigRelationNameFilter";r.ConfigRelationNameFilter=oe;oe.prototype.matchName=function(a){return Ya.checkNameRelation(this.relation_,this.name_,a)};var pe=function(a){tc.call(this);this.regex_=new Za(a)};pe.prototype=new tc;pe.prototype.name="ConfigRegexNameFilter";r.ConfigRegexNameFilter=pe;pe.prototype.matchName=function(a){return this.regex_.match(a)};sa=a.ValidatorConfigError;Ya=function(){};r.ConfigNameRelation=Ya;Ya.Relation=function(){};Ya.Relation.EQUAL=0;Ya.Relation.IS_PREFIX_OF=1;Ya.Relation.IS_STRICT_PREFIX_OF= 2;Ya.toString=function(a){return a==Ya.Relation.EQUAL?"equal":a==Ya.Relation.IS_PREFIX_OF?"is-prefix-of":a==Ya.Relation.IS_STRICT_PREFIX_OF?"is-strict-prefix-of":""};Ya.checkNameRelation=function(a,b,c){return a==Ya.Relation.EQUAL?b.equals(c):a==Ya.Relation.IS_PREFIX_OF?b.isPrefixOf(c):a==Ya.Relation.IS_STRICT_PREFIX_OF?b.isPrefixOf(c)&&b.size()"));var c=a.getFirstValue("for");if(null==c)throw new sa(Error("Expecting in rule: "+b));if("data"==c.toLowerCase())c= !1;else if("interest"==c.toLowerCase())c=!0;else throw new sa(Error("Unrecognized : "+c+" in rule: "+b));for(var c=new Ic(b,c),f=a.get("filter"),t=0;t is specified in rule: "+b));return c};var Qb=a,m=a.Blob,N=a.CertificateV2,uc=function(a,b){this.certificates_=a;this.id_=b;this.anchorNameUris_={}};r.TrustAnchorGroup=uc;uc.prototype.getId= function(){return this.id_};uc.prototype.size=function(){return Object.keys(this.anchorNameUris_).length};uc.prototype.refresh=function(){};uc.readCertificate=function(a){try{var b=Qb.readFileSync(a).toString(),c=new h(b,"base64"),f=new N;f.wireDecode(new m(c,!1));return f}catch(t){return null}};var b=a.SyncPromise,I=a.ValidationError,f=a.Log.LOG,Sa=a.VerificationHelpers,N=a.CertificateV2,Hb=function(){this.certificateChain_=[];this.seenCertificateNameUris_={};this.outcome_=this.hasOutcome_=!1};r.ValidationState= Hb;Hb.prototype.hasOutcome=function(){return this.hasOutcome_};Hb.prototype.isOutcomeFailed=function(){return this.hasOutcome_&&!1==this.outcome_};Hb.prototype.isOutcomeSuccess=function(){return this.hasOutcome_&&!0==this.outcome_};Hb.prototype.fail=function(a){throw Error("ValidationState.fail is not implemented");};Hb.prototype.getDepth=function(){return this.certificateChain_.length};Hb.prototype.hasSeenCertificateName=function(a){a=a.toUri();if(void 0!==this.seenCertificateNameUris_[a])return!0; this.seenCertificateNameUris_[a]=!0;return!1};Hb.prototype.addCertificate=function(a){this.certificateChain_.unshift(new N(a))};Hb.prototype.setOutcome=function(a){if(this.hasOutcome_)throw Error("The ValidationState already has an outcome");this.hasOutcome_=!0;this.outcome_=a};Hb.prototype.verifyOriginalPacketPromise_=function(a){return b.reject(Error("ValidationState.verifyOriginalPacketPromise_ is not implemented"))};Hb.prototype.bypassValidation_=function(){throw Error("ValidationState.bypassValidation_ is not implemented"); };Hb.prototype.verifyCertificateChainPromise_=function(a){var c=a,l=this,h=function(a){if(a>=l.certificateChain_.length)return b.resolve(c);var y=l.certificateChain_[a];return Sa.verifyDataSignaturePromise(y,c).then(function(m){if(m)3a;)l.certificateChain_.splice(a,1);return b.resolve(null)}++a; return h(a)})};return h(0)};var c=a.Name,ha=a.Schedule,N=a.CertificateV2,f=a.Log.LOG,dc=function v(a){this.certificatesByName_=[];this.nextRefreshTime_=Number.MAX_VALUE;this.maxLifetimeMilliseconds_=void 0==a?v.getDefaultLifetime():a;this.nowOffsetMilliseconds_=0};r.CertificateCacheV2=dc;dc.prototype.insert=function(a){var b=a.getValidityPeriod().getNotAfter(),c=(new Date).getTime()+this.nowOffsetMilliseconds_;if(bt)t=this.certificatesByName_.length;else if(this.certificatesByName_[t].name.equals(c)){this.certificatesByName_[t].certificate=a;this.certificatesByName_[t].removalTime=b;return}this.certificatesByName_.splice(t,0,{name:c,certificate:a,removalTime:b})}}; dc.prototype.find=function(a){if(a instanceof c){0b)return null;b=this.certificatesByName_[b];return a.isPrefixOf(b.certificate.getName())?b.certificate:null}null!=a.getChildSelector()&&console.log("Certificate search using a ChildSelector is not supported. Searching as if this selector not specified");0b)return null;for(;bthis.getMetaInfo().getFreshnessPeriod())throw new N.Error(Error("The Data FreshnessPeriod is not set"));if(0==this.getContent().size())throw new N.Error(Error("The Data Content is empty"));};N.prototype.getKeyName=function(){return this.getName().getPrefix(N.KEY_ID_OFFSET+1)};N.prototype.getIdentity=function(){return this.getName().getPrefix(N.KEY_COMPONENT_OFFSET)};N.prototype.getKeyId=function(){return this.getName().get(N.KEY_ID_OFFSET)}; N.prototype.getIssuerId=function(){return this.getName().get(N.ISSUER_ID_OFFSET)};N.prototype.getPublicKey=function(){if(0==this.getContent().size())throw new N.Error(Error("The public key is not set (the Data content is empty)"));return this.getContent()};N.prototype.getValidityPeriod=function(){if(!Ea.canGetFromSignature(this.getSignature()))throw new ec(Error("The SignatureInfo does not have a ValidityPeriod"));return Ea.getFromSignature(this.getSignature())};N.prototype.isValid=function(a){return this.getValidityPeriod().isValid(a)}; N.prototype.wireDecode=function(a,b){b=b||s.getDefaultWireFormat();R.prototype.wireDecode.call(this,a,b);this.checkFormat_()};N.prototype.toString=function(){var a;a="Certificate name:\n"+(" "+this.getName().toUri()+"\n");a+="Validity:\n";a+=" NotBefore: "+ha.toIsoString(this.getValidityPeriod().getNotBefore())+"\n";a+=" NotAfter: "+ha.toIsoString(this.getValidityPeriod().getNotAfter())+"\n";a+="Public key bits:\n";try{for(var b=this.getPublicKey().buf().toString("base64"),c=0;c\n";V.canGetFromSignature(this.getSignature())&&(a+=" Key Locator: ",b=V.getFromSignature(this.getSignature()),b.getType()==ta.KEYNAME?(b.getKeyName().equals(this.getKeyName())&&(a+="Self-Signed "),a+="Name="+b.getKeyName().toUri()+"\n"):a+="\n");return a}; N.isValidName=function(a){return a.size()>=N.MIN_CERT_NAME_LENGTH&&a.get(N.KEY_COMPONENT_OFFSET).equals(N.KEY_COMPONENT)};N.extractIdentityFromCertName=function(a){if(!N.isValidName(a))throw new ec(Error("Certificate name `"+a.toUri()+"` does not follow the naming conventions"));return a.getPrefix(N.KEY_COMPONENT_OFFSET)};N.extractKeyNameFromCertName=function(a){if(!N.isValidName(a))throw new ec(Error("Certificate name `"+a.toUri()+"` does not follow the naming conventions"));return a.getPrefix(N.KEY_ID_OFFSET+ 1)};N.VERSION_OFFSET=-1;N.ISSUER_ID_OFFSET=-2;N.KEY_ID_OFFSET=-3;N.KEY_COMPONENT_OFFSET=-4;N.MIN_CERT_NAME_LENGTH=4;N.MIN_KEY_NAME_LENGTH=2;N.KEY_COMPONENT=new c.Component("KEY");var b=a.SyncPromise,R=a.Data,f=a.Log.LOG,I=a.ValidationError,Hb=a.ValidationState,Sa=a.VerificationHelpers,M=a.NdnCommon,od=function(a,b,c){Hb.call(this);this.data_=new R(a);this.successCallback_=b;this.failureCallback_=c;if(null==this.successCallback_)throw Error("The successCallback is null");if(null==this.failureCallback_)throw Error("The failureCallback is null"); };od.prototype=new Hb;od.prototype.name="DataValidationState";r.DataValidationState=od;od.prototype.fail=function(a){3=t)throw Error("Refresh period for the dynamic group must be positive");0a)){this.expireTime_=a+this.refreshPeriod_;0b)return null;var f=this.anchors_.anchorsByName_[b].certificate;return a.isPrefixOf(f.getName())?f:null}this.refresh_();b=this.anchors_.findFirstByName_(a.getName());if(0>b)return null;for(;bc)c=this.anchorsByName_.length;else if(this.anchorsByName_[c].name.equals(b)){this.anchorsByName_[c].certificate=a;return}this.anchorsByName_.splice(c,0,{name:b,certificate:a})};kb.AnchorContainer_.prototype.remove=function(a){for(var b=0;b=I.USER_MIN?"Custom error code "+this.code_:"Unrecognized error code "+this.code_;0 a.getName().size())return b.fail(new I(I.INVALID_KEY_LOCATOR,"Invalid signed Interest: name too short")),new c;var f;try{f=s.getDefaultWireFormat().decodeSignatureInfoAndValue(a.getName().get(-2).getValue().buf(),a.getName().get(-1).getValue().buf())}catch(l){return b.fail(new I(I.INVALID_KEY_LOCATOR,"Invalid signed Interest: "+l)),new c}return Ta.getKeyLocatorNameFromSignature_(f,b)};Ta.getKeyLocatorNameFromSignature_=function(a,b){if(!V.canGetFromSignature(a))return b.fail(new I(I.INVALID_KEY_LOCATOR, "KeyLocator is missing")),new c;var f=V.getFromSignature(a);return f.getType()!=ta.KEYNAME?(b.fail(new I(I.INVALID_KEY_LOCATOR,"KeyLocator type is not Name")),new c):f.getKeyName()};var Ta=a.ValidationPolicy,Qd=function(){Ta.call(this)};Qd.prototype=new Ta;Qd.prototype.name="ValidationPolicyAcceptAll";r.ValidationPolicyAcceptAll=Qd;Qd.prototype.checkPolicy=function(a,b,c){c(null,b)};var c=a.Name,R=a.Data,pc=a.CommandInterestSigner,I=a.ValidationError,Ta=a.ValidationPolicy,Vb=function $a(a,b){Ta.call(this); this.options_=void 0==b?new $a.Options:new $a.Options(b);this.container_=[];this.nowOffsetMilliseconds_=0;if(null==a)throw Error("inner policy is missing");this.setInnerPolicy(a);0>this.options_.gracePeriod_&&(this.options_.gracePeriod_=0)};Vb.prototype=new Ta;Vb.prototype.name="ValidationPolicyCommandInterest";r.ValidationPolicyCommandInterest=Vb;Vb.Options=function(a,b,c){a instanceof Vb.Options?(this.gracePeriod_=a.gracePeriod_,this.maxRecords_=a.maxRecords_,this.recordLifetime_=a.recordLifetime_): (void 0==a&&(a=12E4),void 0==b&&(b=1E3),void 0==c&&(c=36E5),this.gracePeriod_=a,this.maxRecords_=b,this.recordLifetime_=c)};Vb.prototype.checkPolicy=function(a,b,c){if(a instanceof R)this.getInnerPolicy().checkPolicy(a,b,c);else{var f=[null],l=[0];Vb.parseCommandInterest_(a,b,f,l)&&this.checkTimestamp_(b,f[0],l[0])&&this.getInnerPolicy().checkPolicy(a,b,c)}};Vb.prototype.setNowOffsetMilliseconds_=function(a){this.nowOffsetMilliseconds_=a};Vb.LastTimestampRecord=function(a,b,f){this.keyName_=new c(a); this.timestamp_=b;this.lastRefreshed_=f};Vb.prototype.cleanUp_=function(){for(var a=(new Date).getTime()+this.nowOffsetMilliseconds_-this.options_.recordLifetime_;0this.options_.maxRecords_;)this.container_.shift()};Vb.parseCommandInterest_=function(a,b,f,l){f[0]=new c;l[0]=0;var h=a.getName();if(h.size()f+this.options_.gracePeriod_)return a.fail(new I(I.POLICY_ERROR,"Timestamp is outside the grace period for key "+b.toUri())),!1;f=this.findByKeyName_(b);if(0<=f&&c<=this.container_[f].timestamp_)return a.fail(new I(I.POLICY_ERROR, "Timestamp is reordered for key "+b.toUri())),!1;var l=this;a.addSuccessCallback(function(a){l.insertNewRecord_(a,b,c)});return!0};Vb.prototype.insertNewRecord_=function(a,b,c){a=(new Date).getTime()+this.nowOffsetMilliseconds_;c=new Vb.LastTimestampRecord(b,c,a);b=this.findByKeyName_(b);0<=b&&this.container_.splice(b,1);this.container_.push(c)};Vb.prototype.findByKeyName_=function(a){for(var b=0;b"));if("file"==c.toLowerCase()){var f=a.getFirstValue("file-name"); if(null==f)throw new sa(Error("Expected "));c=hc.getRefreshPeriod_(a);this.validator_.loadAnchor(f,f,c,!1)}else if("base64"==c.toLowerCase()){c=a.getFirstValue("base64-string");if(null==c)throw new sa(Error("Expected "));c=new h(c,"base64");f=new N;try{f.wireDecode(c)}catch(l){throw new sa(Error("Cannot decode certificate from base64-string: "+l));}this.validator_.loadAnchor("",f)}else if("dir"==c.toLowerCase()){f=a.getFirstValue("dir");if(null== f)throw new sa(Error("Expected "));c=hc.getRefreshPeriod_(a);this.validator_.loadAnchor(f,f,c,!0)}else if("any"==c.toLowerCase())this.shouldBypass_=!0;else throw new sa(Error("Unsupported trust-anchor.type"));};hc.getRefreshPeriod_=function(a){var b=a.getFirstValue("refresh");if(null==b)return 1E14;a=0;b=b.match(/(\d+)([hms])/);null!=b&&(a=parseInt(b[1]),"s"!=b[2]&&(a*=60,"m"!=b[2]&&(a*=60)));return 0==a?36E5:1E3*a};var D=a.Interest,Ed=a.CertificateRequest,pa=a.PibKey,I=a.ValidationError, Ta=a.ValidationPolicy,re=function(a){Ta.call(this);this.pib_=a};re.prototype=new Ta;re.prototype.name="ValidationPolicyFromPib";r.ValidationPolicyFromPib=re;re.prototype.checkPolicy=function(a,b,c){a=Ta.getKeyLocatorName(a,b);b.isOutcomeFailed()||this.checkPolicyHelper_(a,b,c)};re.prototype.checkPolicyHelper_=function(a,b,c){var f;try{f=this.pib_.getIdentity(pa.extractIdentityFromKeyName(a))}catch(l){b.fail(new I(I.CANNOT_RETRIEVE_CERTIFICATE,"Cannot get the PIB identity for key "+a.toUri()+": "+ l));return}var h;try{h=f.getKey(a)}catch(m){b.fail(new I(I.CANNOT_RETRIEVE_CERTIFICATE,"Cannot get the PIB key "+a.toUri()+": "+m));return}var n;try{n=h.getDefaultCertificate()}catch(s){b.fail(new I(I.CANNOT_RETRIEVE_CERTIFICATE,"Cannot get the default certificate for key "+a.toUri()+": "+s));return}this.validator_.resetAnchors();this.validator_.loadAnchor("",n);c(new Ed(new D(a)),b);this.validator_.resetAnchors()};var Ed=a.CertificateRequest,I=a.ValidationError,D=a.Interest,Ta=a.ValidationPolicy, Fe=function(){Ta.call(this)};Fe.prototype=new Ta;Fe.prototype.name="ValidationPolicySimpleHierarchy";r.ValidationPolicySimpleHierarchy=Fe;Fe.prototype.checkPolicy=function(a,b,c){keyLocatorName=Ta.getKeyLocatorName(a,b);b.isOutcomeFailed()||(keyLocatorName.getPrefix(-2).isPrefixOf(a.getName())?c(new Ed(new D(keyLocatorName)),b):b.fail(new I(I.INVALID_KEY_LOCATOR,"Signing policy violation for "+a.getName().toUri()+" by "+keyLocatorName.toUri())))};var b=a.SyncPromise,I=a.ValidationError,Dd=a.CertificateFetcherOffline, Ub=a.CertificateStorage,od=a.DataValidationState,Xc=a.InterestValidationState,R=a.Data,f=a.Log.LOG,Mb=function(a,b){Ub.call(this);void 0==b&&(b=new Dd);this.policy_=a;this.certificateFetcher_=b;this.maxDepth_=25;if(null==this.policy_)throw Error("The policy is null");if(null==this.certificateFetcher_)throw Error("The certificateFetcher is null");this.policy_.setValidator(this);this.certificateFetcher_.setCertificateStorage(this)};Mb.prototype=new Ub;Mb.prototype.name="Validator";r.Validator=Mb;Mb.prototype.getPolicy= function(){return this.policy_};Mb.prototype.getFetcher=function(){return this.certificateFetcher_};Mb.prototype.setMaxDepth=function(a){this.maxDepth_=a};Mb.prototype.getMaxDepth=function(){return this.maxDepth_};Mb.prototype.validate=function(a,b,c){a instanceof R?(b=new od(a,b,c),3=this.maxDepth_)c.fail(new I(I.EXCEEDED_DEPTH_LIMIT,"Exceeded validation depth limit"));else if(c.hasSeenCertificateName(a.interest_.getName()))c.fail(new I(I.LOOP_DETECTED,"Validation loop detected for certificate `"+a.interest_.getName().toUri()+"`"));else{3=n.length?b.resolve():h.tpm_.deleteKeyPromise_(n[a],f).then(function(){return l(a+1)})}var h=this;if(a instanceof c)return this.isSecurityV1_?b.reject(new C.Error(Error("deleteIdentityPromise is not supported for security v1. Use deleteIdentity."))):this.pib_.getIdentityPromise(a, f).then(function(a){return h.deleteIdentityPromise(a,f)}).catch(function(a){return b.resolve()});var m=a.getName(),n=a.getKeys_().getKeyNames();return l(0).then(function(){return h.pib_.removeIdentityPromise_(m,f)})};C.prototype.deleteIdentity=function(a,f,l){if(a instanceof c&&this.isSecurityV1_)this.identityManager_.deleteIdentity(a,f,l);else return b.complete(f,l,this.deleteIdentityPromise(a,!f))};C.prototype.setDefaultIdentityPromise=function(a,b){return this.pib_.setDefaultIdentityPromise_(a.getName(), b)};C.prototype.setDefaultIdentity=function(a,c,f){return b.complete(c,f,this.setDefaultIdentityPromise(a,!c))};C.prototype.createKeyPromise=function(a,c,l){l="boolean"===typeof c?c:l;c="boolean"!==typeof c&&c?c:void 0;void 0==c&&(c=C.getDefaultKeyParams());var h=this,m,n;return this.tpm_.createKeyPromise_(a.getName(),c,l).then(function(a){n=a;return h.tpm_.getPublicKeyPromise(n,l)}).then(function(b){return a.addKeyPromise_(b.buf(),n,l)}).then(function(a){m=a;2a.compare(h))return!0}else if(0>a.compare(h))return!0;b=l-1}else if(null!=f){if(0=this.minSuffixComponents_)||null!=this.maxSuffixComponents_&&!(a.size()+1-this.getName().size()<=this.maxSuffixComponents_)||null!=this.getExclude()&&a.size()>this.getName().size()&& this.getExclude().matches(a.get(this.getName().size()))?!1:!0};D.prototype.matches_name=function(a){return this.matchesName(a)};D.prototype.matchesData=function(a,b){b=b||s.getDefaultWireFormat();var c=this.getName().size(),f=a.getName(),l=f.size()+1,h=null!=this.getMinSuffixComponents()?this.getMinSuffixComponents():0;if(!(c+h<=l&&(null==this.getMaxSuffixComponents()||c+this.getMaxSuffixComponents()>=l)))return!1;if(c===l)if(this.getName().get(-1).isImplicitSha256Digest()){if(!this.getName().equals(a.getFullName(b)))return!1}else return!1; else if(!this.getName().isPrefixOf(f))return!1;if(0c)if(c==l-1){if(this.getExclude().matches(a.getFullName(b).get(c)))return!1}else if(this.getExclude().matches(f.get(c)))return!1;c=this.getKeyLocator();return!c.getType()||(f=a.getSignature(),V.canGetFromSignature(f)&&c.equals(V.getFromSignature(f)))?!0:!1};D.prototype.clone=function(){return new D(this)};D.prototype.getName=function(){return this.name_.get()};D.prototype.getMinSuffixComponents=function(){return this.minSuffixComponents_}; D.prototype.getMaxSuffixComponents=function(){return this.maxSuffixComponents_};D.prototype.getCanBePrefix=function(){return 1!=this.maxSuffixComponents_};D.prototype.getKeyLocator=function(){return this.keyLocator_.get()};D.prototype.getExclude=function(){return this.exclude_.get()};D.prototype.getChildSelector=function(){return this.childSelector_};D.prototype.getMustBeFresh=function(){return this.mustBeFresh_};D.prototype.getNonce=function(){this.getNonceChangeCount_!=this.getChangeCount()&&(this.nonce_= new m,this.getNonceChangeCount_=this.getChangeCount());return this.nonce_};D.prototype.getForwardingHint=function(){return this.forwardingHint_.get()};D.prototype.hasApplicationParameters=function(){return 0a.preference_?1:this.name_.compare(a.name_)};hb.prototype.add=function(a,b){this.remove(b);for(var c=new hb.Delegation(a,b),f=0;fa)throw Error("NetworkNack other reason code must be non-negative");this.otherReasonCode_=a;return this};bb.getFirstHeader=function(a){for(var b=0;bb.length)throw new S(Error("TLV length exceeds the buffer length"));if(h==n.LpPacket_Fragment){a.setFragmentWireEncoding(new m(f.getSlice(f.getOffset(),r),c));f.seek(r);break}else if(h== n.LpPacket_Nack)s=new bb,h=f.readOptionalNonNegativeIntegerTlv(n.LpPacket_NackReason,r),0>h||h==bb.Reason.NONE?s.setReason(bb.Reason.NONE):h==bb.Reason.CONGESTION||h==bb.Reason.DUPLICATE||h==bb.Reason.NO_ROUTE?s.setReason(h):(s.setReason(bb.Reason.OTHER_CODE),s.setOtherReasonCode(h)),a.addHeaderField(s);else if(h==n.LpPacket_IncomingFaceId)h=new Ec,h.setFaceId(f.readNonNegativeInteger(s)),a.addHeaderField(h);else if(h==n.LpPacket_CongestionMark)h=new hd,h.setCongestionMark(f.readNonNegativeInteger(s)), a.addHeaderField(h);else{if(!(h>=n.LpPacket_IGNORE_MIN&&h<=n.LpPacket_IGNORE_MAX&&0==(h&3)))throw new S(Error("Did not get the expected TLV type"));f.seek(r)}f.finishNestedTlvs(r)}f.finishNestedTlvs(l)};F.prototype.encodeDelegationSet=function(a){var b=new qa(256);F.encodeDelegationSet_(a,b);return new m(b.getOutput(),!1)};F.prototype.decodeDelegationSet=function(a,b,c){null==c&&(c=!0);var f=new na(b);F.decodeDelegationSet_(a,b.length,f,c)};F.prototype.encodeEncryptedContent=function(a){var b=new qa(256), c=b.getLength();b.writeBlobTlv(n.Encrypt_EncryptedPayload,a.getPayload().buf());b.writeOptionalBlobTlv(n.Encrypt_InitialVector,a.getInitialVector().buf());b.writeNonNegativeIntegerTlv(n.Encrypt_EncryptionAlgorithm,a.getAlgorithmType());F.encodeKeyLocator(n.KeyLocator,a.getKeyLocator(),b);b.writeTypeAndLength(n.Encrypt_EncryptedContent,b.getLength()-c);return new m(b.getOutput(),!1)};F.prototype.decodeEncryptedContent=function(a,b,c){null==c&&(c=!0);b=new na(b);var f=b.readNestedTlvsStart(n.Encrypt_EncryptedContent); a.clear();F.decodeKeyLocator(n.KeyLocator,a.getKeyLocator(),b,c);a.setAlgorithmType(b.readNonNegativeIntegerTlv(n.Encrypt_EncryptionAlgorithm));a.setInitialVector(new m(b.readOptionalBlobTlv(n.Encrypt_InitialVector,f),c));a.setPayload(new m(b.readBlobTlv(n.Encrypt_EncryptedPayload),c));b.finishNestedTlvs(f)};F.prototype.encodeEncryptedContentV2=function(a){var b=new qa(256),c=b.getLength();a.getKeyLocator().getType()==ta.KEYNAME&&F.encodeName(a.getKeyLocator().getKeyName(),b);b.writeOptionalBlobTlv(n.Encrypt_EncryptedPayloadKey, a.getPayloadKey().buf());b.writeOptionalBlobTlv(n.Encrypt_InitialVector,a.getInitialVector().buf());b.writeBlobTlv(n.Encrypt_EncryptedPayload,a.getPayload().buf());b.writeTypeAndLength(n.Encrypt_EncryptedContent,b.getLength()-c);return new m(b.getOutput(),!1)};F.prototype.decodeEncryptedContentV2=function(a,b,c){null==c&&(c=!0);b=new na(b);var f=b.readNestedTlvsStart(n.Encrypt_EncryptedContent);a.clear();a.setPayload(new m(b.readBlobTlv(n.Encrypt_EncryptedPayload),c));a.setInitialVector(new m(b.readOptionalBlobTlv(n.Encrypt_InitialVector, f),c));a.setPayloadKey(new m(b.readOptionalBlobTlv(n.Encrypt_EncryptedPayloadKey,f),c));b.peekType(n.Name,f)&&(F.decodeName(a.getKeyLocator().getKeyName(),b,c),a.getKeyLocator().setType(ta.KEYNAME));b.finishNestedTlvs(f)};F.get=function(){null===F.instance&&(F.instance=new F);return F.instance};F.encodeNameComponent=function(a,b){var c;c=a.getType()===jb.OTHER_CODE?a.getOtherTypeCode():a.getType();b.writeBlobTlv(c,a.getValue().buf())};F.decodeNameComponent=function(a,b){null==b&&(b=!0);var f=a.getOffset(), l=a.readVarNumber();a.seek(f);f=new m(a.readBlobTlv(l),b);return l===n.ImplicitSha256DigestComponent?c.Component.fromImplicitSha256Digest(f):l===n.ParametersSha256DigestComponent?c.Component.fromParametersSha256Digest(f):l===n.NameComponent?new c.Component(f):new c.Component(f,jb.OTHER_CODE,l)};F.encodeName=function(a,b){for(var c=b.getLength(),f,l=a.size()-1;0<=l;--l)F.encodeNameComponent(a.get(l),b),l==a.size()-1&&(f=b.getLength());l=b.getLength();b.writeTypeAndLength(n.Name,b.getLength()-c);c= b.getLength()-l;f=0==a.size()?c:b.getLength()-f;return{signedPortionBeginOffset:c,signedPortionEndOffset:f}};F.decodeName=function(a,b,c){a.clear();for(var f=b.readNestedTlvsStart(n.Name),l=b.getOffset(),h=l;b.getOffset()l||l===Da.BLOB?a.setType(Da.BLOB):l===Da.LINK||l===Da.KEY||l===Da.NACK?a.setType(l):(a.setType(Da.OTHER_CODE),a.setOtherTypeCode(l));a.setFreshnessPeriod(b.readOptionalNonNegativeIntegerTlv(n.FreshnessPeriod,f));b.peekType(n.FinalBlockId, f)?(l=b.readNestedTlvsStart(n.FinalBlockId),a.setFinalBlockId(F.decodeNameComponent(b,c)),b.finishNestedTlvs(l)):a.setFinalBlockId(null);b.finishNestedTlvs(f)};F.encodeControlParameters=function(a,b){var c=b.getLength();b.writeOptionalNonNegativeIntegerTlv(n.ControlParameters_ExpirationPeriod,a.getExpirationPeriod());if(0a.getNonce().size()){var f=h(4);a.getNonce().buf().copy(f);for(var l=a.getNonce().size();4>l;++l)f[l]=W.randomBytes(1)[0];b.writeBlobTlv(n.Nonce,f)}else 4==a.getNonce().size()?b.writeBlobTlv(n.Nonce, a.getNonce().buf()):b.writeBlobTlv(n.Nonce,a.getNonce().buf().slice(0,4));if(0a.getNonce().size()){l=h(4);a.getNonce().buf().copy(l);for(var f=a.getNonce().size();4>f;++f)l[f]=W.randomBytes(1)[0];b.writeBlobTlv(n.Nonce, l)}else 4==a.getNonce().size()?b.writeBlobTlv(n.Nonce,a.getNonce().buf()):b.writeBlobTlv(n.Nonce,a.getNonce().buf().slice(0,4));F.encodeSelectors(a,b);l=F.encodeName(a.getName(),b);a=b.getLength()-l.signedPortionBeginOffset;l=b.getLength()-l.signedPortionEndOffset;b.writeTypeAndLength(n.Interest,b.getLength()-c);var c=b.getLength()-a,l=b.getLength()-l;return{encoding:new m(b.getOutput(),!1),signedPortionBeginOffset:c,signedPortionEndOffset:l}};ic.get=function(){null===ic.instance&&(ic.instance=new ic); return ic.instance};var ic=a.Tlv0_2WireFormat,xc=function(){ic.call(this)};xc.prototype=new ic;xc.prototype.name="Tlv0_1_1WireFormat";r.Tlv0_1_1WireFormat=xc;xc.instance=null;xc.get=function(){null===xc.instance&&(xc.instance=new xc);return xc.instance};var s=a.WireFormat,xc=a.Tlv0_1_1WireFormat,pd=function(){xc.call(this)};pd.prototype=new xc;pd.prototype.name="Tlv0_1WireFormat";r.Tlv0_1WireFormat=pd;pd.instance=null;pd.get=function(){null===pd.instance&&(pd.instance=new pd);return pd.instance}; s=a.WireFormat;F=a.Tlv0_3WireFormat;gb=function(){F.call(this)};gb.prototype=new F;gb.prototype.name="TlvWireFormat";r.TlvWireFormat=gb;gb.instance=null;gb.get=function(){null===gb.instance&&(gb.instance=new gb);return gb.instance};s.setDefaultWireFormat(gb.get());var L=a.DataUtils,ta=a.KeyLocatorType,D=a.Interest,R=a.Data,Ja=a.Sha256WithRsaSignature,Xa=a.Sha256WithEcdsaSignature,pb=a.HmacWithSha256Signature,xb=a.DigestSha256Signature,Da=a.ContentType,s=a.WireFormat,Rd=function(){};r.EncodingUtils= Rd;Rd.encodeToHexInterest=function(a,b){b=b||s.getDefaultWireFormat();return L.toHex(a.wireEncode(b).buf())};Rd.encodeToHexData=function(a,b){b=b||s.getDefaultWireFormat();return L.toHex(a.wireEncode(b).buf())};Rd.decodeHexInterest=function(a,b){b=b||s.getDefaultWireFormat();var c=new D;c.wireDecode(L.toNumbers(a),b);return c};Rd.decodeHexData=function(a,b){b=b||s.getDefaultWireFormat();var c=new R;c.wireDecode(L.toNumbers(a),b);return c};Rd.decodeSubjectPublicKeyInfo=function(a){a=L.toHex(a).toLowerCase(); a=_x509_getPublicKeyHexArrayFromCertHex(a,_x509_getSubjectPublicKeyPosFromCertHex(a,0));var b=new z;b.setPublic(a[0],a[1]);return b};Rd.dataToHtml=function(a){function b(a){a=a.replace(/&/g,"&");a=a.replace(/"}if(-1==a)return"NO CONTENT FOUND";if(-2==a)return"CONTENT NAME IS EMPTY";var c="";b("name: "+a.getName().toUri());0"); a.getMetaInfo().getType()!=Da.BLOB&&(a.getMetaInfo().getType()==Da.KEY?b("metaInfo.type: KEY"):a.getMetaInfo().getType()==Da.LINK?b("metaInfo.type: LINK"):a.getMetaInfo().getType()==Da.NACK?b("metaInfo.type: NACK"):a.getMetaInfo().getType()==Da.OTHER_CODE&&b("metaInfo.type: other code "+a.getMetaInfo().getOtherTypeCode()));b("metaInfo.freshnessPeriod (milliseconds): "+(0<=a.getMetaInfo().getFreshnessPeriod()?""+a.getMetaInfo().getFreshnessPeriod():""));b("metaInfo.finalBlockId: "+(0"));var f=null,l=a.getSignature();l instanceof Ja?(l=a.getSignature(),b("Sha256WithRsa signature.signature: "+(0")),f=l.getKeyLocator()):l instanceof Xa?(l=a.getSignature(),b("Sha256WithEcdsa signature.signature: "+(0")),f=l.getKeyLocator()):l instanceof pb?(l=a.getSignature(),b("HmacWithSha256 signature.signature: "+(0")),f=l.getKeyLocator()):l instanceof xb&&(l=a.getSignature(),b("DigestSha256 signature.signature: "+(0")));null!==f&&(null==f.getType()?b("signature.keyLocator: "):f.getType()==ta.KEY_LOCATOR_DIGEST?b("signature.keyLocator: KeyLocatorDigest: "+f.getKeyData().toHex()):f.getType()==ta.KEYNAME?b("signature.keyLocator: KeyName: "+f.getKeyName().toUri()):b("signature.keyLocator: ")); return c};var c=a.Name,R=a.Data,ae=function(){this.cache_=[]};r.InMemoryStorageRetaining=ae;ae.prototype.insert=function(a){this.cache_[a.getFullName().toUri()]=new R(a)};ae.prototype.find=function(a){for(var b in this.cache_)if(a.getName().isPrefixOf(new c(b)))return this.cache_[b]};ae.prototype.size=function(){return Object.keys(this.cache_).length};var W=a,m=a.Blob,Sd=a.DecryptKey,be=a.EncryptKey,fa=a.EncryptAlgorithmType,Gb=a.UseSubtleCrypto,b=a.SyncPromise,qb=function(){};r.AesAlgorithm=qb;qb.generateKey= function(a){a=W.randomBytes(a.getKeySize()/8);return new Sd(new m(a,!1))};qb.deriveEncryptKey=function(a){return new be(a)};qb.decryptPromise=function(a,c,f,l){if(Gb()&&!l&&f.getAlgorithmType()!=fa.AesEcb)return f.getAlgorithmType()==fa.AesCbc?crypto.subtle.importKey("raw",a.buf(),{name:"AES-CBC"},!1,["encrypt","decrypt"]).then(function(a){return crypto.subtle.decrypt({name:"AES-CBC",iv:f.getInitialVector().buf()},a,c.buf())}).then(function(a){return Promise.resolve(new m(new Uint8Array(a),!1))}): Promise.reject(Error("unsupported encryption mode"));if(f.getAlgorithmType()==fa.AesEcb)try{var n=W.createDecipheriv(32==a.size()?"aes-256-ecb":"aes-128-ecb",a.buf(),"");return b.resolve(new m(h.concat([n.update(c.buf()),n.final()]),!1))}catch(s){return b.reject(s)}else if(f.getAlgorithmType()==fa.AesCbc)try{return n=W.createDecipheriv(32==a.size()?"aes-256-cbc":"aes-128-cbc",a.buf(),f.getInitialVector().buf()),b.resolve(new m(h.concat([n.update(c.buf()),n.final()]),!1))}catch(r){return b.reject(r)}else return b.reject(Error("unsupported encryption mode"))}; qb.decrypt=function(a,c,f){return b.getValue(this.decryptPromise(a,c,f,!0))};qb.encryptPromise=function(a,c,f,l){return f.getAlgorithmType()==fa.AesCbc&&f.getInitialVector().size()!=qb.BLOCK_SIZE?b.reject(Error("incorrect initial vector size")):Gb()&&!l&&f.getAlgorithmType()!=fa.AesEcb?f.getAlgorithmType()==fa.AesCbc?crypto.subtle.importKey("raw",a.buf(),{name:"AES-CBC"},!1,["encrypt","decrypt"]).then(function(a){return crypto.subtle.encrypt({name:"AES-CBC",iv:f.getInitialVector().buf()},a,c.buf())}).then(function(a){return Promise.resolve(new m(new Uint8Array(a), !1))}):Promise.reject(Error("unsupported encryption mode")):f.getAlgorithmType()==fa.AesEcb?(a=W.createCipheriv(32==a.size()?"aes-256-ecb":"aes-128-ecb",a.buf(),""),b.resolve(new m(h.concat([a.update(c.buf()),a.final()]),!1))):f.getAlgorithmType()==fa.AesCbc?(a=W.createCipheriv(32==a.size()?"aes-256-cbc":"aes-128-cbc",a.buf(),f.getInitialVector().buf()),b.resolve(new m(h.concat([a.update(c.buf()),a.final()]),!1))):b.reject(Error("unsupported encryption mode"))};qb.encrypt=function(a,c,f){return b.getValue(this.encryptPromise(a, c,f,!0))};qb.BLOCK_SIZE=16;W=a;m=a.Blob;fa=function(){};r.EncryptAlgorithmType=fa;fa.AesEcb=0;fa.AesCbc=1;fa.RsaPkcs=2;fa.RsaOaep=3;var Fb=function(a,b){this.algorithmType_=a;if(null!=b&&0a.size()||!a.get(-2).equals(Ca.NAME_COMPONENT_KEK)? (b(xa.ErrorCode.KekInvalidName,"Invalid KEK name ["+a.toUri()+"]"),null):a.getPrefix(-2).append(Ca.NAME_COMPONENT_KDK).append(a.get(-1))};Ib.extractKdkInfoFromCkName_=function(a,b,c,f,l,h){if(a.size()=h.length?b.resolve():n.createDKeyDataPromise_(G,x,h[a].keyName,s,h[a].publicKey,l).then(function(b){m.push(b);return c(a+1)})}m.push(a);return c(0)}).then(function(){return b.resolve(m)})})};tb.prototype.addSchedulePromise=function(a,b,c){return this.database_.addSchedulePromise(a,b,c)};tb.prototype.deleteSchedulePromise= function(a,b){return this.database_.deleteSchedulePromise(a,b)};tb.prototype.updateSchedulePromise=function(a,b,c){return this.database_.updateSchedulePromise(a,b,c)};tb.prototype.addMemberPromise=function(a,b,c){b=new Na(b);return this.database_.addMemberPromise(a,b.getPublicKeyName(),b.getPublicKeyInfo().getKeyDer(),c)};tb.prototype.removeMemberPromise=function(a,b){return this.database_.deleteMemberPromise(a,b)};tb.prototype.updateMemberSchedulePromise=function(a,b,c){return this.database_.updateMemberSchedulePromise(a, b,c)};tb.prototype.cleanEKeysPromise=function(a){return this.database_.cleanEKeysPromise(a)};tb.prototype.calculateIntervalPromise_=function(a,c,f){var l=new sb,h=new sb;c.splice(0,c.length);var m=this;return this.database_.listAllScheduleNamesPromise(f).then(function(n){function s(r){if(r>=n.length)return b.resolve();var G=n[r];return m.database_.getSchedulePromise(G,f).then(function(b){b=b.getCoveringInterval(a);var n=b.interval;if(b.isPositive)return l.isValid()||(l=n),l.intersectWith(n),m.database_.getScheduleMembersPromise(G, f).then(function(a){for(var b=0;b=a.endTime_||this.endTime_<=a.startTime_)return this.startTime_=this.endTime_,this;this.startTime_<=a.startTime_&&(this.startTime_=a.startTime_);this.endTime_>a.endTime_&&(this.endTime_=a.endTime_);return this};sb.prototype.unionWith=function(a){if(!this.isValid_)throw Error("Interval.intersectWith: This Interval is invalid");if(!a.isValid_)throw Error("Interval.intersectWith: The other Interval is invalid");if(this.isEmpty())return this.startTime_= a.startTime_,this.endTime_=a.endTime_,this;if(a.isEmpty())return this;if(this.startTime_>=a.endTime_||this.endTime_<=a.startTime_)throw Error("Interval.unionWith: The two intervals do not have an intersection");this.startTime_>a.startTime_&&(this.startTime_=a.startTime_);this.endTime_=G.endTimeSlot?(h.repeatAttempts[r]=0, s.sendKeyInterest_((new D(Ab.keyName)).setExclude(n).setChildSelector(1),a,b,l)):(Ab=new c(Ab.keyName),Ab.append(ha.toIsoString(G.beginTimeSlot)),Ab.append(ha.toIsoString(G.endTimeSlot)),s.encryptContentKeyPromise_(G.keyBits,Ab,a,b,l))}null!=f&&f(m)}))})};la.prototype.produce=function(a,b,f,l,h){h||(h=la.defaultOnError);var m=this;this.createContentKey(b,null,function(n){m.database_.getContentKeyPromise(b).then(function(l){var h=new c(m.namespace_);h.append(ha.toIsoString(b));a.setName(h);h=new Fb(fa.AesCbc, 16);return Fa.encryptData(a,f,n,l,h)}).then(function(){return m.keyChain_.signPromise(a)}).then(function(){try{l()}catch(a){console.log("Error in onComplete: "+M.getErrorWithStackTrace(a))}},function(a){try{h(xa.ErrorCode.General,""+a)}catch(b){console.log("Error in onError: "+M.getErrorWithStackTrace(b))}})},h)};la.defaultOnError=function(a,b){};la.KeyInfo_=function(){this.endTimeSlot=this.beginTimeSlot=0;this.keyBits=null};la.KeyRequest_=function(a){this.interestCount=a;this.repeatAttempts={};this.encryptedKeys= []};la.getRoundedTimeSlot_=function(a){return Math.round(36E5*Math.floor(Math.round(a)/36E5))};la.prototype.sendKeyInterest_=function(a,b,c,f){var l=this;0!==this.keyRetrievalLink_.getDelegations().size()&&(a=new D(a),a.setLinkWireEncoding(this.keyRetrievalLink_.wireEncode()));this.face_.expressInterest(a,function(a,h){l.handleCoveringKey_(a,h,b,c,f)},function(a){l.handleTimeout_(a,b,c,f)},function(a,h){l.handleNetworkNack_(a,h,b,c,f)})};la.prototype.handleTimeout_=function(a,b,c,f){var l=Math.round(b), l=this.keyRequests_[l],h=a.getName().toUri();l.repeatAttempts[h]=G)a=new Wa(a.getExclude()),la.excludeBefore(a,s.get(la.START_TIME_STAMP_INDEX)),h.repeatAttempts[n]=0,this.sendKeyInterest_((new D(m)).setExclude(a).setChildSelector(1),c,f,l);else{var x=b.getContent(),P=this;this.encryptContentKeyPromise_(x, s,c,f,l).then(function(a){a&&(a=P.eKeyInfo_[n].keyInfo,a.beginTimeSlot=r,a.endTimeSlot=G,a.keyBits=x)})}};la.prototype.encryptContentKeyPromise_=function(a,f,l,h,m){var n=Math.round(l),s=this.keyRequests_[n],r=new c(this.namespace_);r.append(Fa.NAME_COMPONENT_C_KEY);r.append(ha.toIsoString(la.getRoundedTimeSlot_(l)));var G,x=this;return this.database_.getContentKeyPromise(l).then(function(b){G=new R;G.setName(r);var c=new Fb(fa.RsaOaep);return Fa.encryptDataPromise(G,b,f,a,c)}).then(function(){return b.resolve(!0)}, function(a){try{m(xa.ErrorCode.EncryptionFailure,"encryptData failed: "+a)}catch(c){console.log("Error in onError: "+M.getErrorWithStackTrace(c))}return b.resolve(!1)}).then(function(a){return a?x.keyChain_.signPromise(G).then(function(){s.encryptedKeys.push(G);x.updateKeyRequest_(s,n,h);return b.resolve(!0)}):b.resolve(!1)})};la.prototype.getEKeyInfoSize_=function(){var a=0;for(key in this.eKeyInfo_)this.eKeyInfo_.hasOwnProperty(key)&&++a;return a};la.ExcludeEntry=function(a,b){this.component_=a; this.anyFollowsComponent_=b};la.getExcludeEntries=function(a){for(var b=[],f=0;f=a[c].component_.compare(b));)--c;return c};la.excludeAfter=function(a,b){var c=la.getExcludeEntries(a),f;f=la.findEntryBeforeOrAt(c,b);if(0>f)c.splice(0,0,new la.ExcludeEntry(b,!0)),f=0;else{var l=c[f];l.anyFollowsComponent_||(l.component_.equals(b)?l.anyFollowsComponent_=!0:(c.splice(f+1,0,new la.ExcludeEntry(b,!0)),f+=1))}f+=1;c.splice(f,c.length-f);la.setExcludeEntries(a,c)};la.excludeBefore=function(a,b){la.excludeRange(a,new c.Component,b)};la.excludeRange= function(a,b,c){if(0<=b.compare(c)){if(0==b.compare(c))throw Error("excludeRange: from == to. To exclude a single component, sue excludeOne.");throw Error("excludeRange: from must be less than to. Invalid range: ["+b.toEscapedString()+", "+c.toEscapedString()+"]");}var f=la.getExcludeEntries(a),l=la.findEntryBeforeOrAt(f,b);if(0>l)f.splice(0,0,new la.ExcludeEntry(b,!0)),b=0;else{var h=f[l];h.anyFollowsComponent_?b=l:h.component_.equals(b)?(h.anyFollowsComponent_=!0,b=l):(f.splice(l+1,0,new la.ExcludeEntry(b, !0)),b=l+1)}l=la.findEntryBeforeOrAt(f,c);h=f[l];l==b?f.splice(b+1,0,new la.ExcludeEntry(c,!1)):(h.anyFollowsComponent_?c=l+1:h.component_.equals(c)?c=l:(f.splice(l+1,0,new la.ExcludeEntry(c,!1)),c=l+1),b+=1,f.splice(b,c-b));la.setExcludeEntries(a,f)};la.START_TIME_STAMP_INDEX=-2;la.END_TIME_STAMP_INDEX=-1;la.NO_LINK=new Eb;var sb=a.Interval,Ia=function Cd(a,b,c,f,l,h){if("object"===typeof a&&a instanceof Cd)repetitiveInterval=a,this.startDate_=repetitiveInterval.startDate_,this.endDate_=repetitiveInterval.endDate_, this.intervalStartHour_=repetitiveInterval.intervalStartHour_,this.intervalEndHour_=repetitiveInterval.intervalEndHour_,this.nRepeats_=repetitiveInterval.nRepeats_,this.repeatUnit_=repetitiveInterval.repeatUnit_;else if("number"===typeof a){void 0==l&&(l=0);void 0==h&&(h=Cd.RepeatUnit.NONE);this.startDate_=Cd.toDateOnlyMilliseconds_(a);this.endDate_=Cd.toDateOnlyMilliseconds_(b);this.intervalStartHour_=Math.round(c);this.intervalEndHour_=Math.round(f);this.nRepeats_=Math.round(l);this.repeatUnit_= h;if(!(this.intervalStartHour_=this.intervalEndHour_))throw Error("ReptitiveInterval: intervalEndHour must be from 1 to 24");if(this.repeatUnit_== Cd.RepeatUnit.NONE&&this.startDate_!=this.endDate_)throw Error("ReptitiveInterval: With RepeatUnit.NONE, startDate must equal endDate");}else this.startDate_=-Number.MAX_VALUE,this.endDate_=-Number.MAX_VALUE,this.intervalStartHour_=0,this.intervalEndHour_=24,this.nRepeats_=0,this.repeatUnit_=Cd.RepeatUnit.NONE};r.RepetitiveInterval=Ia;Ia.RepeatUnit={NONE:0,DAY:1,MONTH:2,YEAR:3};Ia.prototype.getInterval=function(a){var b,c;this.hasIntervalOnDate_(a)?(b=Ia.toDateOnlyMilliseconds_(a)+this.intervalStartHour_* Ia.MILLISECONDS_IN_HOUR,c=Ia.toDateOnlyMilliseconds_(a)+this.intervalEndHour_*Ia.MILLISECONDS_IN_HOUR,ac?(b=c,c=Ia.toDateOnlyMilliseconds_(a)+Ia.MILLISECONDS_IN_DAY,a=!1):a=!0):(b=Ia.toDateOnlyMilliseconds_(a),c=Ia.toDateOnlyMilliseconds_(a)+24*Ia.MILLISECONDS_IN_HOUR,a=!1);return{isPositive:a,interval:new sb(b,c)}};Ia.prototype.compare=function(a){return this.startDate_a.startDate_?1:this.endDate_ a.endDate_?1:this.intervalStartHour_a.intervalStartHour_?1:this.intervalEndHour_a.intervalEndHour_?1:this.nRepeats_a.nRepeats_?1:this.repeatUnit_a.repeatUnit_?1:0};Ia.prototype.getStartDate=function(){return this.startDate_};Ia.prototype.getEndDate=function(){return this.endDate_};Ia.prototype.getIntervalStartHour=function(){return this.intervalStartHour_}; Ia.prototype.getIntervalEndHour=function(){return this.intervalEndHour_};Ia.prototype.getNRepeats=function(){return this.nRepeats_};Ia.prototype.getRepeatUnit=function(){return this.repeatUnit_};Ia.prototype.hasIntervalOnDate_=function(a){a=Ia.toDateOnlyMilliseconds_(a);if(athis.endDate_)return!1;if(this.repeatUnit_==Ia.RepeatUnit.NONE)return!0;if(this.repeatUnit_==Ia.RepeatUnit.DAY){if(0==(a-this.startDate_)/Ia.MILLISECONDS_IN_DAY%this.nRepeats_)return!0}else{a=new Date(a);var b= new Date(this.startDate_);if(this.repeatUnit_==Ia.RepeatUnit.MONTH&&a.getUTCDate()==b.getUTCDate()){if(0==(12*(a.getUTCFullYear()-b.getUTCFullYear())+a.getUTCMonth()-b.getUTCMonth())%this.nRepeats_)return!0}else if(this.repeatUnit_==Ia.RepeatUnit.YEAR&&a.getUTCDate()==b.getUTCDate()&&a.getUTCMonth()==b.getUTCMonth()&&0==(a.getUTCFullYear()-b.getUTCFullYear())%this.nRepeats_)return!0}return!1};Ia.toDateOnlyMilliseconds_=function(a){a=Math.round(a);return a-=a%Ia.MILLISECONDS_IN_DAY};Ia.MILLISECONDS_IN_HOUR= 36E5;Ia.MILLISECONDS_IN_DAY=864E5;sb=a.Interval;Ia=a.RepetitiveInterval;n=a.Tlv;qa=a.TlvEncoder;na=a.TlvDecoder;m=a.Blob;ha=function Nd(a){"object"===typeof a&&a instanceof Nd?(this.whiteIntervalList_=a.whiteIntervalList_.slice(0),this.blackIntervalList_=a.blackIntervalList_.slice(0)):(this.whiteIntervalList_=[],this.blackIntervalList_=[])};r.Schedule=ha;ha.prototype.addWhiteInterval=function(a){ha.sortedSetAdd_(this.whiteIntervalList_,a);return this};ha.prototype.addBlackInterval=function(a){ha.sortedSetAdd_(this.blackIntervalList_, a);return this};ha.prototype.getCoveringInterval=function(a){var b=new sb(!0),c=new sb(!0),f=new sb,l=new sb;ha.calculateIntervalResult_(this.blackIntervalList_,a,b,f);if(!b.isEmpty())return{isPositive:!1,interval:b};ha.calculateIntervalResult_(this.whiteIntervalList_,a,c,l);return c.isEmpty()&&!l.isValid()?(a=Ia.toDateOnlyMilliseconds_(a),{isPositive:!1,interval:new sb(a,a+Ia.MILLISECONDS_IN_DAY)}):c.isEmpty()?{isPositive:!1,interval:l}:f.isValid()?{isPositive:!0,interval:c.intersectWith(f)}:{isPositive:!0, interval:c}};ha.prototype.wireEncode=function(){for(var a=new qa(256),b=a.getLength(),c=a.getLength(),f=this.blackIntervalList_.length-1;0<=f;f--)ha.encodeRepetitiveInterval_(this.blackIntervalList_[f],a);a.writeTypeAndLength(n.Encrypt_BlackIntervalList,a.getLength()-c);c=a.getLength();for(f=this.whiteIntervalList_.length-1;0<=f;f--)ha.encodeRepetitiveInterval_(this.whiteIntervalList_[f],a);a.writeTypeAndLength(n.Encrypt_WhiteIntervalList,a.getLength()-c);a.writeTypeAndLength(n.Encrypt_Schedule,a.getLength()- b);return new m(a.getOutput(),!1)};ha.prototype.wireDecode=function(a){a="object"===typeof a&&a instanceof m?a.buf():a;a=new na(a);var b=a.readNestedTlvsStart(n.Encrypt_Schedule);this.whiteIntervalList_=[];for(var c=a.readNestedTlvsStart(n.Encrypt_WhiteIntervalList);a.getOffset()f))break;++c}a.splice(c,0,b)};ha.encodeRepetitiveInterval_=function(a,b){var c=b.getLength();b.writeNonNegativeIntegerTlv(n.Encrypt_RepeatUnit,a.getRepeatUnit());b.writeNonNegativeIntegerTlv(n.Encrypt_NRepeats,a.getNRepeats());b.writeNonNegativeIntegerTlv(n.Encrypt_IntervalEndHour,a.getIntervalEndHour());b.writeNonNegativeIntegerTlv(n.Encrypt_IntervalStartHour, a.getIntervalStartHour());b.writeBlobTlv(n.Encrypt_EndDate,(new m(ha.toIsoString(a.getEndDate()))).buf());b.writeBlobTlv(n.Encrypt_StartDate,(new m(ha.toIsoString(a.getStartDate()))).buf());b.writeTypeAndLength(n.Encrypt_RepetitiveInterval,b.getLength()-c)};ha.decodeRepetitiveInterval_=function(a){var b=a.readNestedTlvsStart(n.Encrypt_RepetitiveInterval),c=ha.fromIsoString((new m(a.readBlobTlv(n.Encrypt_StartDate),!0)).toString()),f=ha.fromIsoString((new m(a.readBlobTlv(n.Encrypt_EndDate),!0)).toString()), l=a.readNonNegativeIntegerTlv(n.Encrypt_IntervalStartHour),h=a.readNonNegativeIntegerTlv(n.Encrypt_IntervalEndHour),s=a.readNonNegativeIntegerTlv(n.Encrypt_NRepeats),r=a.readNonNegativeIntegerTlv(n.Encrypt_RepeatUnit);a.finishNestedTlvs(b);return new Ia(c,f,l,h,s,r)};ha.calculateIntervalResult_=function(a,b,c,f){for(var l=0;lc?-1:this.digest_tree.get(c).getSequenceNo()};Ka.prototype.publishNextSequenceNo=function(a){a=a instanceof m?a:new m(a,!0); this.usrseq++;var b={name:this.applicationDataPrefixUri,type:"UPDATE",seqno:{seq:this.usrseq,session:this.session}};!a.isNull()&&0c;c++)b[c]=a%256,a=Math.floor(a/256);return b};ub.Node.prototype.recomputeDigest=function(){var a=W.createHash("sha256");a.update(this.Int32ToBuffer(this.seqno_session));a.update(this.Int32ToBuffer(this.seqno_seq));var a=a.digest(),b=W.createHash("sha256");b.update(this.dataPrefix);var b=b.digest(),c=W.createHash("sha256"); c.update(b);c.update(a);this.digest=c.digest("hex")};ub.Node.Compare=function(a,b){return a.dataPrefix!=b.dataPrefix?a.dataPrefixthis.digestnode[c+1].getDataPrefix()&&(a=this.digestnode[c],this.digestnode[c]=this.digestnode[c+1],this.digestnode[c+1]=a)};ub.prototype.sortNodes=function(a,b){return a.getDataPrefix()==b.getDataPrefix()&&a.getSessionNo()==b.getSessionNo()?0:a.getDataPrefix()>b.getDataPrefix()||a.getDataPrefix()==b.getDataPrefix()&&a.getSessionNo()>b.getSessionNo()?1:-1};ub.prototype.find=function(a,b){for(var c=0;ca.getInterestLifetimeMilliseconds())&&a.setInterestLifetimeMilliseconds(1E3);l&&l()})};var f=a.Log.LOG,yc=function(){this.table_=[]};r.InterestFilterTable=yc;yc.Entry=function(a,b,c,f){this.interestFilterId_=a;this.filter_=b;this.onInterest_=c;this.face_=f};yc.Entry.prototype.getInterestFilterId=function(){return this.interestFilterId_};yc.Entry.prototype.getFilter=function(){return this.filter_};yc.Entry.prototype.getOnInterest= function(){return this.onInterest_};yc.Entry.prototype.getFace=function(){return this.face_};yc.prototype.setInterestFilter=function(a,b,c,f){this.table_.push(new yc.Entry(a,b,c,f))};yc.prototype.getMatchedFilters=function(a,b){for(var c=0;cthis.removeRequests_.indexOf(a)&&this.removeRequests_.push(a)}};var f=a.Log.LOG,Zc=function(a){this.interestFilterTable_=a;this.table_=[];this.removeRequests_=[]};r.RegisteredPrefixTable=Zc;Zc.prototype.add=function(a,b,c){var f=this.removeRequests_.indexOf(a);if(0<=f)return this.removeRequests_.splice(f,1),!1;this.table_.push(new Zc._Entry(a,b,c));return!0};Zc.prototype.removeRegisteredPrefix= function(a){for(var b=0,c=this.table_.length-1;0<=c;--c){var l=this.table_[c];l.getRegisteredPrefixId()==a&&(++b,0this.removeRequests_.indexOf(a)&&this.removeRequests_.push(a)};Zc._Entry=function(a,b,c){this.registeredPrefixId_=a;this.prefix_=b;this.relatedInterestFilterId_= c};Zc._Entry.prototype.getRegisteredPrefixId=function(){return this.registeredPrefixId_};Zc._Entry.prototype.getPrefix=function(){return this.prefix_};Zc._Entry.prototype.getRelatedInterestFilterId=function(){return this.relatedInterestFilterId_};hd=function(){this.congestionMark_=0};r.CongestionMark=hd;hd.prototype.getCongestionMark=function(){return this.congestionMark_};hd.prototype.setCongestionMark=function(a){this.congestionMark_=a};hd.getFirstHeader=function(a){for(var b=0;baa.getMaxNdnPacketSize())throw Error("The encoded interest size exceeds the maximum limit getMaxNdnPacketSize()");this.transport.send(a.buf());this.interestLoopbackEnabled_&&dispatchInterest(b)}};aa.prototype.removePendingInterest=function(a){this.pendingInterestTable_.removePendingInterest(a)};aa.prototype.setCommandSigningInfo=function(a,b){this.commandKeyChain=a;this.commandCertificateName=new c(b)};aa.prototype.setCommandCertificateName= function(a){this.commandCertificateName=new c(a)};aa.prototype.makeCommandInterest=function(a,b,c){c="function"===typeof b?b:c;b="function"!==typeof b&&b?b:s.getDefaultWireFormat();this.nodeMakeCommandInterest(a,this.commandKeyChain,this.commandCertificateName,b,c)};aa.prototype.nodeMakeCommandInterest=function(a,b,c,f,l){this.commandInterestGenerator.generate(a,b,c,f,l)};aa.prototype.registerPrefix=function(a,b,c,f,l,h){var m=f,n=l,r=h;f="function"===typeof m?m:null;l=m instanceof va?m:n instanceof va?n:new va;h=m instanceof s?m:n instanceof s?n:r instanceof s?r:s.getDefaultWireFormat();c||(c=function(){});var G=this.getNextEntryId(),x=this,m=function(){x.nfdRegisterPrefix(G,a,b,l,c,f,x.commandKeyChain,x.commandCertificateName,h)};null==this.connectionInfo?null==this.getConnectionInfo?console.log("ERROR: connectionInfo is NOT SET"):this.connectAndExecute(m):m();return G};aa.getMaxNdnPacketSize=function(){return M.MAX_NDN_PACKET_SIZE};aa.RegisterResponse=function(a,b,c,f,l,h){this.prefix=a;this.onRegisterFailed= b;this.onRegisterSuccess=c;this.registeredPrefixId=f;this.parent=l;this.onInterest=h};aa.RegisterResponse.prototype.onData=function(a,b){var c=new wc;try{c.wireDecode(b.getContent(),gb.get())}catch(l){0aa.getMaxNdnPacketSize())throw Error("The encoded Data packet size exceeds the maximum limit getMaxNdnPacketSize()");this.transport.send(c.buf())}};aa.prototype.putNack=function(a,b){var c=aa.encodeLpNack_(a,b);if(c.size()>aa.getMaxNdnPacketSize())throw Error("The encoded Nack packet size exceeds the maximum limit getMaxNdnPacketSize()");this.transport.send(c.buf())};aa.prototype.send=function(a){if(a.length>aa.getMaxNdnPacketSize())throw Error("The encoded packet size exceeds the maximum limit getMaxNdnPacketSize()"); this.transport.send(a)};aa.prototype.isLocal=function(a,b){null==this.connectionInfo?a(!1):this.transport.isLocal(this.connectionInfo,a,b)};aa.prototype.onReceivedElement=function(a){3h}).forEach(function(f){var h=da,n=f._cfg.dbschema;Oc(h,c);Oc(n,c);da=L._dbSchema=n;h=a(h,n);h.add.forEach(function(a){x.push(function(b,c){r(b,a[0],a[1].primKey,a[1].indexes);c()})});h.change.forEach(function(a){if(a.recreate)throw new Ma("Not yet support for changing primary key");x.push(function(b,c){var f=b.objectStore(a.name);a.add.forEach(function(a){Yb(f,a)});a.change.forEach(function(a){f.deleteIndex(a.name);Yb(f,a)});a.del.forEach(function(a){f.deleteIndex(a)}); c()})});f._cfg.contentUpgrade&&x.push(function(a,c){B=!0;var h=L._createTransaction(b,[].slice.call(a.db.objectStoreNames,0),n);h.idbtrans=a;var s=0;h._promise=X(h._promise,function(a){return function(b,f,l){function h(a){return function(){a.apply(this,arguments);0===--s&&c()}}++s;return a.call(this,b,function(a,b,c){arguments[0]=h(a);arguments[1]=h(b);f.apply(this,arguments)},l)}});a.onerror=Qa(m,["running upgrader function for version",f._cfg.version]);h.on("error").subscribe(m);f._cfg.contentUpgrade(h); 0===s&&c()});B&&(0<=navigator.userAgent.indexOf("Trident")||0<=navigator.userAgent.indexOf("MSIE"))||x.push(function(a,b){for(var c=0;cb?1:0}function Vd(a,b){return ab?-1:0}function Bc(a){return function(b,h){for(var m=0;;){var n=a(b[m],h[m]);if(0!==n)return n;++m;if(m===b.length||m===h.length)return a(b.length,h.length)}}}function Xb(a,b){return a?b?function(){return a.apply(this,arguments)&&b.apply(this,arguments)}:a:b}function Ob(){L.verno= m.version/10;L._dbSchema=da={};ed=[].slice.call(m.objectStoreNames,0);if(0!==ed.length){var a=m.transaction(Lc(ed),"readonly");ed.forEach(function(b){for(var h=a.objectStore(b),m=h.keyPath,n=m&&"string"===typeof m&&-1!==m.indexOf("."),r=new ad(m,m||"",!1,!1,!!h.autoIncrement,m&&"string"!==typeof m,n),f=[],x=0;xMath.pow(2,62)?0:a.oldVersion,ec(a/10,r.transaction,h,r))},h);r.onsuccess=ga(function(b){oa=!1;m=r.result;qa? Ob():0h(a[x],c[x])?a.substr(0,x)+c[x]+c.substr(x+1):0>h(a[x],l[x])?a.substr(0,x)+l[x]+c.substr(x+1):0<=s?a.substr(0,s)+b[s]+c.substr(s+1):null;0>h(a[x], B)&&(s=x)}return rs?null:a.substr(0,s)+l[s]+c.substr(s+1)}function r(a,b,c){function l(a){x=h(a);B=m(a);u="next"===a?H:Vd;G=x(c);E=B(c);Mc=a}var x,B,u,G,E,Mc;l("next");a._ondirectionchange=function(a){l(a)};a._addAlgorithm(function(a,c,f){var l=a.key;if("string"!==typeof l)return!1;var h=B(l);if(b(h,E))return c(function(){a.continue()}),!0;var m=n(l,h,G,E,u,Mc);m?c(function(){a.continue(m)}):c(f);return!1})}return{between:function(a, b,c,l){c=!1!==c;l=!0===l;return a>b||a===b&&!(!c&&!l||c&&l)?(new this._ctx.collClass(this,function(){return O.only(a)})).limit(0):new this._ctx.collClass(this,function(){return O.bound(a,b,!c,!l)})},equals:function(a){return new this._ctx.collClass(this,function(){return O.only(a)})},above:function(a){return new this._ctx.collClass(this,function(){return O.lowerBound(a,!0)})},aboveOrEqual:function(a){return new this._ctx.collClass(this,function(){return O.lowerBound(a)})},below:function(a){return new this._ctx.collClass(this, function(){return O.upperBound(a,!0)})},belowOrEqual:function(a){return new this._ctx.collClass(this,function(){return O.upperBound(a)})},startsWith:function(b){return"string"!==typeof b?a(new this._ctx.collClass(this),new dd("String expected")):this.between(b,b+String.fromCharCode(65535),!0,!0)},startsWithIgnoreCase:function(b){if("string"!==typeof b)return a(new this._ctx.collClass(this),new dd("String expected"));if(""===b)return this.startsWith(b);var c=new this._ctx.collClass(this,function(){return O.bound(b.toUpperCase(), b.toLowerCase()+String.fromCharCode(65535))});r(c,function(a,b){return 0===a.indexOf(b)},b);c._ondirectionchange=function(){a(c,new Ma("reverse() not supported with WhereClause.startsWithIgnoreCase()"))};return c},equalsIgnoreCase:function(b){if("string"!==typeof b)return a(new this._ctx.collClass(this),new dd("String expected"));var c=new this._ctx.collClass(this,function(){return O.bound(b.toUpperCase(),b.toLowerCase())});r(c,function(a,b){return a===b},b);return c},anyOf:function(a){var h=this._ctx, m=h.table.schema,l=(h=h.index?m.idxByName[h.index]:m.primKey)&&h.compound,n=b(arguments),r=l?Bc(H):H;n.sort(r);if(0===n.length)return(new this._ctx.collClass(this,function(){return O.only("")})).limit(0);h=new this._ctx.collClass(this,function(){return O.bound(n[0],n[n.length-1])});h._ondirectionchange=function(a){r="next"===a?H:Vd;l&&(r=Bc(r));n.sort(r)};var s=0;h._addAlgorithm(function(a,b,c){for(var f=a.key;0l?x:0}var h=this._ctx;ua(function(){b([r(h)])});var m=a.split(".").reverse(),n=m[0],s=m.length-1,x="next"===this._ctx.dir?1:-1;return this.toArray(function(a){return a.sort(l)}).then(b)}, toArray:function(a){var b=this._ctx;ua(function(){a([r(b)])});return this._read(function(a,c,f){var h=[];n(b,function(a){h.push(a)},function(){a(h)},c,f)},a)},offset:function(b){var c=this._ctx;if(0>=b)return this;c.offset+=b;c.or||c.algorithm||c.filter?a(c,function(a,c,h){return 0>--b}):a(c,function(a,c,h){if(0===b)return!0;if(1===b)return--b,!1;c(function(){a.advance(b);b=0});return!1});return this},limit:function(b){this._ctx.limit=Math.min(this._ctx.limit,b);a(this._ctx,function(a,c,l){0>=--b&& c(l);return 0<=b});return this},until:function(b,c){var h=this._ctx;ua(function(){b(r(h))});a(this._ctx,function(a,h,m){return b(a.value)?(h(m),c):!0});return this},first:function(a){var b=this;ua(function(){a(r(b._ctx))});return this.limit(1).toArray(function(a){return a[0]}).then(a)},last:function(a){return this.reverse().first(a)},and:function(b){var h=this;ua(function(){b(r(h._ctx))});a(this._ctx,function(a){return b(a.value)});c(this._ctx,b);return this},or:function(a){return new Ac(this._ctx.table, a,this)},reverse:function(){this._ctx.dir="prev"===this._ctx.dir?"next":"prev";this._ondirectionchange&&this._ondirectionchange(this._ctx.dir);return this},desc:function(){return this.reverse()},eachKey:function(a){var b=this,c=this._ctx;ua(function(){a(r(b._ctx)[b._ctx.index])});c.isPrimKey||(c.op="openKeyCursor");return this.each(function(b,c){a(c.key,c)})},eachUniqueKey:function(a){this._ctx.unique="unique";return this.eachKey(a)},keys:function(a){ua(function(){a([r(c)[b._ctx.index]])});var b= this,c=this._ctx;c.isPrimKey||(c.op="openKeyCursor");var l=[];return this.each(function(a,b){l.push(b.key)}).then(function(){return l}).then(a)},uniqueKeys:function(a){this._ctx.unique="unique";return this.keys(a)},firstKey:function(a){return this.limit(1).keys(function(a){return a[0]}).then(a)},lastKey:function(a){return this.reverse().firstKey(a)},distinct:function(){var b={};a(this._ctx,function(a){a=a.primaryKey.toString();var c=b.hasOwnProperty(a);b[a]=!0;return!c});return this}}});U(Pa).from(Cb).extend({modify:function(a){var b= this,h=this._ctx,m=h.table.hook,n=m.updating.fire,r=m.deleting.fire;ua(function(){"function"===typeof a&&a.call({value:h.table.schema.instanceTemplate},h.table.schema.instanceTemplate)});return this._write(function(f,m,x,l){function B(a){a&&(M.push(a),Nc.push(ec));return m(new Kd("Error modifying one or more objects",M,C,Nc))}function u(){O&&C+M.length===D&&(0