#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## Shared input validation for msgcollector scripts.
## Source this file to get the check() function and strings.bsh utilities.

## provides: check_is_not_empty_and_only_one_line
## provides: check_is_alpha_numeric
## provides: validate_safe_filename
## provides: is_whole_number
## provides: read_integer_file
source /usr/libexec/helper-scripts/strings.bsh

check() {
  ## NOTE: 'local variable_to_check="$1"' is intentionally avoided.
  ## 'local' always returns 0, which would clobber '$?' if we ever
  ## needed it, and separating declaration from assignment is the
  ## project convention for all other variables.
  local variable_to_check
  variable_to_check="$1"

  check_is_not_empty_and_only_one_line variable_to_check

  if ! printf '%s\n' "${variable_to_check}" | unicode-show >/dev/null; then
    stecho "$0: Invalid character! variable_to_check:" >&2
    printf '%s\n' "'${variable_to_check}'" | unicode-show >&2
    exit 1
  fi

  check_is_alpha_numeric variable_to_check
}
