#!/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.

## style-ok: no-strict - sourced fragment.

## 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
# shellcheck source=../../../../helper-scripts/usr/libexec/helper-scripts/strings.bsh
source "${HELPER_SCRIPTS_PATH:-}/usr/libexec/helper-scripts/strings.bsh"

msgcollector_check() {
  local variable_to_check
  variable_to_check="$1"

  check_is_not_empty_and_only_one_line variable_to_check || return 1

  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 || true
    return 1
  fi

  check_is_alpha_numeric variable_to_check || return 1

  return 0
}
