@hclsoftware/secagent
Version:
IAST agent
65 lines (54 loc) • 1.74 kB
JavaScript
//IASTIGNORE
/*
* ****************************************************
* Licensed Materials - Property of HCL.
* (c) Copyright HCL Technologies Ltd. 2017, 2025.
* Note to U.S. Government Users *Restricted Rights.
* ****************************************************
*/
const crypto = require('crypto')
module.exports.createHashObject = () => {
//const hash = crypto.origCreateHash('sha1')
const hash = crypto.createHash('sha256')
hash.produce = function () { return this.digest('base64') }
return hash
}
module.exports.PASSWORD_TEXT = "**CONFIDENTIAL**"
module.exports.acornOptions = {
ecmaVersion: 2020,
locations: true,
ranges: true,
sourceType: 'script',
allowHashBang: true,
allowReturnOutsideFunction: true,
allowImportExportEverywhere: true,
allowAwaitOutsideFunction: true
}
module.exports.copyObject = (obj) => {
return Object.assign(Object.create(Object.getPrototypeOf(obj)), obj)
}
module.exports.getClassName = (instance) => {
if (instance == null) {
return null
}
if (typeof instance === "string") {
// when that is null in our proxy trap we set it to be the imported module name, e.g:
// const { exec } = require('child_process'); exec(command); => we set that = 'child_process'
// Therefore, if instance is of type string we conclude it is already represents the class name.
return instance
}
if (typeof instance === "function") {
return instance.prototype && instance.prototype.constructor ? instance.prototype.constructor.name : null
}
return instance.constructor ? instance.constructor.name : null
}
module.exports.isJSONStr = (str) => {
try {
JSON.origParse(str)
return true
}
catch (e) {
return false
}
}