From f9d0b56f97f65cb8b1a84a078192f9142ec0d1d1 Mon Sep 17 00:00:00 2001 From: _cry64 Date: Wed, 21 Jan 2026 15:35:11 +1000 Subject: [PATCH] introduce isnumeric function --- ceru/libceru.sh | 2 ++ ceru/subcmds/new/password | 4 +--- ceru/subcmds/new/ssh-key | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ceru/libceru.sh b/ceru/libceru.sh index 24dca94..05e945d 100755 --- a/ceru/libceru.sh +++ b/ceru/libceru.sh @@ -100,6 +100,8 @@ function confirm-file-overwrite { [[ "$OVERWRITE" = false ]] || confirm } +function isnumeric { [[ "$1" =~ ^[0-9]+$ ]]; } + # ====== Core ====== function run-subcmd { # if CMD_MIN is empty, then CMD_MAJ is the root cmd (ie ceru) diff --git a/ceru/subcmds/new/password b/ceru/subcmds/new/password index ae640e7..12cc871 100755 --- a/ceru/subcmds/new/password +++ b/ceru/subcmds/new/password @@ -214,11 +214,9 @@ esac unset -f perr-unsupportedhash perr-forbiddenhash perr-recommendhash # ensure $ROUNDS is a valid numeric -re='^[0-9]+$' -if ! [[ "$ROUNDS" =~ ^[0-9]+$ ]] ; then +if ! isnumeric "$ROUNDS"; then throw-badval 1 "$ROUNDS" '-r|--rounds' fi -unset -v re # Acquire password from stdin if [[ "$STDIN" == true ]]; then diff --git a/ceru/subcmds/new/ssh-key b/ceru/subcmds/new/ssh-key index 7e8605b..eeda49d 100755 --- a/ceru/subcmds/new/ssh-key +++ b/ceru/subcmds/new/ssh-key @@ -81,6 +81,10 @@ while [[ $# -gt 0 ]]; do done; unset -v ARG EXTRA='' +# ensure $ROUNDS is a valid numeric +if ! isnumeric "$ROUNDS"; then + throw-badval 1 "$ROUNDS" '-r|--rounds' +fi case "$TYPE" in ed25519) @@ -93,6 +97,9 @@ case "$TYPE" in ;; esac +if ! isnumeric "$BITS"; then + throw-badval 1 "$BITS" '-b|--bits' +fi if [[ "$HWKEY" == true ]]; then if [[ "$TYPE" == "rsa" ]]; then