moved helpers separately

This commit is contained in:
2026-10-13 16:21:24 +02:00
parent ba1e07744e
commit 9911f6d01d
33 changed files with 1489 additions and 1089 deletions
+3 -39
View File
@@ -36,41 +36,9 @@
load_conf "pwd"
# ------------------------------------------------------------------------------
# Internal helper: put in _PWD_RAND an integer uniformly distributed in
# [0, $1), for 1 <= $1 <= 2^32. $RANDOM is NOT usable for passwords: it only
# has 15 bits, a state seeded from the time and the PID, and is predictable.
# The source is $SRANDOM (bash >= 5.1, from the kernel's random generator), or
# else /dev/urandom read through od, 256 words at a time to limit the number
# of processes. Values above the largest multiple of $1 are rejected, so that
# "% $1" introduces no bias.
# Usage: _pwd_rand <max>
_pwd_rand()
{
local max="$1" limit r
limit=$(( 4294967296 - 4294967296 % max ))
while :; do
if [[ -n "${SRANDOM+x}" ]]; then
r="$SRANDOM"
else
if (( ${#_PWD_POOL[@]} == 0 )); then
# shellcheck disable=SC2207 # whitespace-separated numbers
_PWD_POOL=( $(od -An -v -N1024 -tu4 /dev/urandom 2>/dev/null) )
if (( ${#_PWD_POOL[@]} == 0 )); then
disp E "No source of random numbers available (/dev/urandom)."
return 1
fi
fi
r="${_PWD_POOL[-1]}"
unset '_PWD_POOL[-1]'
fi
if (( r < limit )); then
_PWD_RAND=$(( r % max ))
return 0
fi
done
}
_PWD_POOL=()
# Common helpers, then the ones private to this module (helpers/pwd.sh)
declare -F _profile_load_helpers >/dev/null || . "$(dirname -- "${BASH_SOURCE[0]}")/../helpers/common.sh"
_profile_load_helpers "${BASH_SOURCE[0]}"
# ------------------------------------------------------------------------------
# genpwd : generate a password with different criteria
@@ -332,9 +300,6 @@ genpwd()
done
}
export -f genpwd
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# pwdscore : score a password quality from 1 to 100
# Usage: pwdscore [options] <password>
@@ -541,5 +506,4 @@ pwdscore()
export -f pwdscore
# ------------------------------------------------------------------------------
# EOF