diff options
Diffstat (limited to 'src/bin/pg_verifybackup/parse_manifest.c')
-rw-r--r-- | src/bin/pg_verifybackup/parse_manifest.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/bin/pg_verifybackup/parse_manifest.c b/src/bin/pg_verifybackup/parse_manifest.c index 608e23538b..5b4ce28837 100644 --- a/src/bin/pg_verifybackup/parse_manifest.c +++ b/src/bin/pg_verifybackup/parse_manifest.c @@ -624,7 +624,7 @@ verify_manifest_checksum(JsonManifestParseState *parse, char *buffer, size_t number_of_newlines = 0; size_t ultimate_newline = 0; size_t penultimate_newline = 0; - pg_sha256_ctx manifest_ctx; + pg_cryptohash_ctx *manifest_ctx; uint8 manifest_checksum_actual[PG_SHA256_DIGEST_LENGTH]; uint8 manifest_checksum_expected[PG_SHA256_DIGEST_LENGTH]; @@ -652,9 +652,15 @@ verify_manifest_checksum(JsonManifestParseState *parse, char *buffer, "last line not newline-terminated"); /* Checksum the rest. */ - pg_sha256_init(&manifest_ctx); - pg_sha256_update(&manifest_ctx, (uint8 *) buffer, penultimate_newline + 1); - pg_sha256_final(&manifest_ctx, manifest_checksum_actual); + manifest_ctx = pg_cryptohash_create(PG_SHA256); + if (manifest_ctx == NULL) + context->error_cb(context, "out of memory"); + if (pg_cryptohash_init(manifest_ctx) < 0) + context->error_cb(context, "could not initialize checksum of manifest"); + if (pg_cryptohash_update(manifest_ctx, (uint8 *) buffer, penultimate_newline + 1) < 0) + context->error_cb(context, "could not update checksum of manifest"); + if (pg_cryptohash_final(manifest_ctx, manifest_checksum_actual) < 0) + context->error_cb(context, "could not finalize checksum of manifest"); /* Now verify it. */ if (parse->manifest_checksum == NULL) @@ -667,6 +673,7 @@ verify_manifest_checksum(JsonManifestParseState *parse, char *buffer, if (memcmp(manifest_checksum_actual, manifest_checksum_expected, PG_SHA256_DIGEST_LENGTH) != 0) context->error_cb(context, "manifest checksum mismatch"); + pg_cryptohash_free(manifest_ctx); } /* |