js-encoding-utils
Advanced tools
Comparing version 0.2.8 to 0.3.0
@@ -1,46 +0,183 @@ | ||
"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");var env=_interopRequireWildcard(require("./env.js"));Object.defineProperty(exports,"__esModule",{value:!0}),exports.encodeBase64=encodeBase64,exports.decodeBase64=decodeBase64,exports.encodeBase64Url=encodeBase64Url,exports.decodeBase64Url=decodeBase64Url,exports.arrayBufferToHexString=arrayBufferToHexString,exports.hexStringToArrayBuffer=hexStringToArrayBuffer,exports.arrayBufferToString=arrayBufferToString,exports.stringToArrayBuffer=stringToArrayBuffer;/** | ||
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.encodeBase64 = encodeBase64; | ||
exports.decodeBase64 = decodeBase64; | ||
exports.encodeBase64Url = encodeBase64Url; | ||
exports.decodeBase64Url = decodeBase64Url; | ||
exports.arrayBufferToHexString = arrayBufferToHexString; | ||
exports.hexStringToArrayBuffer = hexStringToArrayBuffer; | ||
exports.arrayBufferToString = arrayBufferToString; | ||
exports.stringToArrayBuffer = stringToArrayBuffer; | ||
var env = _interopRequireWildcard(require("./env.js")); | ||
/** | ||
* encoder.js | ||
*/ /** | ||
*/ | ||
/** | ||
* Encode ArrayBuffer or TypedArray To Base64 | ||
* @param data | ||
* @return {*} | ||
*/function encodeBase64(a){var b="";b="string"==typeof a?a:arrayBufferToString(a);var c=env.getEnvBtoa();return c(b)}/** | ||
*/ | ||
function encodeBase64(data) { | ||
var str = ''; | ||
if (typeof data === 'string') str = data;else str = arrayBufferToString(data); | ||
var btoa = env.getEnvBtoa(); | ||
return btoa(str); | ||
} | ||
/** | ||
* Decode Base64 to Uint8Array | ||
* @param str | ||
* @return {Uint8Array|string|*} | ||
*/function decodeBase64(a){var b=env.getEnvAtob(),c=b(a),d=stringToArrayBuffer(c);return getAsciiIfAscii(d)}/** | ||
*/ | ||
function decodeBase64(str) { | ||
var atob = env.getEnvAtob(); | ||
var binary = atob(str); | ||
var data = stringToArrayBuffer(binary); | ||
return getAsciiIfAscii(data); | ||
} | ||
/** | ||
* if input data is an ArrayBuffer or TypedArray, it would be returned as Uint8Array | ||
* @param data | ||
* @return {Uint8Array} | ||
*/function sanitizeTypedArrayAndArrayBuffer(a){if(a instanceof Uint8Array)return a;if(ArrayBuffer.isView(a)&&"undefined"!=typeof a.buffer)// TypedArray except Uint8Array | ||
return new Uint8Array(a.buffer);if(a instanceof ArrayBuffer)// ArrayBuffer | ||
return new Uint8Array(a);throw new Error("Input must be an ArrayBuffer or a TypedArray")}/** | ||
*/ | ||
function sanitizeTypedArrayAndArrayBuffer(data) { | ||
if (data instanceof Uint8Array) return data; | ||
if (ArrayBuffer.isView(data) && typeof data.buffer !== 'undefined') { | ||
// TypedArray except Uint8Array | ||
return new Uint8Array(data.buffer); | ||
} else if (data instanceof ArrayBuffer) { | ||
// ArrayBuffer | ||
return new Uint8Array(data); | ||
} else throw new Error('Input must be an ArrayBuffer or a TypedArray'); | ||
} | ||
/** | ||
* Check if the given Uint8Array can be expressed in Ascii Text | ||
* @param data | ||
* @return {Uint8Array|string|*} | ||
*/function getAsciiIfAscii(a){if(a instanceof Uint8Array){for(var b=!0,c=0;c<a.length;c++)if(126<a[c]||32>a[c]&&13!==a[c]&&10!==a[c]){b=!1;break}var d=null;if(b){d="";for(var e=0;e<a.length;e++)d+=String.fromCharCode(a[e])}else d=a;return d}throw new Error("Input data must be an Uint8Array")}/** | ||
*/ | ||
function getAsciiIfAscii(data) { | ||
if (data instanceof Uint8Array) { | ||
var flag = true; | ||
for (var i = 0; i < data.length; i++) { | ||
if (data[i] > 0x7e || data[i] < 0x20 && data[i] !== 0x0d && data[i] !== 0x0a) { | ||
flag = false; | ||
break; | ||
} | ||
} | ||
var returnData = null; | ||
if (flag) { | ||
returnData = ''; | ||
for (var _i = 0; _i < data.length; _i++) { | ||
returnData += String.fromCharCode(data[_i]); | ||
} | ||
} else returnData = data; | ||
return returnData; | ||
} else throw new Error('Input data must be an Uint8Array'); | ||
} | ||
/** | ||
* Encode ArrayBuffer or TypedArray to base64url string | ||
* @param data | ||
* @return {string} | ||
*/function encodeBase64Url(a){return encodeBase64(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}/** | ||
*/ | ||
function encodeBase64Url(data) { | ||
return encodeBase64(data).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); | ||
} | ||
/** | ||
* Decode Base64Url string to Uint8Array | ||
* @param str | ||
* @return {Uint8Array} | ||
*/function decodeBase64Url(a){if("string"!=typeof a)throw new Error("Input must be string");// str = str + "=".repeat(str.length % 4); // this sometimes causes error... | ||
return a=a.replace(/-/g,"+").replace(/_/g,"/"),decodeBase64(a)}/** | ||
*/ | ||
function decodeBase64Url(str) { | ||
if (typeof str !== 'string') throw new Error('Input must be string'); | ||
str = str.replace(/-/g, '+').replace(/_/g, '/'); // str = str + "=".repeat(str.length % 4); // this sometimes causes error... | ||
return decodeBase64(str); | ||
} | ||
/** | ||
* Encode ArrayBuffer or TypedArray to hex string | ||
* @param data | ||
* @return {string} | ||
*/function arrayBufferToHexString(a){for(var b,c=sanitizeTypedArrayAndArrayBuffer(a),d="",e=0;e<c.length;e++)b=(255&c[e]).toString(16),b=1===b.length?"0".concat(b):b,d+=b;return d}/** | ||
*/ | ||
function arrayBufferToHexString(data) { | ||
var arr = sanitizeTypedArrayAndArrayBuffer(data); | ||
var hexStr = ''; | ||
for (var i = 0; i < arr.length; i++) { | ||
var hex = (arr[i] & 0xff).toString(16); | ||
hex = hex.length === 1 ? "0".concat(hex) : hex; | ||
hexStr += hex; | ||
} | ||
return hexStr; | ||
} | ||
/** | ||
* Decode hex string to Uint8Array | ||
* @param str | ||
* @return {Uint8Array} | ||
*/function hexStringToArrayBuffer(a){if(!a||"string"!=typeof a)throw new Error("Input arg must be a non-null string");for(var b=[],c=a.length,d=0;d<c;d+=2)b.push(parseInt(a.substr(d,2),16));return new Uint8Array(b)}/** | ||
*/ | ||
function hexStringToArrayBuffer(str) { | ||
if (!str || !(typeof str === 'string')) throw new Error('Input arg must be a non-null string'); | ||
var arr = []; | ||
var len = str.length; | ||
for (var i = 0; i < len; i += 2) { | ||
arr.push(parseInt(str.substr(i, 2), 16)); | ||
} | ||
return new Uint8Array(arr); | ||
} | ||
/** | ||
* Encode ArrayBuffer or TypedArray to string with code (like output of legacy atob) | ||
* @param data | ||
* @return {string} | ||
*/function arrayBufferToString(a){var b=sanitizeTypedArrayAndArrayBuffer(a);return String.fromCharCode.apply(null,b)}/** | ||
*/ | ||
function arrayBufferToString(data) { | ||
var bytes = sanitizeTypedArrayAndArrayBuffer(data); | ||
return String.fromCharCode.apply(null, bytes); | ||
} | ||
/** | ||
* Decode string with code (like output of legacy atob) to Uint8Array | ||
* @param str | ||
* @return {Uint8Array} | ||
*/function stringToArrayBuffer(a){if(!a||"string"!=typeof a)throw new Error("Input arg must be a non-null string");for(var b=new Uint8Array(a.length),c=0;c<a.length;c++)b[c]=a.charCodeAt(c);return b} | ||
*/ | ||
function stringToArrayBuffer(str) { | ||
if (!str || !(typeof str === 'string')) throw new Error('Input arg must be a non-null string'); | ||
var bytes = new Uint8Array(str.length); | ||
for (var i = 0; i < str.length; i++) { | ||
bytes[i] = str.charCodeAt(i); | ||
} | ||
return bytes; | ||
} |
@@ -1,6 +0,45 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getEnvBtoa=getEnvBtoa,exports.getEnvAtob=getEnvAtob;/** | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getEnvBtoa = getEnvBtoa; | ||
exports.getEnvAtob = getEnvAtob; | ||
/** | ||
* this module handles the difference between window (browser) and node js for specific functions and libraries. | ||
* env.js | ||
*/function getEnvBtoa(){return"undefined"==typeof window?nodeBtoa:window.btoa;// node | ||
}function getEnvAtob(){return"undefined"==typeof window?nodeAtob:window.atob;// node | ||
}var nodeBtoa=function(a){if("undefined"!=typeof Buffer){var b,c=Object.prototype.toString.call(a).slice(8,-1);return b=Buffer.isBuffer(a)?a:0<=["ArrayBuffer","TypedArray","Uint8Array","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array"].indexOf(c)?Buffer.from(a):Buffer.from(a.toString(),"binary"),b.toString("base64")}throw new Error("UnsupportedEnvironment")},nodeAtob=function(a){if("undefined"!=typeof Buffer)return Buffer.from(a,"base64").toString("binary");throw new Error("UnsupportedEnvironment")}; | ||
*/ | ||
function getEnvBtoa() { | ||
if (typeof window !== 'undefined') return window.btoa; // browser | ||
else return nodeBtoa; // node | ||
} | ||
function getEnvAtob() { | ||
if (typeof window !== 'undefined') return window.atob; // browser | ||
else return nodeAtob; // node | ||
} | ||
var nodeBtoa = function nodeBtoa(str) { | ||
if (typeof Buffer !== 'undefined') { | ||
var buffer; | ||
var type = Object.prototype.toString.call(str).slice(8, -1); | ||
var typedArrays = ['ArrayBuffer', 'TypedArray', 'Uint8Array', 'Int8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array']; | ||
if (Buffer.isBuffer(str)) { | ||
buffer = str; | ||
} else if (typedArrays.indexOf(type) >= 0) { | ||
buffer = Buffer.from(str); | ||
} else { | ||
buffer = Buffer.from(str.toString(), 'binary'); | ||
} | ||
return buffer.toString('base64'); | ||
} else throw new Error('UnsupportedEnvironment'); | ||
}; | ||
var nodeAtob = function nodeAtob(str) { | ||
if (typeof Buffer !== 'undefined') { | ||
return Buffer.from(str, 'base64').toString('binary'); | ||
} else throw new Error('UnsupportedEnvironment'); | ||
}; |
@@ -1,6 +0,34 @@ | ||
"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");Object.defineProperty(exports,"__esModule",{value:!0}),exports.pemToBin=pemToBin,exports.binToPem=binToPem;var encoder=_interopRequireWildcard(require("./encoder.js")),supportedPEMTypes={public:"PUBLIC KEY",private:"PRIVATE KEY",encryptedPrivate:"ENCRYPTED PRIVATE KEY",certificate:"CERTIFICATE",certRequest:"CERTIFICATE REQUEST"};/** | ||
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.pemToBin = pemToBin; | ||
exports.binToPem = binToPem; | ||
var encoder = _interopRequireWildcard(require("./encoder.js")); | ||
/** | ||
* formatter.js | ||
*/ | ||
var supportedPEMTypes = { | ||
'public': 'PUBLIC KEY', | ||
'private': 'PRIVATE KEY', | ||
'encryptedPrivate': 'ENCRYPTED PRIVATE KEY', | ||
'certificate': 'CERTIFICATE', | ||
'certRequest': 'CERTIFICATE REQUEST' | ||
}; | ||
/** | ||
* Convert PEM armored string to Uint8Array | ||
* @param keydataB64Pem | ||
* @return {Uint8Array} | ||
*/function pemToBin(a){var b=dearmorPem(a);return encoder.decodeBase64(b)}/** | ||
*/ | ||
function pemToBin(keydataB64Pem) { | ||
var keydataB64 = dearmorPem(keydataB64Pem); | ||
return encoder.decodeBase64(keydataB64); | ||
} | ||
/** | ||
* Convert ArrayBuffer or TypedArray to PEM armored string with a specified type | ||
@@ -10,3 +38,10 @@ * @param keydata | ||
* @return {string} | ||
*/function binToPem(a,b){var c=encoder.encodeBase64(a);return formatAsPem(c,b)}/** | ||
*/ | ||
function binToPem(keydata, type) { | ||
var keydataB64 = encoder.encodeBase64(keydata); | ||
return formatAsPem(keydataB64, type); | ||
} | ||
/** | ||
* Armor the given Base64 string and return PEM formatted string | ||
@@ -16,9 +51,41 @@ * @param str | ||
* @return {string} | ||
*/function formatAsPem(a,b){if(!a||"string"!=typeof a)throw new Error("Input arg must be a non-null string");if(!b||"string"!=typeof b)throw new Error("Input arg must be a non-null string");if(0>Object.keys(supportedPEMTypes).indexOf(b))throw new Error("Unsupported type");for(var c=supportedPEMTypes[b],d="-----BEGIN ".concat(c,"-----\n");0<a.length;)d+="".concat(a.substring(0,64),"\n"),a=a.substring(64);return d="".concat(d,"-----END ").concat(c,"-----"),d}/** | ||
*/ | ||
function formatAsPem(str, type) { | ||
if (!str || !(typeof str === 'string')) throw new Error('Input arg must be a non-null string'); | ||
if (!type || !(typeof type === 'string')) throw new Error('Input arg must be a non-null string'); | ||
if (Object.keys(supportedPEMTypes).indexOf(type) < 0) throw new Error('Unsupported type'); | ||
var typeString = supportedPEMTypes[type]; | ||
var finalString = "-----BEGIN ".concat(typeString, "-----\n"); | ||
while (str.length > 0) { | ||
finalString += "".concat(str.substring(0, 64), "\n"); | ||
str = str.substring(64); | ||
} | ||
finalString = "".concat(finalString, "-----END ").concat(typeString, "-----"); | ||
return finalString; | ||
} | ||
/** | ||
* Dearmor the given PEM string and return Base64 string | ||
* @param str | ||
* @return {string} | ||
*/function dearmorPem(a){if(!a||"string"!=typeof a)throw new Error("Input arg must be a non-null string");// const beginRegExp = RegExp('^-----[\s]*BEGIN[^-]*KEY-----$', 'gm'); | ||
// const endRegExp = RegExp('^-----[\s]*END[^-]*KEY-----$', 'gm'); | ||
var b=/^-----[s]*BEGIN[^-]*-----$/gm,c=/^-----[s]*END[^-]*-----$/gm;// check if the object starts from 'begin' | ||
try{var d=a.split(b)[1].split(c)[0];return d=d.replace(/\r?\n/g,""),d}catch(a){throw new Error("Invalid format as PEM")}} | ||
*/ | ||
function dearmorPem(str) { | ||
if (!str || !(typeof str === 'string')) throw new Error('Input arg must be a non-null string'); // const beginRegExp = RegExp('^-----[\s]*BEGIN[^-]*KEY-----$', 'gm'); | ||
// const endRegExp = RegExp('^-----[\s]*END[^-]*KEY-----$', 'gm'); | ||
var beginRegExp = RegExp('^-----[\s]*BEGIN[^-]*-----$', 'gm'); | ||
var endRegExp = RegExp('^-----[\s]*END[^-]*-----$', 'gm'); // check if the object starts from 'begin' | ||
try { | ||
var dearmored = str.split(beginRegExp)[1].split(endRegExp)[0]; | ||
dearmored = dearmored.replace(/\r?\n/g, ''); | ||
return dearmored; | ||
} catch (e) { | ||
throw new Error('Invalid format as PEM'); | ||
} | ||
} |
@@ -1,3 +0,25 @@ | ||
"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");var encoder=_interopRequireWildcard(require("./encoder.js"));var formatter=_interopRequireWildcard(require("./formatter.js"));Object.defineProperty(exports,"__esModule",{value:!0}),exports.formatter=exports.encoder=exports.default=void 0;exports.encoder=encoder;exports.formatter=formatter;/** | ||
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.formatter = exports.encoder = exports.default = void 0; | ||
var encoder = _interopRequireWildcard(require("./encoder.js")); | ||
exports.encoder = encoder; | ||
var formatter = _interopRequireWildcard(require("./formatter.js")); | ||
exports.formatter = formatter; | ||
/** | ||
* index.js | ||
**/var _default={encoder:encoder,formatter:formatter};exports.default=_default; | ||
**/ | ||
var _default = { | ||
encoder: encoder, | ||
formatter: formatter | ||
}; | ||
exports.default = _default; |
@@ -1,1 +0,1 @@ | ||
!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.jseu=n():r.jseu=n()}(this,function(){return function(r){var n={};function t(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=n,t.d=function(r,n,e){t.o(r,n)||Object.defineProperty(r,n,{enumerable:!0,get:e})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,n){if(1&n&&(r=t(r)),8&n)return r;if(4&n&&"object"==typeof r&&r&&r.__esModule)return r;var e=Object.create(null);if(t.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:r}),2&n&&"string"!=typeof r)for(var o in r)t.d(e,o,function(n){return r[n]}.bind(null,o));return e},t.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,"a",n),n},t.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},t.p="/Users/jun/ProjectJavaScript/js_buffer_utils/dist",t(t.s=0)}([function(r,n,t){r.exports=t(1)},function(r,n,t){"use strict";t.r(n);var e={};t.r(e),t.d(e,"encodeBase64",function(){return i}),t.d(e,"decodeBase64",function(){return a}),t.d(e,"encodeBase64Url",function(){return s}),t.d(e,"decodeBase64Url",function(){return p}),t.d(e,"arrayBufferToHexString",function(){return d}),t.d(e,"hexStringToArrayBuffer",function(){return l}),t.d(e,"arrayBufferToString",function(){return y}),t.d(e,"stringToArrayBuffer",function(){return g});var o={};t.r(o),t.d(o,"pemToBin",function(){return w}),t.d(o,"binToPem",function(){return m});var u=function(r){if("undefined"!=typeof Buffer){var n=Object.prototype.toString.call(r).slice(8,-1);return(Buffer.isBuffer(r)?r:0<=["ArrayBuffer","TypedArray","Uint8Array","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array"].indexOf(n)?Buffer.from(r):Buffer.from(r.toString(),"binary")).toString("base64")}throw new Error("UnsupportedEnvironment")},f=function(r){if("undefined"!=typeof Buffer)return Buffer.from(r,"base64").toString("binary");throw new Error("UnsupportedEnvironment")};function i(r){var n;return n="string"==typeof r?r:y(r),("undefined"==typeof window?u:window.btoa)(n)}function a(r){return function(r){if(r instanceof Uint8Array){for(var n=!0,t=0;t<r.length;t++)if(126<r[t]||32>r[t]&&13!==r[t]&&10!==r[t]){n=!1;break}var e=null;if(n){e="";for(var o=0;o<r.length;o++)e+=String.fromCharCode(r[o])}else e=r;return e}throw new Error("Input data must be an Uint8Array")}(g(("undefined"==typeof window?f:window.atob)(r)))}function c(r){if(r instanceof Uint8Array)return r;if(ArrayBuffer.isView(r)&&void 0!==r.buffer)return new Uint8Array(r.buffer);if(r instanceof ArrayBuffer)return new Uint8Array(r);throw new Error("Input must be an ArrayBuffer or a TypedArray")}function s(r){return i(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function p(r){if("string"!=typeof r)throw new Error("Input must be string");return a(r=r.replace(/-/g,"+").replace(/_/g,"/"))}function d(r){for(var n,t=c(r),e="",o=0;o<t.length;o++)e+=n=1===(n=(255&t[o]).toString(16)).length?"0".concat(n):n;return e}function l(r){if(!r||"string"!=typeof r)throw new Error("Input arg must be a non-null string");for(var n=[],t=r.length,e=0;e<t;e+=2)n.push(parseInt(r.substr(e,2),16));return new Uint8Array(n)}function y(r){var n=c(r);return String.fromCharCode.apply(null,n)}function g(r){if(!r||"string"!=typeof r)throw new Error("Input arg must be a non-null string");for(var n=new Uint8Array(r.length),t=0;t<r.length;t++)n[t]=r.charCodeAt(t);return n}var b={public:"PUBLIC KEY",private:"PRIVATE KEY",encryptedPrivate:"ENCRYPTED PRIVATE KEY",certificate:"CERTIFICATE",certRequest:"CERTIFICATE REQUEST"};function w(r){return a(function(r){if(!r||"string"!=typeof r)throw new Error("Input arg must be a non-null string");try{var n=r.split(/^-----[s]*BEGIN[^-]*-----$/gm)[1].split(/^-----[s]*END[^-]*-----$/gm)[0];return n=n.replace(/\r?\n/g,"")}catch(r){throw new Error("Invalid format as PEM")}}(r))}function m(r,n){return function(r,n){if(!r||"string"!=typeof r)throw new Error("Input arg must be a non-null string");if(!n||"string"!=typeof n)throw new Error("Input arg must be a non-null string");if(0>Object.keys(b).indexOf(n))throw new Error("Unsupported type");for(var t=b[n],e="-----BEGIN ".concat(t,"-----\n");0<r.length;)e+="".concat(r.substring(0,64),"\n"),r=r.substring(64);return e="".concat(e,"-----END ").concat(t,"-----")}(i(r),n)}t.d(n,"encoder",function(){return e}),t.d(n,"formatter",function(){return o});n.default={encoder:e,formatter:o}}])}); | ||
!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.jseu=n():r.jseu=n()}(this,function(){return function(r){var n={};function t(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=n,t.d=function(r,n,e){t.o(r,n)||Object.defineProperty(r,n,{enumerable:!0,get:e})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,n){if(1&n&&(r=t(r)),8&n)return r;if(4&n&&"object"==typeof r&&r&&r.__esModule)return r;var e=Object.create(null);if(t.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:r}),2&n&&"string"!=typeof r)for(var o in r)t.d(e,o,function(n){return r[n]}.bind(null,o));return e},t.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,"a",n),n},t.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},t.p="/home/circleci/repo/dist",t(t.s=0)}([function(r,n,t){r.exports=t(1)},function(r,n,t){"use strict";t.r(n);var e={};t.r(e),t.d(e,"encodeBase64",function(){return i}),t.d(e,"decodeBase64",function(){return a}),t.d(e,"encodeBase64Url",function(){return p}),t.d(e,"decodeBase64Url",function(){return s}),t.d(e,"arrayBufferToHexString",function(){return d}),t.d(e,"hexStringToArrayBuffer",function(){return l}),t.d(e,"arrayBufferToString",function(){return y}),t.d(e,"stringToArrayBuffer",function(){return g});var o={};t.r(o),t.d(o,"pemToBin",function(){return w}),t.d(o,"binToPem",function(){return E});var u=function(r){if("undefined"!=typeof Buffer){var n=Object.prototype.toString.call(r).slice(8,-1);return(Buffer.isBuffer(r)?r:["ArrayBuffer","TypedArray","Uint8Array","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array"].indexOf(n)>=0?Buffer.from(r):Buffer.from(r.toString(),"binary")).toString("base64")}throw new Error("UnsupportedEnvironment")},f=function(r){if("undefined"!=typeof Buffer)return Buffer.from(r,"base64").toString("binary");throw new Error("UnsupportedEnvironment")};function i(r){var n="";return n="string"==typeof r?r:y(r),("undefined"!=typeof window?window.btoa:u)(n)}function a(r){return function(r){if(r instanceof Uint8Array){for(var n=!0,t=0;t<r.length;t++)if(r[t]>126||r[t]<32&&13!==r[t]&&10!==r[t]){n=!1;break}var e=null;if(n){e="";for(var o=0;o<r.length;o++)e+=String.fromCharCode(r[o])}else e=r;return e}throw new Error("Input data must be an Uint8Array")}(g(("undefined"!=typeof window?window.atob:f)(r)))}function c(r){if(r instanceof Uint8Array)return r;if(ArrayBuffer.isView(r)&&void 0!==r.buffer)return new Uint8Array(r.buffer);if(r instanceof ArrayBuffer)return new Uint8Array(r);throw new Error("Input must be an ArrayBuffer or a TypedArray")}function p(r){return i(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function s(r){if("string"!=typeof r)throw new Error("Input must be string");return a(r=r.replace(/-/g,"+").replace(/_/g,"/"))}function d(r){for(var n=c(r),t="",e=0;e<n.length;e++){var o=(255&n[e]).toString(16);t+=o=1===o.length?"0".concat(o):o}return t}function l(r){if(!r||"string"!=typeof r)throw new Error("Input arg must be a non-null string");for(var n=[],t=r.length,e=0;e<t;e+=2)n.push(parseInt(r.substr(e,2),16));return new Uint8Array(n)}function y(r){var n=c(r);return String.fromCharCode.apply(null,n)}function g(r){if(!r||"string"!=typeof r)throw new Error("Input arg must be a non-null string");for(var n=new Uint8Array(r.length),t=0;t<r.length;t++)n[t]=r.charCodeAt(t);return n}var b={public:"PUBLIC KEY",private:"PRIVATE KEY",encryptedPrivate:"ENCRYPTED PRIVATE KEY",certificate:"CERTIFICATE",certRequest:"CERTIFICATE REQUEST"};function w(r){return a(function(r){if(!r||"string"!=typeof r)throw new Error("Input arg must be a non-null string");var n=RegExp("^-----[s]*BEGIN[^-]*-----$","gm"),t=RegExp("^-----[s]*END[^-]*-----$","gm");try{var e=r.split(n)[1].split(t)[0];return e=e.replace(/\r?\n/g,"")}catch(r){throw new Error("Invalid format as PEM")}}(r))}function E(r,n){return function(r,n){if(!r||"string"!=typeof r)throw new Error("Input arg must be a non-null string");if(!n||"string"!=typeof n)throw new Error("Input arg must be a non-null string");if(Object.keys(b).indexOf(n)<0)throw new Error("Unsupported type");var t=b[n],e="-----BEGIN ".concat(t,"-----\n");for(;r.length>0;)e+="".concat(r.substring(0,64),"\n"),r=r.substring(64);return e="".concat(e,"-----END ").concat(t,"-----")}(i(r),n)}t.d(n,"encoder",function(){return e}),t.d(n,"formatter",function(){return o});n.default={encoder:e,formatter:o}}])}); |
{ | ||
"name": "js-encoding-utils", | ||
"version": "0.2.8", | ||
"version": "0.3.0", | ||
"description": "Miscellaneous Encoding Utilities for Crypto-related Objects in JavaScript", | ||
"main": "dist/jseu.bundle.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha --require @babel/register --recursive $(find test -name '*.spec.js')", | ||
"karma": "./node_modules/.bin/karma start", | ||
"webpack": "./node_modules/.bin/webpack --optimize-minimize --mode production", | ||
"build": "NODE_ENV=production ./node_modules/.bin/babel src -d dist/ --keep-file-extension && npm run webpack" | ||
"flow:version": "npm version --no-git-tag-version", | ||
"release:start": "./node_modules/.bin/can-npm-publish --vorbose && git flow release start v$npm_package_version", | ||
"release:finish": "git flow release finish v$npm_package_version", | ||
"release:push": "git push --all && git push origin v$npm_package_version", | ||
"test": "cross-env NODE_ENV=test nyc mocha --recursive $(find test -name '*.spec.js')", | ||
"test:bundle": "npm run webpack && cross-env TEST_ENV=bundle npm run test", | ||
"karma": "cross-env TEST_ENV=source ./node_modules/.bin/karma start", | ||
"karma:bundle": "npm run webpack && cross-env TEST_ENV=bundle ./node_modules/.bin/karma start", | ||
"karma:window": "npm run webpack && cross-env TEST_ENV=window ./node_modules/.bin/karma start", | ||
"html": "npm run html:source && npm run html:bundle && npm run html:window", | ||
"html:source": "cross-env TEST_ENV=source NODE_ENV=html npm run webpack", | ||
"html:bundle": "cross-env TEST_ENV=bundle NODE_ENV=html npm run webpack", | ||
"html:window": "cross-env TEST_ENV=window NODE_ENV=html npm run webpack", | ||
"webpack": "./node_modules/.bin/webpack --optimize-minimize --mode development --config webpack.dev.js", | ||
"webpack:prod": "cross-env NODE_ENV=production ./node_modules/.bin/webpack --optimize-minimize --mode production --config webpack.prod.js", | ||
"analyze": "cross-env NODE_ENV=production ./node_modules/.bin/webpack --mode production --optimize-minimize --json --config webpack.prod.js | webpack-bundle-size-analyzer", | ||
"build": "cross-env NODE_ENV=production ./node_modules/.bin/babel src -d dist/ --keep-file-extension && npm run webpack:prod" | ||
}, | ||
@@ -30,25 +43,31 @@ "author": "Jun Kurihara", | ||
"devDependencies": { | ||
"@babel/cli": "^7.1.5", | ||
"@babel/core": "^7.1.5", | ||
"@babel/plugin-transform-runtime": "^7.1.0", | ||
"@babel/polyfill": "^7.0.0", | ||
"@babel/preset-env": "^7.1.5", | ||
"@babel/register": "^7.0.0", | ||
"babel-eslint": "^10.0.1", | ||
"babel-loader": "^8.0.4", | ||
"babel-plugin-istanbul": "^5.1.0", | ||
"babel-preset-minify": "^0.5.0", | ||
"chai": "^4.2.0", | ||
"eslint": "^5.8.0", | ||
"karma": "^3.1.1", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-cli": "^1.0.1", | ||
"karma-coverage": "^1.1.2", | ||
"karma-mocha": "^1.3.0", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"karma-webpack": "^3.0.5", | ||
"mocha": "^5.2.0", | ||
"mocha-sinon": "^2.1.0", | ||
"webpack": "^4.25.1", | ||
"webpack-cli": "^3.1.2" | ||
"@babel/cli": "7.1.5", | ||
"@babel/core": "7.1.6", | ||
"@babel/plugin-transform-runtime": "7.1.0", | ||
"@babel/polyfill": "7.0.0", | ||
"@babel/preset-env": "7.1.6", | ||
"@babel/register": "7.0.0", | ||
"babel-eslint": "10.0.1", | ||
"babel-loader": "8.0.4", | ||
"babel-plugin-istanbul": "5.1.0", | ||
"babel-plugin-transform-remove-console": "6.9.4", | ||
"can-npm-publish": "^1.3.1", | ||
"chai": "4.2.0", | ||
"cross-env": "5.2.0", | ||
"eslint": "5.9.0", | ||
"jsdom": "13.0.0", | ||
"karma": "3.1.1", | ||
"karma-chrome-launcher": "2.2.0", | ||
"karma-cli": "1.0.1", | ||
"karma-coverage": "1.1.2", | ||
"karma-mocha": "1.3.0", | ||
"karma-mocha-reporter": "2.2.5", | ||
"karma-webpack": "3.0.5", | ||
"mocha": "5.2.0", | ||
"mocha-sinon": "2.1.0", | ||
"nyc": "13.1.0", | ||
"webpack": "4.26.0", | ||
"webpack-cli": "3.1.2", | ||
"webpack-common-shake": "2.1.0", | ||
"webpack-merge": "4.1.4" | ||
}, | ||
@@ -55,0 +74,0 @@ "dependencies": { |
Miscellaneous Encoding Utilities for Crypto-related Objects in JavaScript | ||
-- | ||
[![npm version](https://badge.fury.io/js/js-encoding-utils.svg)](https://badge.fury.io/js/js-encoding-utils) | ||
[![CircleCI](https://circleci.com/gh/junkurihara/jseu.svg?style=svg)](https://circleci.com/gh/junkurihara/jseu) | ||
[![Dependencies](https://david-dm.org/junkurihara/jseu.svg)](https://david-dm.org/junkurihara/jseu) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/771abd93ae5d986f1e0a/maintainability)](https://codeclimate.com/github/junkurihara/jseu/maintainability) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
> **WARNING**: At this time this solution should be considered suitable for research and experimentation, further code and security review is needed before utilization in a production application. | ||
@@ -6,0 +11,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
21504
9
273
81
29
1