@kyfe/decrypt
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,2 +0,2 @@ | ||
import { getValue, isString } from '../utils' | ||
import { getValue, isString, isObject } from '../utils' | ||
import { decryptMask } from './mask' | ||
@@ -19,9 +19,10 @@ import { decryptVirtual } from './virtual' | ||
} | ||
this.bindMethodThis() | ||
} | ||
/** | ||
/** | ||
* @overview 获取不同加密类型key | ||
* @param {key} 数据key名称 | ||
*/ | ||
getMaskKey(key) { | ||
getMaskKey(key) { | ||
const { MASK_KEY } = this.config | ||
@@ -40,4 +41,5 @@ return `${key}${MASK_KEY}` | ||
isEncryptedByString(d = {}, key) { | ||
if (!isObject(d)) d = d + '' | ||
const val = isString(d) ? d : getValue(key, d) | ||
if (!val) return | ||
if (!val) return false | ||
const { ENCRYPTE_MASK_SYMBOL, ENCRYPTE_MASKSEC_SYMBOL } = this.config | ||
@@ -53,2 +55,3 @@ return !!matchEncrypteSymbol(val, ENCRYPTE_MASK_SYMBOL) || !!matchEncrypteSymbol(val, ENCRYPTE_MASKSEC_SYMBOL) | ||
isEncrypteStatus(d, key) { | ||
if (!isObject(d)) d = d + '' | ||
if (d && isString(d)) { | ||
@@ -58,3 +61,3 @@ return this.isEncryptedByString(d) | ||
const plaintext = getValue(key, d) | ||
return this.getEncrypteText(d, key) && this.isEncryptedByString(plaintext) | ||
return !!(this.getEncrypteText(d, key) && this.isEncryptedByString(plaintext)) | ||
} | ||
@@ -69,6 +72,7 @@ } | ||
isEncrypted(d, key) { | ||
if (!isObject(d)) d = d + '' | ||
if (d && isString(d)) { | ||
return this.isEncryptedByString(d) | ||
} else { | ||
return !!this.getEncrypteText(d, key) | ||
return this.isMask(d, key) || this.isVirtual(d, key) || this.isMaskSec(d, key) | ||
} | ||
@@ -92,3 +96,4 @@ } | ||
isMask(d, key) { | ||
return !!this.getMaskVal(d, key) | ||
const decryptKey = this.getMaskKey(key) | ||
return this.isHasEncryptKey(d, decryptKey) | ||
} | ||
@@ -106,3 +111,4 @@ getMaskVal(d, key) { | ||
isVirtual(d, key) { | ||
return !!this.getVirtualVal(d, key) | ||
const decryptKey = this.getVirtualkey(key) | ||
return this.isHasEncryptKey(d, decryptKey) | ||
} | ||
@@ -120,4 +126,10 @@ getVirtualVal(d, key) { | ||
isMaskSec(d, key) { | ||
return !!this.getMaskSecVal(d, key) | ||
const decryptKey = this.getMaskSeckey(key) | ||
return this.isHasEncryptKey(d, decryptKey) | ||
} | ||
/** | ||
* @overview 通过内容字符串判断是否敏感字段 | ||
* @param {d} 数据对象 | ||
* @param {key} 数据key名称 | ||
*/ | ||
isMaskSecByString(d, key) { | ||
@@ -134,2 +146,3 @@ const val = this.getValue(d, key) | ||
/** | ||
@@ -160,3 +173,24 @@ * @overview 解密方法 | ||
/** | ||
* @overview 是否存在加密key | ||
* @param {d} 数据对象 | ||
* @param {key} 数据key名称 | ||
*/ | ||
isHasEncryptKey(obj, key) { | ||
if (!obj || !key) return false | ||
const keys = key.split('.') | ||
let current = obj | ||
for (const key of keys) { | ||
if (!current || !Object.prototype.hasOwnProperty.call(current, key)) { | ||
return false | ||
} | ||
current = current[key] | ||
} | ||
return true | ||
} | ||
getValue(d, key) { | ||
if (!isObject(d)) d = d + '' | ||
return isString(d) ? d : getValue(key, d) | ||
@@ -171,3 +205,15 @@ } | ||
} | ||
/** | ||
* @overview 关于this的绑定 | ||
*/ | ||
bindMethodThis() { | ||
const methods = Object.getOwnPropertyNames(DecryptApi.prototype).filter( | ||
prop => typeof this[prop] === 'function' && prop !== 'constructor' | ||
) | ||
for (const method of methods) { | ||
this[method] = this[method].bind(this) | ||
} | ||
} | ||
} | ||
@@ -164,3 +164,2 @@ let maxDecryptConfig = {} | ||
const isLock = this.keyLockMaps[key] | ||
console.log('采集') | ||
// 只有配置了最大解密才去记录 | ||
@@ -167,0 +166,0 @@ if (this.getMaxDecryptNumByKey(key)) { |
{ | ||
"name": "@kyfe/decrypt", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -81,2 +81,11 @@ export const getValue = (key, obj, getSourceOfKey) => { | ||
return is('Boolean', true)(item); | ||
} | ||
/** | ||
* @method 检测当前类型是否是对象 | ||
* @param item 检测当前类型 | ||
* @returns { Boolean } 如果是对象则返回true、否则返回false | ||
*/ | ||
export function isObject(item) { | ||
return is('Object')(item); | ||
} |
16697
557