You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-11-11 01:42:26 +03:00
Library code for repository encryption support.
This commit is contained in:
32
test/src/module/cipher/randomTest.c
Normal file
32
test/src/module/cipher/randomTest.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/***********************************************************************************************************************************
|
||||
Test Random
|
||||
***********************************************************************************************************************************/
|
||||
#include "common/memContext.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Test Run
|
||||
***********************************************************************************************************************************/
|
||||
void testRun()
|
||||
{
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
if (testBegin("randomBytes()"))
|
||||
{
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
// Test if the buffer was overrun
|
||||
int bufferSize = 256;
|
||||
char *buffer = memNew(bufferSize);
|
||||
|
||||
randomBytes(buffer, bufferSize);
|
||||
TEST_RESULT_BOOL(buffer[bufferSize] == 0, true, "check that buffer did not overrun (though random byte could be 0)");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
// Count bytes that are not zero (there shouldn't be all zeroes)
|
||||
int nonZeroTotal = 0;
|
||||
|
||||
for (int charIdx = 0; charIdx < bufferSize; charIdx++)
|
||||
if (buffer[charIdx] != 0)
|
||||
nonZeroTotal++;
|
||||
|
||||
TEST_RESULT_INT_NE(nonZeroTotal, 0, "check that there are non-zero values in the buffer");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user