1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00
pgbackrest/libc/xs/crypto/hash.xs
David Steele 4815752ccc Add Perl interface to C storage layer.
Maintaining the storage layer/drivers in two languages is burdensome.  Since the integration tests require the Perl storage layer/drivers we'll need them even after the core code is migrated to C.  Create an interface layer so the Perl code can be removed and new storage drivers/features introduced without adding Perl equivalents.

The goal is to move the integration tests to C so this interface will eventually be removed.  That being the case, the interface was designed for maximum compatibility to ease the transition.  The result looks a bit hacky but we'll improve it as needed until it can be retired.
2019-06-26 08:24:58 -04:00

32 lines
1.1 KiB
Plaintext

####################################################################################################################################
# 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