mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
549ce23ce8
* All projects into monorepo * Update CI * More CI updates * Extracted a bunch of things into packages * Publish - insomnia-plugin-base64@1.0.1 - insomnia-plugin-default-headers@1.0.2 - insomnia-plugin-file@1.0.1 - insomnia-plugin-hash@1.0.1 - insomnia-plugin-now@1.0.1 - insomnia-plugin-request@1.0.1 - insomnia-plugin-response@1.0.1 - insomnia-plugin-uuid@1.0.1 - insomnia-cookies@0.0.2 - insomnia-importers@1.5.2 - insomnia-prettify@0.0.3 - insomnia-url@0.0.2 - insomnia-xpath@0.0.2 * A bunch of small fixes * Improved build script * Fixed * Merge dangling files * Usability refactor * Handle duplicate plugin names
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
const crypto = require('crypto');
|
|
|
|
module.exports.templateTags = [{
|
|
name: 'hash',
|
|
displayName: 'Hash',
|
|
description: 'Apply hash to a value',
|
|
args: [
|
|
{
|
|
displayName: 'Algorithm',
|
|
type: 'enum',
|
|
options: [
|
|
{displayName: 'MD5', value: 'md5'},
|
|
{displayName: 'SHA1', value: 'sha1'},
|
|
{displayName: 'SHA256', value: 'sha256'},
|
|
{displayName: 'SHA512', value: 'sha512'}
|
|
]
|
|
},
|
|
{
|
|
displayName: 'Digest Encoding',
|
|
description: 'The encoding of the output',
|
|
type: 'enum',
|
|
options: [
|
|
{displayName: 'Hexadecimal', value: 'hex'},
|
|
{displayName: 'Base64', value: 'base64'}
|
|
]
|
|
},
|
|
{
|
|
displayName: 'Input',
|
|
type: 'string',
|
|
placeholder: 'Value to hash'
|
|
}
|
|
],
|
|
run (context, algorithm, encoding, value = '') {
|
|
if (encoding !== 'hex' && encoding !== 'latin1' && encoding !== 'base64') {
|
|
throw new Error(`Invalid encoding ${encoding}. Choices are hex, latin1, base64`);
|
|
}
|
|
|
|
const valueType = typeof value;
|
|
if (valueType !== 'string') {
|
|
throw new Error(`Cannot hash value of type "${valueType}"`);
|
|
}
|
|
|
|
const hash = crypto.createHash(algorithm);
|
|
hash.update(value || '', 'utf8');
|
|
return hash.digest(encoding);
|
|
}
|
|
}];
|