Skip to content

Commit

Permalink
Minor improvement to validate_hash()
Browse files Browse the repository at this point in the history
Simply use parameter 1.

Add comments for validate_hash_block

Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Mar 3, 2022
1 parent 0d583f0 commit 346adb1
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions easytls
Original file line number Diff line number Diff line change
Expand Up @@ -1637,28 +1637,40 @@ validate_hash ()
return 1
}

test_hash="${1}"
test_length="${#test_hash}"
#validate_hash_block="$(( validate_hash_block + 1 ))"
#if [ -z "${auto_check}" ]; then
# easytls_verbose "General use - validate_hash (${validate_hash_block})"
# [ "${validate_hash_block}" -lt 2 ] || {
# error_msg "validate_hash must only run twice"
# return 1
# }
#else
# easytls_verbose "auto_check - validate_hash (${validate_hash_block})"
# #validate_hash_block="$(( validate_hash_block - 1 ))"
#fi

#test_hash="${1}"
#test_length="${#test_hash}"

# Verify length
[ "${test_length}" -eq "${fixed_length}" ] || {
error_msg "validate_hash - test_length: ${test_length}"
unset -v test_hash test_length
[ "${#1}" -eq "${fixed_length}" ] || {
error_msg "validate_hash - test_length: ${#test_hash}"
unset -v test_hash #test_length
return 1
}

# Verify hash is hex only
# Any error will contain non-hex chars (hopefully)
[ "${test_hash}" = "${test_hash%[!0123456789abcdefABCDEF]*}" ] || {
[ "${1}" = "${1%[!0123456789abcdefABCDEF]*}" ] || {
error_msg "validate_hash - !hex"
unset -v test_hash test_length
unset -v test_hash #test_length
return 1
}

# Test for empty input hash
[ "${test_hash}" != "${forbidden_hash}" ] || {
[ "${1}" != "${forbidden_hash}" ] || {
error_msg "validate_hash - forbidden_hash"
unset -v test_hash test_length
unset -v test_hash #test_length
return 1
}

Expand Down

1 comment on commit 346adb1

@TinCanTech
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.