Skip to content

Commit

Permalink
Refactor in several files
Browse files Browse the repository at this point in the history
  • Loading branch information
pplanel committed Apr 27, 2021
1 parent 4950911 commit 3a8b30a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/hash_calc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:
- master

jobs:
# unit tests
# test action works running from the graph
test:
runs-on: ubuntu-latest
steps:
Expand All @@ -18,3 +16,6 @@ jobs:
with:
input: pplanel
method: SHA512
- name: print output
run: |
echo This is the output ${{steps.hash.outputs.digest}}
7 changes: 4 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ branding:
color: gray-dark
runs:
using: 'node12'
main: 'dist/index.js'
main: '../dist/index.js'
inputs:
method:
required: true
description: The algorithm used to hash the input str\wing. Check docs for all available methods.
description: The algorithm used to hash the input string. Check docs for all available methods.
input:
required: true
description: Input string to be converted.j
description: Input string to be converted
output_len:
required: false
description: When choosing MD3(Keccak) you can optionally choose its output length. Default is 512 bits.
default: -1
outputs:
digest:
description: Generated hash based on input and hash method.
20 changes: 9 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions generator.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const HashAlgorithmFactory = require('./lib/hash_algorithm_factory')

let generator = function (hash_type, input_str, hash_output_length=undefined) {
let generator = function (hash_type, input_str, hash_output_length) {
return new Promise((resolve) => {

const hash_algo = HashAlgorithmFactory
.getHashAlgorithm(hash_type)

if (hash_type === 'SHA3' || hash_type === 'SHA-3') {
const hashed_string = hash_algo(input_str, hash_output_length)
.toString()
if (['SHA3', 'SHA-3'].includes(hash_type)) {
const hashed_string = hash_algo(input_str, hash_output_length).toString()

resolve(hashed_string)
}
resolve(hashed_string + 'asda')
} else if(hash_output_length > 0){

throw new Error("output_len can only be set in SHA3 mode.");
}

const hashed_string = hash_algo(input_str)
.toString()
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function run() {
try {
const input = core.getInput('input');
const method = core.getInput('method');
const output_length = core.getInput('output_length');
const output_length = core.getInput('output_len');

let output_string = await generator(method, input, output_length)
core.setOutput('digest', output_string.toString());
Expand Down

0 comments on commit 3a8b30a

Please sign in to comment.