You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-05-22 10:15:16 +02:00
Remove dependency on LibC hash filter.
Perl provides Digest::SHA for hashing so there is no need to expose this via LibC anymore.
This commit is contained in:
@@ -8,6 +8,7 @@ use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use Digest::SHA qw(sha1_hex);
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw();
|
||||
use File::Basename qw(dirname);
|
||||
@@ -17,7 +18,6 @@ use Storable qw(dclone);
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::Common::String;
|
||||
use pgBackRest::LibC qw(:crypto);
|
||||
use pgBackRest::Version;
|
||||
|
||||
####################################################################################################################################
|
||||
@@ -563,7 +563,7 @@ sub hash
|
||||
|
||||
# Set the new checksum
|
||||
$self->{oContent}{&INI_SECTION_BACKREST}{&INI_KEY_CHECKSUM} =
|
||||
cryptoHashOne('sha1', JSON::PP->new()->canonical()->allow_nonref()->encode($self->{oContent}));
|
||||
sha1_hex(JSON::PP->new()->canonical()->allow_nonref()->encode($self->{oContent}));
|
||||
|
||||
return $self->{oContent}{&INI_SECTION_BACKREST}{&INI_KEY_CHECKSUM};
|
||||
}
|
||||
|
||||
@@ -323,11 +323,6 @@ sub libcAutoExportTag
|
||||
'cfgOptionTotal',
|
||||
],
|
||||
|
||||
crypto =>
|
||||
[
|
||||
'cryptoHashOne',
|
||||
],
|
||||
|
||||
debug =>
|
||||
[
|
||||
'libcUvSize',
|
||||
|
||||
@@ -52,8 +52,6 @@ use constant STORAGE_FILTER_CIPHER_BLOCK => 'pgBackRe
|
||||
push @EXPORT, qw(STORAGE_FILTER_CIPHER_BLOCK);
|
||||
use constant STORAGE_FILTER_GZ => 'pgBackRest::Storage::Filter::Gz';
|
||||
push @EXPORT, qw(STORAGE_FILTER_GZ);
|
||||
use constant STORAGE_FILTER_SHA => 'pgBackRest::Storage::Filter::Sha';
|
||||
push @EXPORT, qw(STORAGE_FILTER_SHA);
|
||||
|
||||
####################################################################################################################################
|
||||
# Capability constants
|
||||
|
||||
@@ -9,6 +9,7 @@ use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use Digest::SHA qw(sha1_hex);
|
||||
use File::Basename qw(dirname);
|
||||
use Fcntl qw(:mode);
|
||||
use File::stat qw{lstat};
|
||||
@@ -172,17 +173,20 @@ sub hashSize
|
||||
my $lSize;
|
||||
|
||||
# Is this an IO object or a file expression?
|
||||
my $oFileIo = ref($xFileExp) ? $xFileExp : $self->openRead($xFileExp, {bIgnoreMissing => $bIgnoreMissing});
|
||||
my $rtContent = $self->get($xFileExp, {bIgnoreMissing => $bIgnoreMissing});
|
||||
|
||||
# Add size and sha filters
|
||||
$oFileIo->{oStorageCRead}->filterAdd(COMMON_IO_HANDLE, undef);
|
||||
$oFileIo->{oStorageCRead}->filterAdd(STORAGE_FILTER_SHA, undef);
|
||||
|
||||
# Read the file and set results if it exists
|
||||
if ($self->{oStorageC}->readDrain($oFileIo->{oStorageCRead}))
|
||||
if (defined($rtContent))
|
||||
{
|
||||
$strHash = $oFileIo->result(STORAGE_FILTER_SHA);
|
||||
$lSize = $oFileIo->result(COMMON_IO_HANDLE);
|
||||
if (defined($$rtContent))
|
||||
{
|
||||
$strHash = sha1_hex($$rtContent);
|
||||
$lSize = length($$rtContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
$strHash = sha1_hex('');
|
||||
$lSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
# Return from function and log return values if any
|
||||
|
||||
@@ -48,7 +48,6 @@ C includes
|
||||
|
||||
These includes are from the src directory. There is no Perl-specific code in them.
|
||||
***********************************************************************************************************************************/
|
||||
#include "common/crypto/common.h"
|
||||
#include "common/error.h"
|
||||
#include "common/io/io.h"
|
||||
#include "config/config.h"
|
||||
@@ -67,7 +66,6 @@ XSH includes
|
||||
|
||||
These includes define data structures that are required for the C to Perl interface but are not part of the regular C source.
|
||||
***********************************************************************************************************************************/
|
||||
#include "xs/crypto/hash.xsh"
|
||||
#include "xs/config/configTest.xsh"
|
||||
#include "xs/postgres/client.xsh"
|
||||
#include "xs/storage/storage.xsh"
|
||||
@@ -96,7 +94,6 @@ OUTPUT:
|
||||
INCLUDE: xs/config/config.xs
|
||||
INCLUDE: xs/config/configTest.xs
|
||||
INCLUDE: xs/config/define.xs
|
||||
INCLUDE: xs/crypto/hash.xs
|
||||
INCLUDE: xs/postgres/client.xs
|
||||
INCLUDE: xs/storage/storage.xs
|
||||
INCLUDE: xs/storage/storageRead.xs
|
||||
|
||||
@@ -94,13 +94,6 @@ my $rhExport =
|
||||
)],
|
||||
},
|
||||
|
||||
'crypto' =>
|
||||
{
|
||||
&BLD_EXPORTTYPE_SUB => [qw(
|
||||
cryptoHashOne
|
||||
)],
|
||||
},
|
||||
|
||||
'debug' =>
|
||||
{
|
||||
&BLD_EXPORTTYPE_SUB => [qw(
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
####################################################################################################################################
|
||||
# Cryptographic Hashes Perl Exports
|
||||
#
|
||||
# XS wrapper for functions in cipher/hash.c.
|
||||
####################################################################################################################################
|
||||
|
||||
MODULE = pgBackRest::LibC PACKAGE = pgBackRest::LibC
|
||||
|
||||
####################################################################################################################################
|
||||
SV *
|
||||
cryptoHashOne(type, message)
|
||||
const char *type
|
||||
SV *message
|
||||
CODE:
|
||||
RETVAL = NULL;
|
||||
|
||||
MEM_CONTEXT_XS_TEMP_BEGIN()
|
||||
{
|
||||
STRLEN messageSize;
|
||||
const void *messagePtr = SvPV(message, messageSize);
|
||||
|
||||
String *hash = bufHex(cryptoHashOne(strNew(type), BUF(messagePtr, messageSize)));
|
||||
|
||||
RETVAL = newSV(strSize(hash));
|
||||
SvPOK_only(RETVAL);
|
||||
strcpy((char *)SvPV_nolen(RETVAL), strPtr(hash));
|
||||
SvCUR_set(RETVAL, strSize(hash));
|
||||
}
|
||||
MEM_CONTEXT_XS_TEMP_END();
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
@@ -1,4 +0,0 @@
|
||||
/***********************************************************************************************************************************
|
||||
Cryptographic Hashes XS Header
|
||||
***********************************************************************************************************************************/
|
||||
#include "common/crypto/hash.h"
|
||||
@@ -124,10 +124,6 @@ storageFilterXsAdd(IoFilterGroup *filterGroup, const String *filter, const Strin
|
||||
varUInt64Force(varLstGet(paramList, 0)) ? cipherModeEncrypt : cipherModeDecrypt,
|
||||
cipherType(varStr(varLstGet(paramList, 1))), BUFSTR(varStr(varLstGet(paramList, 2))), NULL));
|
||||
}
|
||||
else if (strEqZ(filter, "pgBackRest::Storage::Filter::Sha"))
|
||||
{
|
||||
ioFilterGroupAdd(filterGroup, cryptoHashNew(HASH_TYPE_SHA1_STR));
|
||||
}
|
||||
else if (strEqZ(filter, "pgBackRest::Common::Io::Handle"))
|
||||
{
|
||||
ioFilterGroupAdd(filterGroup, ioSizeNew());
|
||||
@@ -151,11 +147,7 @@ storageFilterXsResult(const IoFilterGroup *filterGroup, const String *filter)
|
||||
{
|
||||
const Variant *result;
|
||||
|
||||
if (strEqZ(filter, "pgBackRest::Storage::Filter::Sha"))
|
||||
{
|
||||
result = ioFilterGroupResult(filterGroup, CRYPTO_HASH_FILTER_TYPE_STR);
|
||||
}
|
||||
else if (strEqZ(filter, "pgBackRest::Common::Io::Handle"))
|
||||
if (strEqZ(filter, "pgBackRest::Common::Io::Handle"))
|
||||
{
|
||||
result = ioFilterGroupResult(filterGroup, SIZE_FILTER_TYPE_STR);
|
||||
}
|
||||
@@ -182,11 +174,7 @@ storageFilterXsResultAll(const IoFilterGroup *filterGroup)
|
||||
const String *filter = varStr(varLstGet(filterList, filterIdx));
|
||||
const String *filterPerl = NULL;
|
||||
|
||||
if (strEq(filter, CRYPTO_HASH_FILTER_TYPE_STR))
|
||||
{
|
||||
filterPerl = strNew("pgBackRest::Storage::Filter::Sha");
|
||||
}
|
||||
else if (strEq(filter, SIZE_FILTER_TYPE_STR))
|
||||
if (strEq(filter, SIZE_FILTER_TYPE_STR))
|
||||
{
|
||||
filterPerl = strNew("pgBackRest::Common::Io::Handle");
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
|
||||
use Digest::SHA qw(sha1_hex);
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw();
|
||||
use Storable qw(dclone);
|
||||
@@ -19,7 +20,6 @@ use pgBackRest::Archive::Common;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::Config::Config;
|
||||
use pgBackRest::DbVersion;
|
||||
use pgBackRest::LibC qw(:crypto);
|
||||
use pgBackRest::Protocol::Storage::Helper;
|
||||
|
||||
use pgBackRestTest::Env::Host::HostBackupTest;
|
||||
@@ -492,7 +492,7 @@ sub walGenerateContentChecksum
|
||||
{name => 'hParam', required => false, trace => true},
|
||||
);
|
||||
|
||||
return cryptoHashOne('sha1', ${$self->walGenerateContent($strPgVersion, $hParam)});
|
||||
return sha1_hex(${$self->walGenerateContent($strPgVersion, $hParam)});
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
@@ -513,7 +513,7 @@ sub walGenerate
|
||||
|
||||
my $rtWalContent = $self->walGenerateContent($strPgVersion, {iSourceNo => $iSourceNo});
|
||||
my $strWalFile =
|
||||
"${strWalPath}/${strWalSegment}" . ($bChecksum ? '-' . cryptoHashOne('sha1', $rtWalContent) : '') .
|
||||
"${strWalPath}/${strWalSegment}" . ($bChecksum ? '-' . sha1_hex($rtWalContent) : '') .
|
||||
(defined($bPartial) && $bPartial ? '.partial' : '');
|
||||
|
||||
# Put the WAL segment and the ready file
|
||||
|
||||
Reference in New Issue
Block a user