Source
for (pc = p_str, pc_r = *p_b64str; 0 != full_block_num; pc += c_per_block, pc_r += b_per_block, full_block_num--)
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**********************************************************************
* Purpose: Check if supplied character is a valid base64 character. *
* Not a complete check, since it ignores equal sign '=' *
* as it depends on the context where this is placed. *
* Corresponds to the [A-Za-z0-9+\\/] block validation from *
* zbx_base64_validate() function below. *
**********************************************************************/
static int is_valid_base64_char(const char c)
{
if (('A' <= c && 'Z' >= c) ||
('a' <= c && 'z' >= c) ||
('/' <= c && '9' >= c) ||
'+' == c)
{
return SUCCEED;
}
return FAIL;
}
/*************************************************************************************************
* *
* Purpose: Checks if the string is a valid Base64 encoded string. *
* Check is based on RFC 4648, based on the following regexp: *
* "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$" *
* *
* Note, that pcre regexp matching cannot be used, because it would exceed max *
* stack frame limit when recursively checking long strings, *
* (check compute_recursion_limit() for more details). *
* *
* Parameters: p_str - [IN] string to validate *
* *
* Return value: SUCCEED - string is a valid Base64 encoded string *
* FAIL - otherwise *
* *
*************************************************************************************************/
int zbx_base64_validate(const char *p_str)
{
size_t i;
/* consider empty strings - valid Base64 encodings */
if ('\0' == p_str[0])
return SUCCEED;