Gazebo_simulation-Frontend/node_modules/webcrypto-shim/webcrypto-shim.min.js
2020-12-21 10:29:31 -05:00

4 lines
10 KiB
JavaScript

/*! WebCrypto API shim v0.1.5, (c) 2015 Artem S Vybornov <vybornov@gmail.com>, opensource.org/licenses/MIT */
!function(e,t){"function"==typeof define&&define.amd?define([],function(){return t(e)}):"object"==typeof module&&module.exports?module.exports=t(e):t(e)}("undefined"!=typeof self?self:this,function(e){"use strict";if("function"!=typeof Promise)throw"Promise support required";var p=e.crypto||e.msCrypto;if(p){var l=p.subtle||p.webkitSubtle;if(l){var t=e.Crypto||p.constructor||Object,r=e.SubtleCrypto||l.constructor||Object,n=(e.CryptoKey||e.Key||Object,-1<e.navigator.userAgent.indexOf("Edge/")),y=!!e.msCrypto&&!n,f=!p.subtle&&!!p.webkitSubtle;if(y||f){var s={KoZIhvcNAQEB:"1.2.840.113549.1.1.1"},c={"1.2.840.113549.1.1.1":"KoZIhvcNAQEB"};if(["generateKey","importKey","unwrapKey"].forEach(function(s){var c=l[s];l[s]=function(t,e,r){var n,a,o,i,u=[].slice.call(arguments);switch(s){case"generateKey":n=b(t),a=e,o=r;break;case"importKey":n=b(r),a=u[3],o=u[4],"jwk"===t&&((e=d(e)).alg||(e.alg=w(n)),e.key_ops||(e.key_ops="oct"!==e.kty?"d"in e?o.filter(E):o.filter(K):o.slice()),u[1]=function(e){var t=d(e);return y&&(t.extractable=t.ext,delete t.ext),A(unescape(encodeURIComponent(JSON.stringify(t)))).buffer}(e));break;case"unwrapKey":n=u[4],a=u[5],o=u[6],u[2]=r._key}if("generateKey"===s&&"HMAC"===n.name&&n.hash)return n.length=n.length||{"SHA-1":512,"SHA-256":512,"SHA-384":1024,"SHA-512":1024}[n.hash.name],l.importKey("raw",p.getRandomValues(new Uint8Array(n.length+7>>3)),n,a,o);if(f&&"generateKey"===s&&"RSASSA-PKCS1-v1_5"===n.name&&(!n.modulusLength||2048<=n.modulusLength))return(t=b(t)).name="RSAES-PKCS1-v1_5",delete t.hash,l.generateKey(t,!0,["encrypt","decrypt"]).then(function(e){return Promise.all([l.exportKey("jwk",e.publicKey),l.exportKey("jwk",e.privateKey)])}).then(function(e){return e[0].alg=e[1].alg=w(n),e[0].key_ops=o.filter(K),e[1].key_ops=o.filter(E),Promise.all([l.importKey("jwk",e[0],n,!0,e[0].key_ops),l.importKey("jwk",e[1],n,a,e[1].key_ops)])}).then(function(e){return{publicKey:e[0],privateKey:e[1]}});if((f||y&&"SHA-1"===(n.hash||{}).name)&&"importKey"===s&&"jwk"===t&&"HMAC"===n.name&&"oct"===e.kty)return l.importKey("raw",A(g(e.k)),r,u[3],u[4]);if(f&&"importKey"===s&&("spki"===t||"pkcs8"===t))return l.importKey("jwk",function(e){var t=S(e),r=!1;2<t.length&&(r=!0,t.shift());var n={ext:!0};switch(t[0][0]){case"1.2.840.113549.1.1.1":var a=["n","e","d","p","q","dp","dq","qi"],o=S(t[1]);r&&o.shift();for(var i=0;i<o.length;i++)o[i][0]||(o[i]=o[i].subarray(1)),n[a[i]]=h(m(o[i]));n.kty="RSA";break;default:throw new TypeError("Unsupported key type")}return n}(e),r,u[3],u[4]);if(y&&"unwrapKey"===s)return l.decrypt(u[3],r,e).then(function(e){return l.importKey(t,e,u[4],u[5],u[6])});try{i=c.apply(l,u)}catch(e){return Promise.reject(e)}return y&&(i=new Promise(function(t,r){i.onabort=i.onerror=function(e){r(e)},i.oncomplete=function(e){t(e.target.result)}})),i=i.then(function(e){return"HMAC"===n.name&&(n.length||(n.length=8*e.algorithm.length)),0==n.name.search("RSA")&&(n.modulusLength||(n.modulusLength=(e.publicKey||e).algorithm.modulusLength),n.publicExponent||(n.publicExponent=(e.publicKey||e).algorithm.publicExponent)),e=e.publicKey&&e.privateKey?{publicKey:new v(e.publicKey,n,a,o.filter(K)),privateKey:new v(e.privateKey,n,a,o.filter(E))}:new v(e,n,a,o)})}}),["exportKey","wrapKey"].forEach(function(o){var i=l[o];l[o]=function(t,r,n){var e,a=[].slice.call(arguments);switch(o){case"exportKey":a[1]=r._key;break;case"wrapKey":a[1]=r._key,a[2]=n._key}if((f||y&&"SHA-1"===(r.algorithm.hash||{}).name)&&"exportKey"===o&&"jwk"===t&&"HMAC"===r.algorithm.name&&(a[0]="raw"),!f||"exportKey"!==o||"spki"!==t&&"pkcs8"!==t||(a[0]="jwk"),y&&"wrapKey"===o)return l.exportKey(t,r).then(function(e){return"jwk"===t&&(e=A(unescape(encodeURIComponent(JSON.stringify(d(e)))))),l.encrypt(a[3],n,e)});try{e=i.apply(l,a)}catch(e){return Promise.reject(e)}return y&&(e=new Promise(function(t,r){e.onabort=e.onerror=function(e){r(e)},e.oncomplete=function(e){t(e.target.result)}})),"exportKey"===o&&"jwk"===t&&(e=e.then(function(e){return(f||y&&"SHA-1"===(r.algorithm.hash||{}).name)&&"HMAC"===r.algorithm.name?{kty:"oct",alg:w(r.algorithm),key_ops:r.usages.slice(),ext:!0,k:h(m(e))}:((e=d(e)).alg||(e.alg=w(r.algorithm)),e.key_ops||(e.key_ops="public"===r.type?r.usages.filter(K):"private"===r.type?r.usages.filter(E):r.usages.slice()),e)})),!f||"exportKey"!==o||"spki"!==t&&"pkcs8"!==t||(e=e.then(function(e){return e=function(e){var t,r=[["",null]],n=!1;switch(e.kty){case"RSA":for(var a=["n","e","d","p","q","dp","dq","qi"],o=[],i=0;i<a.length&&a[i]in e;i++){var u=o[i]=A(g(e[a[i]]));128&u[0]&&(o[i]=new Uint8Array(u.length+1),o[i].set(u,1))}2<o.length&&(n=!0,o.unshift(new Uint8Array([0]))),r[0][0]="1.2.840.113549.1.1.1",t=o;break;default:throw new TypeError("Unsupported key type")}return r.push(new Uint8Array(k(t)).buffer),n?r.unshift(new Uint8Array([0])):r[1]={tag:3,value:r[1]},new Uint8Array(k(r)).buffer}(d(e))})),e}}),["encrypt","decrypt","sign","verify"].forEach(function(s){var c=l[s];l[s]=function(e,t,r,n){if(y&&(!r.byteLength||n&&!n.byteLength))throw new Error("Empy input is not allowed");var a,o=[].slice.call(arguments),i=b(e);if(y&&("encrypt"===s||"decrypt"===s)&&t.algorithm.hash&&(o[0].hash=o[0].hash||t.algorithm.hash),y&&"decrypt"===s&&"AES-GCM"===i.name){var u=e.tagLength>>3;o[2]=(r.buffer||r).slice(0,r.byteLength-u),e.tag=(r.buffer||r).slice(r.byteLength-u)}o[1]=t._key;try{a=c.apply(l,o)}catch(e){return Promise.reject(e)}return y&&(a=new Promise(function(n,t){a.onabort=a.onerror=function(e){t(e)},a.oncomplete=function(e){e=e.target.result;if("encrypt"===s&&e instanceof AesGcmEncryptResult){var t=e.ciphertext,r=e.tag;(e=new Uint8Array(t.byteLength+r.byteLength)).set(new Uint8Array(t),0),e.set(new Uint8Array(r),t.byteLength),e=e.buffer}n(e)}})),a}}),y){var a=l.digest;l.digest=function(e,t){if(!t.byteLength)throw new Error("Empy input is not allowed");var n;try{n=a.call(l,e,t)}catch(e){return Promise.reject(e)}return n=new Promise(function(t,r){n.onabort=n.onerror=function(e){r(e)},n.oncomplete=function(e){t(e.target.result)}})},e.crypto=Object.create(p,{getRandomValues:{value:function(e){return p.getRandomValues(e)}},subtle:{value:l}}),e.CryptoKey=v}f&&(p.subtle=l,e.Crypto=t,e.SubtleCrypto=r,e.CryptoKey=v)}}}function h(e){return btoa(e).replace(/\=+$/,"").replace(/\+/g,"-").replace(/\//g,"_")}function g(e){return e=(e+="===").slice(0,-e.length%4),atob(e.replace(/-/g,"+").replace(/_/g,"/"))}function A(e){for(var t=new Uint8Array(e.length),r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}function m(e){return e instanceof ArrayBuffer&&(e=new Uint8Array(e)),String.fromCharCode.apply(String,e)}function b(e){var t={name:(e.name||e||"").toUpperCase().replace("V","v")};switch(t.name){case"SHA-1":case"SHA-256":case"SHA-384":case"SHA-512":break;case"AES-CBC":case"AES-GCM":case"AES-KW":e.length&&(t.length=e.length);break;case"HMAC":e.hash&&(t.hash=b(e.hash)),e.length&&(t.length=e.length);break;case"RSAES-PKCS1-v1_5":e.publicExponent&&(t.publicExponent=new Uint8Array(e.publicExponent)),e.modulusLength&&(t.modulusLength=e.modulusLength);break;case"RSASSA-PKCS1-v1_5":case"RSA-OAEP":e.hash&&(t.hash=b(e.hash)),e.publicExponent&&(t.publicExponent=new Uint8Array(e.publicExponent)),e.modulusLength&&(t.modulusLength=e.modulusLength);break;default:throw new SyntaxError("Bad algorithm name")}return t}function w(e){return{HMAC:{"SHA-1":"HS1","SHA-256":"HS256","SHA-384":"HS384","SHA-512":"HS512"},"RSASSA-PKCS1-v1_5":{"SHA-1":"RS1","SHA-256":"RS256","SHA-384":"RS384","SHA-512":"RS512"},"RSAES-PKCS1-v1_5":{"":"RSA1_5"},"RSA-OAEP":{"SHA-1":"RSA-OAEP","SHA-256":"RSA-OAEP-256"},"AES-KW":{128:"A128KW",192:"A192KW",256:"A256KW"},"AES-GCM":{128:"A128GCM",192:"A192GCM",256:"A256GCM"},"AES-CBC":{128:"A128CBC",192:"A192CBC",256:"A256CBC"}}[e.name][(e.hash||{}).name||e.length||""]}function d(t){(t instanceof ArrayBuffer||t instanceof Uint8Array)&&(t=JSON.parse(decodeURIComponent(escape(m(t)))));var r={kty:t.kty,alg:t.alg,ext:t.ext||t.extractable};switch(r.kty){case"oct":r.k=t.k;case"RSA":["n","e","d","p","q","dp","dq","qi","oth"].forEach(function(e){e in t&&(r[e]=t[e])});break;default:throw new TypeError("Unsupported key type")}return r}function S(e,t){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),t||(t={pos:0,end:e.length}),t.end-t.pos<2||t.end>e.length)throw new RangeError("Malformed DER");var r,n=e[t.pos++],a=e[t.pos++];if(128<=a){if(a&=127,t.end-t.pos<a)throw new RangeError("Malformed DER");for(var o=0;a--;)o<<=8,o|=e[t.pos++];a=o}if(t.end-t.pos<a)throw new RangeError("Malformed DER");switch(n){case 2:r=e.subarray(t.pos,t.pos+=a);break;case 3:if(e[t.pos++])throw new Error("Unsupported bit string");a--;case 4:r=new Uint8Array(e.subarray(t.pos,t.pos+=a)).buffer;break;case 5:r=null;break;case 6:var i=btoa(m(e.subarray(t.pos,t.pos+=a)));if(!(i in s))throw new Error("Unsupported OBJECT ID "+i);r=s[i];break;case 48:r=[];for(var u=t.pos+a;t.pos<u;)r.push(S(e,t));break;default:throw new Error("Unsupported DER tag 0x"+n.toString(16))}return r}function k(e,t){t||(t=[]);var r=0,n=0,a=t.length+2;if(t.push(0,0),e instanceof Uint8Array){r=2,n=e.length;for(var o=0;o<n;o++)t.push(e[o])}else if(e instanceof ArrayBuffer){r=4,n=e.byteLength,e=new Uint8Array(e);for(o=0;o<n;o++)t.push(e[o])}else if(null===e)r=5,n=0;else if("string"==typeof e&&e in c){var i=A(atob(c[e]));r=6,n=i.length;for(o=0;o<n;o++)t.push(i[o])}else if(e instanceof Array){for(o=0;o<e.length;o++)k(e[o],t);r=48,n=t.length-a}else{if(!("object"==typeof e&&3===e.tag&&e.value instanceof ArrayBuffer))throw new Error("Unsupported DER value "+e);r=3,n=(e=new Uint8Array(e.value)).byteLength,t.push(0);for(o=0;o<n;o++)t.push(e[o]);n++}if(128<=n){var u=n;n=4;for(t.splice(a,0,u>>24&255,u>>16&255,u>>8&255,255&u);1<n&&!(u>>24);)u<<=8,n--;n<4&&t.splice(a,4-n),n|=128}return t.splice(a-2,2,r,n),t}function v(e,t,r,n){Object.defineProperties(this,{_key:{value:e},type:{value:e.type,enumerable:!0},extractable:{value:void 0===r?e.extractable:r,enumerable:!0},algorithm:{value:void 0===t?e.algorithm:t,enumerable:!0},usages:{value:void 0===n?e.usages:n,enumerable:!0}})}function K(e){return"verify"===e||"encrypt"===e||"wrapKey"===e}function E(e){return"sign"===e||"decrypt"===e||"unwrapKey"===e}});
//# sourceMappingURL=webcrypto-shim.min.js.map