UNPKG

webcrypto-liner

Version:

A WebCrypto polyfill that "smooths out" the rough-edges in existing User Agent implementations.

1 lines 258 kB
var _excluded=["name","optional","primitiveSchema"],_excluded2=["value"],_excluded3=["isHexOnly"],_excluded4=["value","isIndefiniteForm"],_excluded5=["value"],_excluded6=["isConstructed"],_excluded7=["idBlock","lenBlock"],_excluded8=["unusedBits","isConstructed"],_excluded9=["idBlock","lenBlock"],_excluded10=["value"],_excluded11=["valueDec","isFirstSid"],_excluded12=["value"],_excluded13=["valueDec"],_excluded14=["value"],_excluded15=["value","valueDate"],_excluded16=["value"],_excluded17=["value","local"];function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _regeneratorRuntime(){"use strict";_regeneratorRuntime=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},a="function"==typeof Symbol?Symbol:{},o=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var a=t&&t.prototype instanceof d?t:d,o=Object.create(a.prototype),u=new K(n||[]);return i(o,"_invoke",{value:x(e,r,u)}),o}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var f="suspendedStart",p="suspendedYield",v="executing",y="completed",g={};function d(){}function m(){}function k(){}var w={};c(w,o,(function(){return this}));var b=Object.getPrototypeOf,_=b&&b(b(O([])));_&&_!==r&&n.call(_,o)&&(w=_);var C=k.prototype=d.prototype=Object.create(w);function S(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function A(e,t){function r(i,a,o,u){var s=h(e[i],e,a);if("throw"!==s.type){var c=s.arg,l=c.value;return l&&"object"==_typeof(l)&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,o,u)}),(function(e){r("throw",e,o,u)})):t.resolve(l).then((function(e){c.value=e,o(c)}),(function(e){return r("throw",e,o,u)}))}u(s.arg)}var a;i(this,"_invoke",{value:function(e,n){function i(){return new t((function(t,i){r(e,n,t,i)}))}return a=a?a.then(i,i):i()}})}function x(t,r,n){var i=f;return function(a,o){if(i===v)throw new Error("Generator is already running");if(i===y){if("throw"===a)throw o;return{value:e,done:!0}}for(n.method=a,n.arg=o;;){var u=n.delegate;if(u){var s=B(u,n);if(s){if(s===g)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===f)throw i=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=v;var c=h(t,r,n);if("normal"===c.type){if(i=n.done?y:p,c.arg===g)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(i=y,n.method="throw",n.arg=c.arg)}}}function B(t,r){var n=r.method,i=t.iterator[n];if(i===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,B(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var a=h(i,t.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,g;var o=a.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,g):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function E(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function R(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function K(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function O(t){if(t||""===t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}throw new TypeError(_typeof(t)+" is not iterable")}return m.prototype=k,i(C,"constructor",{value:k,configurable:!0}),i(k,"constructor",{value:m,configurable:!0}),m.displayName=c(k,s,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,k):(e.__proto__=k,c(e,s,"GeneratorFunction")),e.prototype=Object.create(C),e},t.awrap=function(e){return{__await:e}},S(A.prototype),c(A.prototype,u,(function(){return this})),t.AsyncIterator=A,t.async=function(e,r,n,i,a){void 0===a&&(a=Promise);var o=new A(l(e,r,n,i),a);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},S(C),c(C,s,"Generator"),c(C,o,(function(){return this})),c(C,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,K.prototype={constructor:K,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(R),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return u.type="throw",u.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],u=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var s=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(s&&c){if(this.prev<o.catchLoc)return i(o.catchLoc,!0);if(this.prev<o.finallyLoc)return i(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return i(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return i(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,g):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),g},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),R(r),g}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;R(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:O(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),g}},t}function asyncGeneratorStep(e,t,r,n,i,a,o){try{var u=e[a](o),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,i)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var a=e.apply(t,r);function o(e){asyncGeneratorStep(a,n,i,o,u,"next",e)}function u(e){asyncGeneratorStep(a,n,i,o,u,"throw",e)}o(void 0)}))}}function _wrapNativeSuper(e){var t="function"==typeof Map?new Map:void 0;return _wrapNativeSuper=function(e){if(null===e||!_isNativeFunction(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return _construct(e,arguments,_getPrototypeOf(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(r,e)},_wrapNativeSuper(e)}function _construct(e,t,r){if(_isNativeReflectConstruct())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,t);var i=new(e.bind.apply(e,n));return r&&_setPrototypeOf(i,r.prototype),i}function _isNativeFunction(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}function _objectDestructuringEmpty(e){if(null==e)throw new TypeError("Cannot destructure "+e)}function _objectWithoutProperties(e,t){if(null==e)return{};var r,n,i=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var r,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(i[r]=e[r]);return i}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _callSuper(e,t,r){return t=_getPrototypeOf(t),_possibleConstructorReturn(e,_isNativeReflectConstruct()?Reflect.construct(t,r||[],_getPrototypeOf(e).constructor):t.apply(e,r))}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(_isNativeReflectConstruct=function(){return!!e})()}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=_superPropBase(e,t);if(n){var i=Object.getOwnPropertyDescriptor(n,t);return i.get?i.get.call(arguments.length<3?e:r):i.value}},_get.apply(this,arguments)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _getPrototypeOf(e){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},_getPrototypeOf(e)}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},_setPrototypeOf(e,t)}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function _createForOfIteratorHelper(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){u=!0,a=e},f:function(){try{o||null==r.return||r.return()}finally{if(u)throw a}}}}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey(n.key),n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"==_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var liner=function(e,t,r){"use strict";function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=n(t),a=n(r),o={};"undefined"!=typeof self&&(o=self),e.nativeCrypto=o.msCrypto||o.crypto||{},e.nativeSubtle=null;try{e.nativeSubtle=(null===e.nativeCrypto||void 0===e.nativeCrypto?void 0:e.nativeCrypto.subtle)||(null===e.nativeCrypto||void 0===e.nativeCrypto?void 0:e.nativeCrypto.webkitSubtle)||null}catch(e){console.warn("Cannot get subtle from crypto",e)}var u=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"isArrayBuffer",value:function(e){return"[object ArrayBuffer]"===Object.prototype.toString.call(e)}},{key:"toArrayBuffer",value:function(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}},{key:"toUint8Array",value:function(e){return this.toView(e,Uint8Array)}},{key:"toView",value:function(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}},{key:"isBufferSource",value:function(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}},{key:"isArrayBufferView",value:function(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}},{key:"isEqual",value:function(t,r){var n=e.toUint8Array(t),i=e.toUint8Array(r);if(n.length!==i.byteLength)return!1;for(var a=0;a<n.length;a++)if(n[a]!==i[a])return!1;return!0}},{key:"concat",value:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];var i,a=0,o=_createForOfIteratorHelper(e=!Array.isArray(r[0])||r[1]instanceof Function?Array.isArray(r[0])&&r[1]instanceof Function?r[0]:r[r.length-1]instanceof Function?r.slice(0,r.length-1):r:r[0]);try{for(o.s();!(i=o.n()).done;){a+=i.value.byteLength}}catch(e){o.e(e)}finally{o.f()}var u,s=new Uint8Array(a),c=0,l=_createForOfIteratorHelper(e);try{for(l.s();!(u=l.n()).done;){var h=u.value,f=this.toUint8Array(h);s.set(f,c),c+=f.length}}catch(e){l.e(e)}finally{l.f()}return r[r.length-1]instanceof Function?this.toView(s,r[r.length-1]):s.buffer}}]),e}(),s="string",c=/^[0-9a-f]+$/i,l=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,h=/^[a-zA-Z0-9-_]+$/,f=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"fromString",value:function(e){for(var t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length),n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r.buffer}},{key:"toString",value:function(e){for(var t=u.toUint8Array(e),r="",n=0;n<t.length;n++)r+=String.fromCharCode(t[n]);return decodeURIComponent(escape(r))}}]),e}(),p=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"toString",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=u.toArrayBuffer(e),n=new DataView(r),i="",a=0;a<r.byteLength;a+=2){var o=n.getUint16(a,t);i+=String.fromCharCode(o)}return i}},{key:"fromString",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=new ArrayBuffer(2*e.length),n=new DataView(r),i=0;i<e.length;i++)n.setUint16(2*i,e.charCodeAt(i),t);return r}}]),e}(),v=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"isHex",value:function(e){return _typeof(e)===s&&c.test(e)}},{key:"isBase64",value:function(e){return _typeof(e)===s&&l.test(e)}},{key:"isBase64Url",value:function(e){return _typeof(e)===s&&h.test(e)}},{key:"ToString",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf8",r=u.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(r);case"binary":return this.ToBinary(r);case"hex":return this.ToHex(r);case"base64":return this.ToBase64(r);case"base64url":return this.ToBase64Url(r);case"utf16le":return p.toString(r,!0);case"utf16":case"utf16be":return p.toString(r);default:throw new Error("Unknown type of encoding '".concat(t,"'"))}}},{key:"FromString",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf8";if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return p.fromString(e,!0);case"utf16":case"utf16be":return p.fromString(e);default:throw new Error("Unknown type of encoding '".concat(t,"'"))}}},{key:"ToBase64",value:function(e){var t=u.toUint8Array(e);if("undefined"!=typeof btoa){var r=this.ToString(t,"binary");return btoa(r)}return Buffer.from(t).toString("base64")}},{key:"FromBase64",value:function(t){var r=this.formatString(t);if(!r)return new ArrayBuffer(0);if(!e.isBase64(r))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return"undefined"!=typeof atob?this.FromBinary(atob(r)):new Uint8Array(Buffer.from(r,"base64")).buffer}},{key:"FromBase64Url",value:function(t){var r=this.formatString(t);if(!r)return new ArrayBuffer(0);if(!e.isBase64Url(r))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(r.replace(/\-/g,"+").replace(/\_/g,"/")))}},{key:"ToBase64Url",value:function(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}},{key:"FromUtf8String",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.DEFAULT_UTF8_ENCODING;switch(r){case"ascii":return this.FromBinary(t);case"utf8":return f.fromString(t);case"utf16":case"utf16be":return p.fromString(t);case"utf16le":case"usc2":return p.fromString(t,!0);default:throw new Error("Unknown type of encoding '".concat(r,"'"))}}},{key:"ToUtf8String",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.DEFAULT_UTF8_ENCODING;switch(r){case"ascii":return this.ToBinary(t);case"utf8":return f.toString(t);case"utf16":case"utf16be":return p.toString(t);case"utf16le":case"usc2":return p.toString(t,!0);default:throw new Error("Unknown type of encoding '".concat(r,"'"))}}},{key:"FromBinary",value:function(e){for(var t=e.length,r=new Uint8Array(t),n=0;n<t;n++)r[n]=e.charCodeAt(n);return r.buffer}},{key:"ToBinary",value:function(e){for(var t=u.toUint8Array(e),r="",n=0;n<t.length;n++)r+=String.fromCharCode(t[n]);return r}},{key:"ToHex",value:function(e){for(var t=u.toUint8Array(e),r="",n=t.length,i=0;i<n;i++){var a=t[i];a<16&&(r+="0"),r+=a.toString(16)}return r}},{key:"FromHex",value:function(t){var r=this.formatString(t);if(!r)return new ArrayBuffer(0);if(!e.isHex(r))throw new TypeError("Argument 'hexString' is not HEX encoded");r.length%2&&(r="0".concat(r));for(var n=new Uint8Array(r.length/2),i=0;i<r.length;i+=2){var a=r.slice(i,i+2);n[i/2]=parseInt(a,16)}return n.buffer}},{key:"ToUtf16String",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return p.toString(e,t)}},{key:"FromUtf16String",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return p.fromString(e,t)}},{key:"Base64Padding",value:function(e){var t=4-e.length%4;if(t<4)for(var r=0;r<t;r++)e+="=";return e}},{key:"formatString",value:function(e){return(null==e?void 0:e.replace(/[\n\r\t ]/g,""))||""}}]),e}();function y(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=t.map((function(e){return e.byteLength})).reduce((function(e,t){return e+t})),i=new Uint8Array(n),a=0;return t.map((function(e){return new Uint8Array(e)})).forEach((function(e){var t,r=_createForOfIteratorHelper(e);try{for(r.s();!(t=r.n()).done;){var n=t.value;i[a++]=n}}catch(e){r.e(e)}finally{r.f()}})),i.buffer}function g(e,t){var r=0;if(1===e.length)return e[0];for(var n=e.length-1;n>=0;n--)r+=e[e.length-1-n]*Math.pow(2,t*n);return r}function d(e,t){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:-1,n=e,i=0,a=Math.pow(2,t),o=1;o<8;o++){if(e<a){var u=void 0;if(r<0)u=new ArrayBuffer(o),i=o;else{if(r<o)return new ArrayBuffer(0);u=new ArrayBuffer(r),i=r}for(var s=new Uint8Array(u),c=o-1;c>=0;c--){var l=Math.pow(2,c*t);s[i-c-1]=Math.floor(n/l),n-=s[i-c-1]*l}return u}a*=Math.pow(2,t)}return new ArrayBuffer(0)}function m(){for(var e=0,t=0,r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];for(var a=0,o=n;a<o.length;a++){e+=o[a].length}for(var u=new ArrayBuffer(e),s=new Uint8Array(u),c=0,l=n;c<l.length;c++){var h=l[c];s.set(h,t),t+=h.length}return s}function k(){var e=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){var t=255===e[0]&&128&e[1],r=0===e[0]&&0==(128&e[1]);(t||r)&&this.warnings.push("Needlessly long format")}for(var n=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(n),a=0;a<this.valueHex.byteLength;a++)i[a]=0;i[0]=128&e[0];for(var o=g(i,8),u=new ArrayBuffer(this.valueHex.byteLength),s=new Uint8Array(u),c=0;c<this.valueHex.byteLength;c++)s[c]=e[c];return s[0]&=127,g(s,8)-o}function w(e,t){var r=e.toString(10);if(t<r.length)return"";for(var n=t-r.length,i=new Array(n),a=0;a<n;a++)i[a]="0";return i.join("").concat(r)}function b(){if("undefined"==typeof BigInt)throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function _(e){for(var t=0,r=0,n=0;n<e.length;n++){t+=e[n].byteLength}for(var i=new Uint8Array(t),a=0;a<e.length;a++){var o=e[a];i.set(new Uint8Array(o),r),r+=o.byteLength}return i.buffer}function C(e,t,r,n){return t instanceof Uint8Array?t.byteLength?r<0?(e.error="Wrong parameter: inputOffset less than zero",!1):n<0?(e.error="Wrong parameter: inputLength less than zero",!1):!(t.byteLength-r-n<0)||(e.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):(e.error="Wrong parameter: inputBuffer has zero length",!1):(e.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}v.DEFAULT_UTF8_ENCODING="utf8";var S=function(){function e(){_classCallCheck(this,e),this.items=[]}return _createClass(e,[{key:"write",value:function(e){this.items.push(e)}},{key:"final",value:function(){return _(this.items)}}]),e}(),A=[new Uint8Array([1])],x="0123456789",B="name",E="valueHexView",R="isHexOnly",K="idBlock",O="tagClass",N="tagNumber",P="isConstructed",U="fromBER",I="toBER",L="local",T="",j=new ArrayBuffer(0),H=new Uint8Array(0),V="EndOfContent",D="OCTET STRING",M="BIT STRING";function F(e){var t;return t=function(e){function t(){var e,r;_classCallCheck(this,t);for(var n=arguments.length,i=new Array(n),a=0;a<n;a++)i[a]=arguments[a];e=_callSuper(this,t,[].concat(i));var o=i[0]||{};return e.isHexOnly=null!==(r=o.isHexOnly)&&void 0!==r&&r,e.valueHexView=o.valueHex?u.toUint8Array(o.valueHex):H,e}return _inherits(t,e),_createClass(t,[{key:"valueHex",get:function(){return this.valueHexView.slice().buffer},set:function(e){this.valueHexView=new Uint8Array(e)}},{key:"fromBER",value:function(e,t,r){var n=e instanceof ArrayBuffer?new Uint8Array(e):e;if(!C(this,n,t,r))return-1;var i=t+r;return this.valueHexView=n.subarray(t,i),this.valueHexView.length?(this.blockLength=r,i):(this.warnings.push("Zero buffer length"),t)}},{key:"toBER",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.isHexOnly?e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",j)}},{key:"toJSON",value:function(){return _objectSpread(_objectSpread({},_get(_getPrototypeOf(t.prototype),"toJSON",this).call(this)),{},{isHexOnly:this.isHexOnly,valueHex:v.ToHex(this.valueHexView)})}}]),t}(e),t.NAME="hexBlock",t}var J=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.blockLength,n=void 0===r?0:r,i=t.error,a=void 0===i?T:i,o=t.warnings,s=void 0===o?[]:o,c=t.valueBeforeDecode,l=void 0===c?H:c;_classCallCheck(this,e),this.blockLength=n,this.error=a,this.warnings=s,this.valueBeforeDecodeView=u.toUint8Array(l)}return _createClass(e,[{key:"valueBeforeDecode",get:function(){return this.valueBeforeDecodeView.slice().buffer},set:function(e){this.valueBeforeDecodeView=new Uint8Array(e)}},{key:"toJSON",value:function(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:v.ToHex(this.valueBeforeDecodeView)}}}],[{key:"blockName",value:function(){return this.NAME}}]),e}();J.NAME="baseBlock";var G=function(e){function t(){return _classCallCheck(this,t),_callSuper(this,t,arguments)}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,t,r){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}},{key:"toBER",value:function(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}}]),t}(J);G.NAME="valueBlock";var z=function(e){function t(){var e,r,n,i,a,o=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).idBlock,s=void 0===o?{}:o;return _classCallCheck(this,t),e=_callSuper(this,t),s?(e.isHexOnly=null!==(r=s.isHexOnly)&&void 0!==r&&r,e.valueHexView=s.valueHex?u.toUint8Array(s.valueHex):H,e.tagClass=null!==(n=s.tagClass)&&void 0!==n?n:-1,e.tagNumber=null!==(i=s.tagNumber)&&void 0!==i?i:-1,e.isConstructed=null!==(a=s.isConstructed)&&void 0!==a&&a):(e.tagClass=-1,e.tagNumber=-1,e.isConstructed=!1),e}return _inherits(t,e),_createClass(t,[{key:"toBER",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",j}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){var r=new Uint8Array(1);if(!e){var n=this.tagNumber;t|=n&=31,r[0]=t}return r.buffer}if(!this.isHexOnly){var i=d(this.tagNumber,7),a=new Uint8Array(i),o=i.byteLength,u=new Uint8Array(o+1);if(u[0]=31|t,!e){for(var s=0;s<o-1;s++)u[s+1]=128|a[s];u[o]=a[o-1]}return u.buffer}var c=new Uint8Array(this.valueHexView.byteLength+1);if(c[0]=31|t,!e){for(var l=this.valueHexView,h=0;h<l.length-1;h++)c[h+1]=128|l[h];c[this.valueHexView.byteLength]=l[l.length-1]}return c.buffer}},{key:"fromBER",value:function(e,t,r){var n=u.toUint8Array(e);if(!C(this,n,t,r))return-1;var i=n.subarray(t,t+r);if(0===i.length)return this.error="Zero buffer length",-1;switch(192&i[0]){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=32==(32&i[0]),this.isHexOnly=!1;var a=31&i[0];if(31!==a)this.tagNumber=a,this.blockLength=1;else{for(var o=1,s=this.valueHexView=new Uint8Array(255),c=255;128&i[o];){if(s[o-1]=127&i[o],++o>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(o===c){c+=255;for(var l=new Uint8Array(c),h=0;h<s.length;h++)l[h]=s[h];s=this.valueHexView=new Uint8Array(c)}}this.blockLength=o+1,s[o-1]=127&i[o];for(var f=new Uint8Array(o),p=0;p<o;p++)f[p]=s[p];(s=this.valueHexView=new Uint8Array(o)).set(f),this.blockLength<=9?this.tagNumber=g(s,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(1===this.tagClass&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}},{key:"toJSON",value:function(){return _objectSpread(_objectSpread({},_get(_getPrototypeOf(t.prototype),"toJSON",this).call(this)),{},{tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed})}}]),t}(F(J));z.NAME="identificationBlock";var q=function(e){function t(){var e,r,n,i,a=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).lenBlock,o=void 0===a?{}:a;return _classCallCheck(this,t),(e=_callSuper(this,t)).isIndefiniteForm=null!==(r=o.isIndefiniteForm)&&void 0!==r&&r,e.longFormUsed=null!==(n=o.longFormUsed)&&void 0!==n&&n,e.length=null!==(i=o.length)&&void 0!==i?i:0,e}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,t,r){var n=u.toUint8Array(e);if(!C(this,n,t,r))return-1;var i=n.subarray(t,t+r);if(0===i.length)return this.error="Zero buffer length",-1;if(255===i[0])return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=128===i[0],this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(128&i[0]),!1===this.longFormUsed)return this.length=i[0],this.blockLength=1,t+this.blockLength;var a=127&i[0];if(a>8)return this.error="Too big integer",-1;if(a+1>i.length)return this.error="End of input reached before message was fully decoded",-1;var o=t+1,s=n.subarray(o,o+a);return 0===s[a-1]&&this.warnings.push("Needlessly long encoded length"),this.length=g(s,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=a+1,t+this.blockLength}},{key:"toBER",value:function(){var e,t,r=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return e=new ArrayBuffer(1),!1===r&&((t=new Uint8Array(e))[0]=128),e;if(this.longFormUsed){var n=d(this.length,8);if(n.byteLength>127)return this.error="Too big length",j;if(e=new ArrayBuffer(n.byteLength+1),r)return e;var i=new Uint8Array(n);(t=new Uint8Array(e))[0]=128|n.byteLength;for(var a=0;a<n.byteLength;a++)t[a+1]=i[a];return e}return e=new ArrayBuffer(1),!1===r&&((t=new Uint8Array(e))[0]=this.length),e}},{key:"toJSON",value:function(){return _objectSpread(_objectSpread({},_get(_getPrototypeOf(t.prototype),"toJSON",this).call(this)),{},{isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length})}}]),t}(J);q.NAME="lengthBlock";var W={},X=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.name,i=void 0===n?T:n,a=r.optional,o=void 0!==a&&a,u=r.primitiveSchema,s=_objectWithoutProperties(r,_excluded),c=arguments.length>1?arguments[1]:void 0;return _classCallCheck(this,t),(e=_callSuper(this,t,[s])).name=i,e.optional=o,u&&(e.primitiveSchema=u),e.idBlock=new z(s),e.lenBlock=new q(s),e.valueBlock=c?new c(s):new G(s),e}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,t,r){var n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return-1===n?(this.error=this.valueBlock.error,n):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}},{key:"toBER",value:function(e,t){var r=t||new S;t||Z(this);var n=this.idBlock.toBER(e);if(r.write(n),this.lenBlock.isIndefiniteForm)r.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,r),r.write(new ArrayBuffer(2));else{var i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;var a=this.lenBlock.toBER(e);r.write(a),r.write(i)}return t?j:r.final()}},{key:"toJSON",value:function(){var e=_objectSpread(_objectSpread({},_get(_getPrototypeOf(t.prototype),"toJSON",this).call(this)),{},{idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional});return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}},{key:"toString",value:function(){return"ascii"===(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"ascii")?this.onAsciiEncoding():v.ToHex(this.toBER())}},{key:"onAsciiEncoding",value:function(){return"".concat(this.constructor.NAME," : ").concat(v.ToHex(this.valueBlock.valueBeforeDecodeView))}},{key:"isEqual",value:function(e){return this===e||e instanceof this.constructor&&function(e,t){if(e.byteLength!==t.byteLength)return!1;for(var r=new Uint8Array(e),n=new Uint8Array(t),i=0;i<r.length;i++)if(r[i]!==n[i])return!1;return!0}(this.toBER(),e.toBER())}}]),t}(J);function Z(e){if(e instanceof W.Constructed){var t,r=_createForOfIteratorHelper(e.valueBlock.value);try{for(r.s();!(t=r.n()).done;){Z(t.value)&&(e.lenBlock.isIndefiniteForm=!0)}}catch(e){r.e(e)}finally{r.f()}}return!!e.lenBlock.isIndefiniteForm}X.NAME="BaseBlock";var $=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.value,i=void 0===n?T:n,a=_objectWithoutProperties(r,_excluded2),o=arguments.length>1?arguments[1]:void 0;return _classCallCheck(this,t),e=_callSuper(this,t,[a,o]),i&&e.fromString(i),e}return _inherits(t,e),_createClass(t,[{key:"getValue",value:function(){return this.valueBlock.value}},{key:"setValue",value:function(e){this.valueBlock.value=e}},{key:"fromBER",value:function(e,t,r){var n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return-1===n?(this.error=this.valueBlock.error,n):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}},{key:"onAsciiEncoding",value:function(){return"".concat(this.constructor.NAME," : '").concat(this.valueBlock.value,"'")}}]),t}(X);$.NAME="BaseStringBlock";var Y,Q=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.isHexOnly,i=void 0===n||n,a=_objectWithoutProperties(r,_excluded3);return _classCallCheck(this,t),(e=_callSuper(this,t,[a])).isHexOnly=i,e}return _inherits(t,e),_createClass(t)}(F(G));Q.NAME="PrimitiveValueBlock";var ee=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return _classCallCheck(this,t),(e=_callSuper(this,t,[r,Q])).idBlock.isConstructed=!1,e}return _inherits(t,e),_createClass(t)}(X);function te(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,n=t,i=new X({},G),a=new J;if(!C(a,e,t,r))return i.error=a.error,{offset:-1,result:i};if(!e.subarray(t,t+r).length)return i.error="Zero buffer length",{offset:-1,result:i};var o=i.idBlock.fromBER(e,t,r);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),-1===o)return i.error=i.idBlock.error,{offset:-1,result:i};if(t=o,r-=i.idBlock.blockLength,o=i.lenBlock.fromBER(e,t,r),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),-1===o)return i.error=i.lenBlock.error,{offset:-1,result:i};if(t=o,r-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};var u=X;if(1===i.idBlock.tagClass){if(i.idBlock.tagNumber>=37&&!1===i.idBlock.isHexOnly)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};u=W.EndOfContent;break;case 1:u=W.Boolean;break;case 2:u=W.Integer;break;case 3:u=W.BitString;break;case 4:u=W.OctetString;break;case 5:u=W.Null;break;case 6:u=W.ObjectIdentifier;break;case 10:u=W.Enumerated;break;case 12:u=W.Utf8String;break;case 13:u=W.RelativeObjectIdentifier;break;case 14:u=W.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:u=W.Sequence;break;case 17:u=W.Set;break;case 18:u=W.NumericString;break;case 19:u=W.PrintableString;break;case 20:u=W.TeletexString;break;case 21:u=W.VideotexString;break;case 22:u=W.IA5String;break;case 23:u=W.UTCTime;break;case 24:u=W.GeneralizedTime;break;case 25:u=W.GraphicString;break;case 26:u=W.VisibleString;break;case 27:u=W.GeneralString;break;case 28:u=W.UniversalString;break;case 29:u=W.CharacterString;break;case 30:u=W.BmpString;break;case 31:u=W.DATE;break;case 32:u=W.TimeOfDay;break;case 33:u=W.DateTime;break;case 34:u=W.Duration;break;default:var s=i.idBlock.isConstructed?new W.Constructed:new W.Primitive;s.idBlock=i.idBlock,s.lenBlock=i.lenBlock,s.warnings=i.warnings,i=s}}else u=i.idBlock.isConstructed?W.Constructed:W.Primitive;return i=function(e,t){if(e instanceof t)return e;var r=new t;return r.idBlock=e.idBlock,r.lenBlock=e.lenBlock,r.warnings=e.warnings,r.valueBeforeDecodeView=e.valueBeforeDecodeView,r}(i,u),o=i.fromBER(e,t,i.lenBlock.isIndefiniteForm?r:i.lenBlock.length),i.valueBeforeDecodeView=e.subarray(n,n+i.blockLength),{offset:o,result:i}}function re(e){if(!e.byteLength){var t=new X({},G);return t.error="Input buffer has zero length",{offset:-1,result:t}}return te(u.toUint8Array(e).slice(),0,e.byteLength)}Y=ee,W.Primitive=Y,ee.NAME="PRIMITIVE";var ne,ie=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.value,i=void 0===n?[]:n,a=r.isIndefiniteForm,o=void 0!==a&&a,u=_objectWithoutProperties(r,_excluded4);return _classCallCheck(this,t),(e=_callSuper(this,t,[u])).value=i,e.isIndefiniteForm=o,e}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,t,r){var n=u.toUint8Array(e);if(!C(this,n,t,r))return-1;if(this.valueBeforeDecodeView=n.subarray(t,t+r),0===this.valueBeforeDecodeView.length)return this.warnings.push("Zero buffer length"),t;for(var i,a,o=t;i=this.isIndefiniteForm,a=r,(i?1:a)>0;){var s=te(n,o,r);if(-1===s.offset)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(o=s.offset,this.blockLength+=s.result.blockLength,r-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===V)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===V?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}},{key:"toBER",value:function(e,t){for(var r=t||new S,n=0;n<this.value.length;n++)this.value[n].toBER(e,r);return t?j:r.final()}},{key:"toJSON",value:function(){var e,r=_objectSpread(_objectSpread({},_get(_getPrototypeOf(t.prototype),"toJSON",this).call(this)),{},{isIndefiniteForm:this.isIndefiniteForm,value:[]}),n=_createForOfIteratorHelper(this.value);try{for(n.s();!(e=n.n()).done;){var i=e.value;r.value.push(i.toJSON())}}catch(e){n.e(e)}finally{n.f()}return r}}]),t}(G);ie.NAME="ConstructedValueBlock";var ae=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return _classCallCheck(this,t),(e=_callSuper(this,t,[r,ie])).idBlock.isConstructed=!0,e}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,t,r){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;var n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return-1===n?(this.error=this.valueBlock.error,n):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}},{key:"onAsciiEncoding",value:function(){var e,t=[],r=_createForOfIteratorHelper(this.valueBlock.value);try{for(r.s();!(e=r.n()).done;){var n=e.value;t.push(n.toString("ascii").split("\n").map((function(e){return" ".concat(e)})).join("\n"))}}catch(e){r.e(e)}finally{r.f()}var i=3===this.idBlock.tagClass?"[".concat(this.idBlock.tagNumber,"]"):this.constructor.NAME;return t.length?"".concat(i," :\n").concat(t.join("\n")):"".concat(i," :")}}]),t}(X);ne=ae,W.Constructed=ne,ae.NAME="CONSTRUCTED";var oe,ue=function(e){function t(){return _classCallCheck(this,t),_callSuper(this,t,arguments)}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,t,r){return t}},{key:"toBER",value:function(e){return j}}]),t}(G);ue.override="EndOfContentValueBlock";var se,ce=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return _classCallCheck(this,t),(e=_callSuper(this,t,[r,ue])).idBlock.tagClass=1,e.idBlock.tagNumber=0,e}return _inherits(t,e),_createClass(t)}(X);oe=ce,W.EndOfContent=oe,ce.NAME=V;var le=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return _classCallCheck(this,t),(e=_callSuper(this,t,[r,G])).idBlock.tagClass=1,e.idBlock.tagNumber=5,e}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,t,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}},{key:"toBER",value:function(e,t){var r=new ArrayBuffer(2);if(!e){var n=new Uint8Array(r);n[0]=5,n[1]=0}return t&&t.write(r),r}},{key:"onAsciiEncoding",value:function(){return"".concat(this.constructor.NAME)}}]),t}(X);se=le,W.Null=se,le.NAME="NULL";var he,fe=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.value,i=_objectWithoutProperties(r,_excluded5);return _classCallCheck(this,t),e=_callSuper(this,t,[i]),i.valueHex?e.valueHexView=u.toUint8Array(i.valueHex):e.valueHexView=new Uint8Array(1),n&&(e.value=n),e}return _inherits(t,e),_createClass(t,[{key:"value",get:function(){var e,t=_createForOfIteratorHelper(this.valueHexView);try{for(t.s();!(e=t.n()).done;){if(e.value>0)return!0}}catch(e){t.e(e)}finally{t.f()}return!1},set:function(e){this.valueHexView[0]=e?255:0}},{key:"fromBER",value:function(e,t,r){var n=u.toUint8Array(e);return C(this,n,t,r)?(this.valueHexView=n.subarray(t,t+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,k.call(this),this.blockLength=r,t+r):-1}},{key:"toBER",value:function(){return this.valueHexView.slice()}},{key:"toJSON",value:function(){return _objectSpread(_objectSpread({},_get(_getPrototypeOf(t.prototype),"toJSON",this).call(this)),{},{value:this.value})}}]),t}(F(G));fe.NAME="BooleanValueBlock";var pe=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return _classCallCheck(this,t),(e=_callSuper(this,t,[r,fe])).idBlock.tagClass=1,e.idBlock.tagNumber=1,e}return _inherits(t,e),_createClass(t,[{key:"getValue",value:function(){return this.valueBlock.value}},{key:"setValue",value:function(e){this.valueBlock.value=e}},{key:"onAsciiEncoding",value:function(){return"".concat(this.constructor.NAME," : ").concat(this.getValue)}}]),t}(X);he=pe,W.Boolean=he,pe.NAME="BOOLEAN";var ve,ye=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.isConstructed,i=void 0!==n&&n,a=_objectWithoutProperties(r,_excluded6);return _classCallCheck(this,t),(e=_callSuper(this,t,[a])).isConstructed=i,e}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,r,n){var i=0;if(this.isConstructed){if(this.isHexOnly=!1,-1===(i=ie.prototype.fromBER.call(this,e,r,n)))return i;for(var a=0;a<this.value.length;a++){var o=this.value[a].constructor.NAME;if(o===V){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==D)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=_get(_getPrototypeOf(t.prototype),"fromBER",this).call(this,e,r,n),this.blockLength=n;return i}},{key:"toBER",value:function(e,t){return this.isConstructed?ie.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}},{key:"toJSON",value:function(){return _objectSpread(_objectSpread({},_get(_getPrototypeOf(t.prototype),"toJSON",this).call(this)),{},{isConstructed:this.isConstructed})}}]),t}(F(ie));ye.NAME="OctetStringValueBlock";var ge=function(e){function t(){var e,r,n,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=i.idBlock,o=void 0===a?{}:a,u=i.lenBlock,s=void 0===u?{}:u,c=_objectWithoutProperties(i,_excluded7);return _classCallCheck(this,t),null!==(r=c.isConstructed)&&void 0!==r||(c.isConstructed=!!(null===(n=c.value)||void 0===n?void 0:n.length)),(e=_callSuper(this,t,[_objectSpread({idBlock:_objectSpread({isConstructed:c.isConstructed},o),lenBlock:_objectSpread(_objectSpread({},s),{},{isIndefiniteForm:!!c.isIndefiniteForm})},c),ye])).idBlock.tagClass=1,e.idBlock.tagNumber=4,e}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,r,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,0===n)return 0===this.idBlock.error.length&&(this.blockLength+=this.idBlock.blockLength),0===this.lenBlock.error.length&&(this.blockLength+=this.lenBlock.blockLength),r;if(!this.valueBlock.isConstructed){var i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(r,r+n);try{if(i.byteLength){var a=te(i,0,i.byteLength);-1!==a.offset&&a.offset===n&&(this.valueBlock.value=[a.result])}}catch(e){}}return _get(_getPrototypeOf(t.prototype),"fromBER",this).call(this,e,r,n)}},{key:"onAsciiEncoding",value:function(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?ae.prototype.onAsciiEncoding.call(this):"".concat(this.constructor.NAME," : ").concat(v.ToHex(this.valueBlock.valueHexView))}},{key:"getValue",value:function(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;var e,r=[],n=_createForOfIteratorHelper(this.valueBlock.value);try{for(n.s();!(e=n.n()).done;){var i=e.value;i instanceof t&&r.push(i.valueBlock.valueHexView)}}catch(e){n.e(e)}finally{n.f()}return u.concat(r)}}]),t}(X);ve=ge,W.OctetString=ve,ge.NAME=D;var de,me=function(e){function t(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.unusedBits,i=void 0===n?0:n,a=r.isConstructed,o=void 0!==a&&a,u=_objectWithoutProperties(r,_excluded8);return _classCallCheck(this,t),(e=_callSuper(this,t,[u])).unusedBits=i,e.isConstructed=o,e.blockLength=e.valueHexView.byteLength,e}return _inherits(t,e),_createClass(t,[{key:"fromBER",value:function(e,t,r){if(!r)return t;var n=-1;if(this.isConstructed){if(-1===(n=ie.prototype.fromBER.call(this,e,t,r)))return n;var i,a=_createForOfIteratorHelper(this.value);try{for(a.s();!(i=a.n()).done;){var o=i.value,s=o.constructor.NAME;if(s===V){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(s!==M)return this.error="BIT STRING may consists of BIT STRINGs only",-1;var c=o.valueBlock;if(this.unusedBits>0&&c.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=c.unusedBits}}catch(e){a.e(e)}finally{a.f()}return n}var l=u.toUint8Array(e);if(!C(this,l,t,r))return-1;var h=l.subarray(t,t+r);if(this.unusedBits=h[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){var f=h.subarray(1);try{if(f.byteLength){var p=te(f,0,f.byteLength);-1!==p.offset&&p.offset===r-1&&(this.value=[p.result])}}catch(e){}}return this.valueHexView=h.subarray(1),this.blockLength=h.length,t+r}},{key:"toBER",value:function(e,t){if(this.isConstructed)return ie.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return j;var r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffe