+validateInput() {
+ # Desc: Validates Input
+ # Usage: validateInput [str input] [str input type]
+ # Version: 0.3.1
+ # Input: arg1: string to validate
+ # arg2: string specifying input type (ex:"ssh_pubkey")
+ # Output: return code 0: if input string matched specified string type
+ # Depends: bash 5, yell()
+
+ local fn argInput argType
+
+ # Save function name
+ fn="${FUNCNAME[0]}";
+
+ # Process arguments
+ argInput="$1";
+ argType="$2";
+ if [[ $# -gt 2 ]]; then yell "ERROR:$0:$fn:Too many arguments."; exit 1; fi;
+
+ # Check for blank
+ if [[ -z "$argInput" ]]; then return 1; fi
+
+ # Define input types
+ ## ssh_pubkey
+ ### Check for alnum/dash base64 (ex: "ssh-rsa AAAAB3NzaC1yc2EAAA")
+ if [[ "$argType" = "ssh_pubkey" ]]; then
+ if [[ "$argInput" =~ ^[[:alnum:]-]*[\ ]*[[:alnum:]+/=]*$ ]]; then
+ return 0; fi; fi;
+
+ ## age_pubkey
+ ### Check for age1[:bech32:]
+ if [[ "$argType" = "age_pubkey" ]]; then
+ if [[ "$argInput" =~ ^age1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*$ ]]; then
+ return 0; fi; fi
+
+ ## integer
+ if [[ "$argType" = "integer" ]]; then
+ if [[ "$argInput" =~ ^[[:digit:]]*$ ]]; then
+ return 0; fi; fi;
+
+ ## time element (year, month, week, day, hour, minute, second)
+ if [[ "$argType" = "time_element" ]]; then
+ if [[ "$argInput" = "year" ]] || \
+ [[ "$argInput" = "month" ]] || \
+ [[ "$argInput" = "week" ]] || \
+ [[ "$argInput" = "day" ]] || \
+ [[ "$argInput" = "hour" ]] || \
+ [[ "$argInput" = "minute" ]] || \
+ [[ "$argInput" = "second" ]]; then
+ return 0; fi; fi;
+
+ # Return error if no condition matched.
+ return 1;
+} # Validates strings