@ridi/parser-core
Advanced tools
Comparing version 0.6.2 to 0.6.3
@@ -23,2 +23,4 @@ 'use strict'; | ||
var _cryptoUtil = require('./cryptoUtil'); | ||
var _errors = require('./errors'); | ||
@@ -42,90 +44,6 @@ | ||
/* eslint-disable no-bitwise, no-plusplus */ | ||
var pad = _cryptoJs2.default.pad, | ||
enc = _cryptoJs2.default.enc, | ||
aesMode = _cryptoJs2.default.mode, | ||
var aesMode = _cryptoJs2.default.mode, | ||
AES = _cryptoJs2.default.AES; | ||
var Pkcs7 = pad.Pkcs7; | ||
var Utf8 = enc.Utf8, | ||
Hex = enc.Hex; | ||
var Padding = (0, _freeze2.default)({ | ||
AUTO: { | ||
name: 'auto', | ||
op: Pkcs7, | ||
pad: function pad(data) { | ||
return Pkcs7.pad(data, 4); | ||
}, | ||
unpad: Pkcs7.unpad | ||
}, | ||
PKCS7: { | ||
name: 'pkcs7', | ||
op: pad.Pkcs7, | ||
pad: function pad(data) { | ||
return Pkcs7.pad(data, 4); | ||
}, | ||
unpad: Pkcs7.unpad | ||
}, | ||
NONE: { | ||
name: 'none', | ||
op: pad.NoPadding | ||
} | ||
}); | ||
var Uint8 = { | ||
decode: function decode(uint8Array) { | ||
var len = uint8Array.length; | ||
var words = []; | ||
var i = 0; | ||
while (i < len) { | ||
words.push(uint8Array[i++] << 24 | uint8Array[i++] << 16 | uint8Array[i++] << 8 | uint8Array[i++]); | ||
} | ||
return _cryptoJs2.default.lib.WordArray.create(words, words.length * 4); | ||
}, | ||
encode: function encode(wordArray) { | ||
var words = wordArray.words, | ||
sigBytes = wordArray.sigBytes; | ||
var uint8Array = new Uint8Array(sigBytes); | ||
var offset = 0; | ||
var word = void 0; | ||
for (var i = 0; i < words.length; i++) { | ||
word = words[i]; | ||
uint8Array[offset++] = word >> 24; | ||
uint8Array[offset++] = word >> 16 & 0xff; | ||
uint8Array[offset++] = word >> 8 & 0xff; | ||
uint8Array[offset++] = word & 0xff; | ||
} | ||
return uint8Array; | ||
} | ||
}; | ||
var Encoding = (0, _freeze2.default)({ | ||
UTF8: { | ||
name: 'utf8', | ||
decode: Utf8.parse, | ||
encode: Utf8.stringify | ||
}, | ||
HEX: { | ||
name: 'hex', | ||
decode: Hex.parse, | ||
encode: Hex.stringify | ||
}, | ||
UINT8: { | ||
name: 'uint8', | ||
decode: Uint8.decode, | ||
encode: Uint8.encode | ||
}, | ||
BUFFER: { | ||
name: 'buffer', | ||
decode: function decode(data) { | ||
return Uint8.decode(new Uint8Array(data)); | ||
}, | ||
encode: function encode(data) { | ||
return Buffer.from(Uint8.encode(data)); | ||
} | ||
} | ||
}); | ||
var defaultConfigTypes = { | ||
@@ -213,10 +131,10 @@ key: 'String|Buffer|Uint8Array|Array' | ||
key = Encoding.UTF8.decode(key); | ||
key = _cryptoUtil.Encoding.UTF8.decode(key); | ||
if (length % 16 !== 0) { | ||
Padding.PKCS7.pad(key); | ||
_cryptoUtil.Padding.PKCS7.pad(key); | ||
} | ||
} else if (Buffer.isBuffer(key)) { | ||
key = Encoding.BUFFER.decode(key); | ||
key = _cryptoUtil.Encoding.BUFFER.decode(key); | ||
} else if (key instanceof Uint8Array || key instanceof Array) { | ||
key = Encoding.UINT8.decode(key); | ||
key = _cryptoUtil.Encoding.UINT8.decode(key); | ||
} | ||
@@ -226,5 +144,5 @@ | ||
if (Buffer.isBuffer(iv)) { | ||
iv = Encoding.BUFFER.decode(iv); | ||
iv = _cryptoUtil.Encoding.BUFFER.decode(iv); | ||
} else if (iv instanceof Uint8Array || iv instanceof Array) { | ||
iv = Encoding.UINT8.decode(iv); | ||
iv = _cryptoUtil.Encoding.UINT8.decode(iv); | ||
} | ||
@@ -241,3 +159,3 @@ | ||
// return operator | ||
var options = { iv: iv, mode: mode.op, padding: Padding.NONE.op }; | ||
var options = { iv: iv, mode: mode.op, padding: _cryptoUtil.Padding.NONE.op }; | ||
return { // Note that all data and return type is a WordArray | ||
@@ -258,4 +176,4 @@ name: mode.name, | ||
var padding = options.padding || Padding.NONE; | ||
var encoding = options.encoding || Encoding.BUFFER; | ||
var padding = options.padding || _cryptoUtil.Padding.NONE; | ||
var encoding = options.encoding || _cryptoUtil.Encoding.BUFFER; | ||
var length = (0, _typecheck.isExists)(data) && (0, _typecheck.isExists)(data.length) ? data.length : 0; | ||
@@ -265,11 +183,11 @@ | ||
if ((0, _typecheck.isString)(data)) { | ||
data = Encoding.UTF8.decode(data); | ||
data = _cryptoUtil.Encoding.UTF8.decode(data); | ||
} else if (Buffer.isBuffer(data)) { | ||
data = Encoding.BUFFER.decode(data); | ||
data = _cryptoUtil.Encoding.BUFFER.decode(data); | ||
} else if (data instanceof Uint8Array || data instanceof Array) { | ||
data = Encoding.UINT8.decode(data); | ||
data = _cryptoUtil.Encoding.UINT8.decode(data); | ||
} | ||
// padding data if needed as padding type | ||
if (padding === Padding.PKCS7 || padding === Padding.AUTO && length % 16 !== 0) { | ||
if (padding === _cryptoUtil.Padding.PKCS7 || padding === _cryptoUtil.Padding.AUTO && length % 16 !== 0) { | ||
padding.pad(data); | ||
@@ -285,10 +203,10 @@ } | ||
var padding = options.padding || Padding.NONE; | ||
var encoding = options.encoding || Encoding.BUFFER; | ||
var padding = options.padding || _cryptoUtil.Padding.NONE; | ||
var encoding = options.encoding || _cryptoUtil.Encoding.BUFFER; | ||
// convert data to WordArray | ||
if (Buffer.isBuffer(data)) { | ||
data = Encoding.BUFFER.decode(data); | ||
data = _cryptoUtil.Encoding.BUFFER.decode(data); | ||
} else if (data instanceof Uint8Array || data instanceof Array) { | ||
data = Encoding.UINT8.decode(data); | ||
data = _cryptoUtil.Encoding.UINT8.decode(data); | ||
} | ||
@@ -300,5 +218,5 @@ | ||
// unpadding data if needed as padding type | ||
if (padding === Padding.PKCS7 || padding === Padding.AUTO) { | ||
if (padding === _cryptoUtil.Padding.PKCS7 || padding === _cryptoUtil.Padding.AUTO) { | ||
try { | ||
var array = Encoding.UINT8.encode(decryptedData); | ||
var array = _cryptoUtil.Encoding.UINT8.encode(decryptedData); | ||
if (array.length < 16) { | ||
@@ -319,3 +237,3 @@ throw (0, _errors.createError)(_errors2.default.ECRYT, 'invalid data length'); | ||
} catch (e) { | ||
if (padding !== Padding.AUTO) { | ||
if (padding !== _cryptoUtil.Padding.AUTO) { | ||
throw (0, _errors.createError)(_errors2.default.ECRYT, e.message); | ||
@@ -333,4 +251,4 @@ } | ||
AesCryptor.Padding = Padding; | ||
AesCryptor.Encoding = Encoding; | ||
AesCryptor.Padding = _cryptoUtil.Padding; | ||
AesCryptor.Encoding = _cryptoUtil.Encoding; | ||
AesCryptor.Mode = Mode; | ||
@@ -337,0 +255,0 @@ |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.Version = exports.openZip = exports.validateOptions = exports.isUrl = exports.isString = exports.isObject = exports.isFunc = exports.isExists = exports.isBool = exports.isArray = exports.getType = exports.stringContains = exports.MatchOption = exports.conditionally = exports.readEntries = exports.getPathes = exports.safePathJoin = exports.safePath = exports.safeDirname = exports.Parser = exports.parseBool = exports.mergeObjects = exports.LogLevel = exports.Logger = exports.mustOverride = exports.createError = exports.Errors = exports.CryptoProvider = exports.AesCryptor = exports.writeCacheFile = exports.readCacheFile = exports.removeAllCacheFiles = exports.removeCacheFile = exports.getCachePath = exports.trimEnd = exports.trimStart = exports.trim = undefined; | ||
exports.Version = exports.openZip = exports.validateOptions = exports.isUrl = exports.isString = exports.isObject = exports.isFunc = exports.isExists = exports.isBool = exports.isArray = exports.getType = exports.stringContains = exports.MatchOption = exports.conditionally = exports.readEntries = exports.getPathes = exports.safePathJoin = exports.safePath = exports.safeDirname = exports.Parser = exports.parseBool = exports.mergeObjects = exports.LogLevel = exports.Logger = exports.Hash = exports.mustOverride = exports.createError = exports.Errors = exports.CryptoProvider = exports.AesCryptor = exports.writeCacheFile = exports.readCacheFile = exports.removeAllCacheFiles = exports.removeCacheFile = exports.getCachePath = exports.trimEnd = exports.trimStart = exports.trim = undefined; | ||
@@ -21,2 +21,4 @@ var _bufferUtil = require('./bufferUtil'); | ||
var _cryptoUtil = require('./cryptoUtil'); | ||
var _errors = require('./errors'); | ||
@@ -81,2 +83,3 @@ | ||
exports.mustOverride = _errors.mustOverride; | ||
exports.Hash = _cryptoUtil.Hash; | ||
exports.Logger = _Logger2.default; | ||
@@ -83,0 +86,0 @@ exports.LogLevel = _Logger.LogLevel; |
{ | ||
"name": "@ridi/parser-core", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"description": "Utilities for parsers", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90875
25
2241