Skip to content
Permalink
Browse files

Extern infoHash() so it can be used by other modules.

This is currently needed only for testing, but there's no reason not to expose the function to everyone.
  • Loading branch information...
dwsteele committed Apr 23, 2019
1 parent cddb0c0 commit aebac47cd5fa21f6e62ee3dce3ef13abf59ca61f
Showing with 31 additions and 20 deletions.
  1. +4 −0 doc/xml/release.xml
  2. +24 −18 src/info/info.c
  3. +1 −0 src/info/info.h
  4. +1 −1 test/src/module/command/infoTest.c
  5. +1 −1 test/src/module/info/infoBackupTest.c
@@ -45,6 +45,10 @@
<p>Add <code>iniSave()</code> and <code>iniMove()</code> to <code>Ini</code> object.</p>
</release-item>

<release-item>
<p>Extern <code>infoHash()</code> so it can be used by other modules.</p>
</release-item>

<release-item>
<p><code>varNewKv()</code> accepts a <code>KeyValue</code> object rather than creating one.</p>
</release-item>
@@ -41,9 +41,9 @@ struct Info
};

/***********************************************************************************************************************************
Return a hash of the contents of the info file
Generate hash for the contents of an ini file
***********************************************************************************************************************************/
static CryptoHash *
String *
infoHash(const Ini *ini)
{
FUNCTION_TEST_BEGIN();
@@ -52,14 +52,15 @@ infoHash(const Ini *ini)

ASSERT(ini != NULL);

CryptoHash *result = cryptoHashNew(HASH_TYPE_SHA1_STR);
String *result = NULL;

MEM_CONTEXT_TEMP_BEGIN()
{
StringList *sectionList = iniSectionList(ini);
CryptoHash *hash = cryptoHashNew(HASH_TYPE_SHA1_STR);
StringList *sectionList = strLstSort(iniSectionList(ini), sortOrderAsc);

// Initial JSON opening bracket
cryptoHashProcessC(result, (const unsigned char *)"{", 1);
cryptoHashProcessC(hash, (const unsigned char *)"{", 1);

// Loop through sections and create hash for checking checksum
for (unsigned int sectionIdx = 0; sectionIdx < strLstSize(sectionList); sectionIdx++)
@@ -68,14 +69,14 @@ infoHash(const Ini *ini)

// Add a comma before additional sections
if (sectionIdx != 0)
cryptoHashProcessC(result, (const unsigned char *)",", 1);
cryptoHashProcessC(hash, (const unsigned char *)",", 1);

// Create the section header
cryptoHashProcessC(result, (const unsigned char *)"\"", 1);
cryptoHashProcessStr(result, section);
cryptoHashProcessC(result, (const unsigned char *)"\":{", 3);
cryptoHashProcessC(hash, (const unsigned char *)"\"", 1);
cryptoHashProcessStr(hash, section);
cryptoHashProcessC(hash, (const unsigned char *)"\":{", 3);

StringList *keyList = iniSectionKeyList(ini, section);
StringList *keyList = strLstSort(iniSectionKeyList(ini, section), sortOrderAsc);
unsigned int keyListSize = strLstSize(keyList);

// Loop through values and build the section
@@ -87,21 +88,26 @@ infoHash(const Ini *ini)
if ((strEq(section, INFO_SECTION_BACKREST_STR) && !strEq(key, INFO_KEY_CHECKSUM_STR)) ||
!strEq(section, INFO_SECTION_BACKREST_STR))
{
cryptoHashProcessC(result, (const unsigned char *)"\"", 1);
cryptoHashProcessStr(result, key);
cryptoHashProcessC(result, (const unsigned char *)"\":", 2);
cryptoHashProcessStr(result, iniGet(ini, section, strLstGet(keyList, keyIdx)));
cryptoHashProcessC(hash, (const unsigned char *)"\"", 1);
cryptoHashProcessStr(hash, key);
cryptoHashProcessC(hash, (const unsigned char *)"\":", 2);
cryptoHashProcessStr(hash, iniGet(ini, section, strLstGet(keyList, keyIdx)));

if ((keyListSize > 1) && (keyIdx < keyListSize - 1))
cryptoHashProcessC(result, (const unsigned char *)",", 1);
cryptoHashProcessC(hash, (const unsigned char *)",", 1);
}
}

// Close the key/value list
cryptoHashProcessC(result, (const unsigned char *)"}", 1);
cryptoHashProcessC(hash, (const unsigned char *)"}", 1);
}

// JSON closing bracket
cryptoHashProcessC(result, (const unsigned char *)"}", 1);
cryptoHashProcessC(hash, (const unsigned char *)"}", 1);

memContextSwitch(MEM_CONTEXT_OLD());
result = bufHex(cryptoHash(hash));
memContextSwitch(MEM_CONTEXT_TEMP());
}
MEM_CONTEXT_TEMP_END();

@@ -161,7 +167,7 @@ infoLoad(Info *this, const Storage *storage, bool copyFile, CipherType cipherTyp

// Make sure the ini is valid by testing the checksum
const String *infoChecksumJson = iniGet(this->ini, INFO_SECTION_BACKREST_STR, INFO_KEY_CHECKSUM_STR);
const String *checksum = bufHex(cryptoHash(infoHash(this->ini)));
const String *checksum = infoHash(this->ini);

if (strSize(infoChecksumJson) == 0)
{
@@ -31,6 +31,7 @@ Getters
***********************************************************************************************************************************/
const String *infoCipherPass(const Info *this);
String *infoFileName(const Info *this);
String *infoHash(const Ini *ini);
Ini *infoIni(const Info *this);

/***********************************************************************************************************************************
@@ -227,7 +227,7 @@ testRun(void)
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"2edbac400200cc0bd559951f1ee166de5c6f5f49\"\n"
"backrest-checksum=\"c68d528a1b28f6ef1c370955ac8915eab737d402\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
@@ -98,7 +98,7 @@ testRun(void)
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"b944d83dcfa33ac0eb88d41b16efc5aaa5da7ec1\"\n"
"backrest-checksum=\"7f77f7a8efc72bd99b1a20022b6db50d4cbd72fa\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"

0 comments on commit aebac47

Please sign in to comment.
You can’t perform that action at this time.