1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Do not expose valid/validate functions from encode module.

These functions have never been used externally. Validation is always part of decoding so performing validation separately would be wasteful.
This commit is contained in:
David Steele 2021-02-19 18:25:50 -05:00
parent edab2a0b89
commit f6c3262861
3 changed files with 6 additions and 61 deletions

View File

@ -316,48 +316,3 @@ decodeToBinSize(EncodeType type, const char *source)
FUNCTION_TEST_RETURN(destinationSize);
}
/**********************************************************************************************************************************/
bool
decodeToBinValid(EncodeType type, const char *source)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, type);
FUNCTION_TEST_PARAM(STRINGZ, source);
FUNCTION_TEST_END();
bool valid = true;
TRY_BEGIN()
{
decodeToBinValidate(type, source);
}
CATCH(FormatError)
{
valid = false;
}
TRY_END();
FUNCTION_TEST_RETURN(valid);
}
/**********************************************************************************************************************************/
void
decodeToBinValidate(EncodeType type, const char *source)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, type);
FUNCTION_TEST_PARAM(STRINGZ, source);
FUNCTION_TEST_END();
ASSERT_ENCODE_TYPE_VALID(type);
switch (type)
{
case encodeBase64:
decodeToBinValidateBase64(source);
break;
}
FUNCTION_TEST_RETURN_VOID();
}

View File

@ -1,7 +1,5 @@
/***********************************************************************************************************************************
Binary to String Encode/Decode
These high-level functions are preferred to the low-level functions for each encoding type in the encode subdirectory.
***********************************************************************************************************************************/
#ifndef COMMON_ENCODE_H
#define COMMON_ENCODE_H
@ -13,7 +11,7 @@ Encoding types
***********************************************************************************************************************************/
typedef enum
{
encodeBase64
encodeBase64,
} EncodeType;
/***********************************************************************************************************************************
@ -31,10 +29,4 @@ void decodeToBin(EncodeType type, const char *source, unsigned char *destination
// Size of the binary data returned by decodeToBin()
size_t decodeToBinSize(EncodeType type, const char *source);
// Check that the encoded string is valid
bool decodeToBinValid(EncodeType type, const char *source);
// Validate the encoded string
void decodeToBinValidate(EncodeType type, const char *source);
#endif

View File

@ -89,15 +89,13 @@ testRun(void)
decodeToBin(encodeBase64, "cc$=", destinationDecode), FormatError, "base64 invalid character found at position 2");
// -------------------------------------------------------------------------------------------------------------------------
TEST_ERROR(decodeToBinValidate(encodeBase64, "c3"), FormatError, "base64 size 2 is not evenly divisible by 4");
TEST_ERROR(decodeToBin(encodeBase64, "c3", destinationDecode), FormatError, "base64 size 2 is not evenly divisible by 4");
TEST_ERROR(
decodeToBinValidate(encodeBase64, "c==="), FormatError, "base64 '=' character may only appear in last two positions");
decodeToBin(encodeBase64, "c===", destinationDecode), FormatError,
"base64 '=' character may only appear in last two positions");
TEST_ERROR(
decodeToBinValidate(encodeBase64, "cc=c"), FormatError, "base64 last character must be '=' if second to last is");
// -------------------------------------------------------------------------------------------------------------------------
TEST_RESULT_BOOL(decodeToBinValid(encodeBase64, "CCCCCCCCCCC"), false, "base64 string not valid");
TEST_RESULT_BOOL(decodeToBinValid(encodeBase64, "CCCCCCCCCCCC"), true, "base64 string valid");
decodeToBin(encodeBase64, "cc=c", destinationDecode), FormatError,
"base64 last character must be '=' if second to last is");
}
FUNCTION_HARNESS_RESULT_VOID();