mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-02-21 19:48:29 +02:00
Add BUFFER_EXTERN() and cleanup hash zero constants.
BUFFER_EXTERN() provides a clean way to create buffer constants. Convert HASH_TYPE_SHA256_ZERO_STR to HASH_TYPE_SHA256_ZERO_BUF to be consistent with HASH_TYPE_SHA1_ZERO_BUF.
This commit is contained in:
parent
66f108ea8a
commit
d51a86c621
@ -20,11 +20,12 @@ Cryptographic Hash
|
||||
/***********************************************************************************************************************************
|
||||
Hashes for zero-length files (i.e., seed value)
|
||||
***********************************************************************************************************************************/
|
||||
static uint8_t hashTypeSha1Zero[HASH_TYPE_SHA1_SIZE] =
|
||||
{0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09};
|
||||
VR_EXTERN_DEFINE const Buffer *const HASH_TYPE_SHA1_ZERO_BUF = BUF(hashTypeSha1Zero, sizeof(hashTypeSha1Zero));
|
||||
|
||||
STRING_EXTERN(HASH_TYPE_SHA256_ZERO_STR, HASH_TYPE_SHA256_ZERO);
|
||||
BUFFER_EXTERN(
|
||||
HASH_TYPE_SHA1_ZERO_BUF, 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf,
|
||||
0xd8, 0x07, 0x09);
|
||||
BUFFER_EXTERN(
|
||||
HASH_TYPE_SHA256_ZERO_BUF, 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27,
|
||||
0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Include local MD5 code
|
||||
|
@ -23,7 +23,7 @@ Hashes for zero-length files (i.e., starting hash)
|
||||
BUFFER_DECLARE(HASH_TYPE_SHA1_ZERO_BUF);
|
||||
#define HASH_TYPE_SHA256_ZERO \
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
STRING_DECLARE(HASH_TYPE_SHA256_ZERO_STR);
|
||||
BUFFER_DECLARE(HASH_TYPE_SHA256_ZERO_BUF);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Hash type sizes
|
||||
|
@ -178,6 +178,11 @@ By convention all buffer constant identifiers are appended with _BUF.
|
||||
#define BUFSTRDEF(stringdef) \
|
||||
BUF((unsigned char *)stringdef, (sizeof(stringdef) - 1))
|
||||
|
||||
// Used to define buffer constants that will be externed using BUFFER_DECLARE(). Must be used in a .c file.
|
||||
#define BUFFER_EXTERN(name, ...) \
|
||||
static const uint8_t name##_RAW[] = {__VA_ARGS__}; \
|
||||
VR_EXTERN_DEFINE const Buffer *const name = BUF(name##_RAW, sizeof(name##_RAW));
|
||||
|
||||
// Used to define String Buffer constants that will be externed using BUFFER_DECLARE(). Must be used in a .c file.
|
||||
#define BUFFER_STRDEF_EXTERN(name, string) \
|
||||
VR_EXTERN_DEFINE const Buffer *const name = BUFSTRDEF(string)
|
||||
|
@ -531,8 +531,10 @@ storageS3RequestAsync(StorageS3 *this, const String *verb, const String *path, S
|
||||
// Generate authorization header
|
||||
storageS3Auth(
|
||||
this, verb, path, param.query, storageS3DateTime(time(NULL)), requestHeader,
|
||||
param.content == NULL || bufEmpty(param.content) ?
|
||||
HASH_TYPE_SHA256_ZERO_STR : strNewEncode(encodingHex, cryptoHashOne(hashTypeSha256, param.content)));
|
||||
strNewEncode(
|
||||
encodingHex,
|
||||
param.content == NULL || bufEmpty(param.content) ?
|
||||
HASH_TYPE_SHA256_ZERO_BUF : cryptoHashOne(hashTypeSha256, param.content)));
|
||||
|
||||
// Send request
|
||||
MEM_CONTEXT_PRIOR_BEGIN()
|
||||
|
@ -308,7 +308,8 @@ testRun(void)
|
||||
httpQueryAdd(query, STRDEF("list-type"), STRDEF("2"));
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
storageS3Auth(driver, STRDEF("GET"), STRDEF("/"), query, STRDEF("20170606T121212Z"), header, HASH_TYPE_SHA256_ZERO_STR),
|
||||
storageS3Auth(
|
||||
driver, STRDEF("GET"), STRDEF("/"), query, STRDEF("20170606T121212Z"), header, STRDEF(HASH_TYPE_SHA256_ZERO)),
|
||||
"generate authorization");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderGet(header, STRDEF("authorization")),
|
||||
@ -321,7 +322,8 @@ testRun(void)
|
||||
const Buffer *lastSigningKey = driver->signingKey;
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
storageS3Auth(driver, STRDEF("GET"), STRDEF("/"), query, STRDEF("20170606T121212Z"), header, HASH_TYPE_SHA256_ZERO_STR),
|
||||
storageS3Auth(
|
||||
driver, STRDEF("GET"), STRDEF("/"), query, STRDEF("20170606T121212Z"), header, STRDEF(HASH_TYPE_SHA256_ZERO)),
|
||||
"generate authorization");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderGet(header, STRDEF("authorization")),
|
||||
@ -335,7 +337,8 @@ testRun(void)
|
||||
TEST_TITLE("change date to generate new signing key");
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
storageS3Auth(driver, STRDEF("GET"), STRDEF("/"), query, STRDEF("20180814T080808Z"), header, HASH_TYPE_SHA256_ZERO_STR),
|
||||
storageS3Auth(
|
||||
driver, STRDEF("GET"), STRDEF("/"), query, STRDEF("20180814T080808Z"), header, STRDEF(HASH_TYPE_SHA256_ZERO)),
|
||||
"generate authorization");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderGet(header, STRDEF("authorization")),
|
||||
@ -371,7 +374,8 @@ testRun(void)
|
||||
TEST_TITLE("auth with token");
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
storageS3Auth(driver, STRDEF("GET"), STRDEF("/"), query, STRDEF("20170606T121212Z"), header, HASH_TYPE_SHA256_ZERO_STR),
|
||||
storageS3Auth(
|
||||
driver, STRDEF("GET"), STRDEF("/"), query, STRDEF("20170606T121212Z"), header, STRDEF(HASH_TYPE_SHA256_ZERO)),
|
||||
"generate authorization");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderGet(header, STRDEF("authorization")),
|
||||
|
Loading…
x
Reference in New Issue
Block a user