+ Add base64 encode/decode.
+
diff --git a/libc/LibC.xs b/libc/LibC.xs
index 0ff4e6d95..ac0bb7fad 100644
--- a/libc/LibC.xs
+++ b/libc/LibC.xs
@@ -25,6 +25,7 @@ C includes
These includes are from the src directory. There is no Perl-specific code in them.
***********************************************************************************************************************************/
+#include "common/encode.h"
#include "common/error.h"
#include "config/config.h"
#include "config/configRule.h"
@@ -35,6 +36,13 @@ Helper macros
***********************************************************************************************************************************/
#include "LibC.h"
+/***********************************************************************************************************************************
+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/common/encode.xsh"
+
/***********************************************************************************************************************************
Constant include
@@ -58,6 +66,7 @@ INCLUDE: const-xs.inc
#
# These modules should map 1-1 with C modules in src directory.
# ----------------------------------------------------------------------------------------------------------------------------------
+INCLUDE: xs/common/encode.xs
INCLUDE: xs/config/config.xs
INCLUDE: xs/config/configRule.xs
INCLUDE: xs/postgres/pageChecksum.xs
diff --git a/libc/Makefile.PL b/libc/Makefile.PL
index 7f2fb352b..29f1505ad 100644
--- a/libc/Makefile.PL
+++ b/libc/Makefile.PL
@@ -101,6 +101,17 @@ my $rhExport =
libCVersion
)],
},
+
+ 'encode' =>
+ {
+ &BLD_EXPORTTYPE_CONSTANT => [qw(
+ ENCODE_TYPE_BASE64
+ )],
+
+ &BLD_EXPORTTYPE_SUB => [qw(
+ encodeToStr decodeToBin
+ )],
+ },
};
####################################################################################################################################
diff --git a/libc/xs/common/encode.xs b/libc/xs/common/encode.xs
new file mode 100644
index 000000000..d41c69da6
--- /dev/null
+++ b/libc/xs/common/encode.xs
@@ -0,0 +1,48 @@
+# ----------------------------------------------------------------------------------------------------------------------------------
+# Binary to String Encode/Decode Perl Exports
+# ----------------------------------------------------------------------------------------------------------------------------------
+
+MODULE = pgBackRest::LibC PACKAGE = pgBackRest::LibC
+
+####################################################################################################################################
+SV *
+encodeToStr(encodeType, source)
+ int encodeType
+ SV *source
+CODE:
+ RETVAL = NULL;
+
+ STRLEN sourceSize;
+ unsigned char *sourcePtr = (unsigned char *)SvPV(source, sourceSize);
+
+ ERROR_XS_BEGIN()
+ {
+ RETVAL = newSV(encodeToStrSize(encodeType, sourceSize));
+ SvPOK_only(RETVAL);
+
+ encodeToStr(encodeType, sourcePtr, sourceSize, (char *)SvPV_nolen(RETVAL));
+ SvCUR_set(RETVAL, encodeToStrSize(encodeType, sourceSize));
+ }
+ ERROR_XS_END();
+OUTPUT:
+ RETVAL
+
+####################################################################################################################################
+SV *
+decodeToBin(encodeType, source)
+ int encodeType
+ const char *source
+CODE:
+ RETVAL = NULL;
+
+ ERROR_XS_BEGIN()
+ {
+ RETVAL = newSV(decodeToBinSize(encodeType, source));
+ SvPOK_only(RETVAL);
+
+ decodeToBin(encodeType, source, (unsigned char *)SvPV_nolen(RETVAL));
+ SvCUR_set(RETVAL, decodeToBinSize(encodeType, source));
+ }
+ ERROR_XS_END();
+OUTPUT:
+ RETVAL
diff --git a/libc/xs/common/encode.xsh b/libc/xs/common/encode.xsh
new file mode 100644
index 000000000..65f60aabc
--- /dev/null
+++ b/libc/xs/common/encode.xsh
@@ -0,0 +1,7 @@
+/***********************************************************************************************************************************
+Binary to String Encode/Decode XS Header
+***********************************************************************************************************************************/
+#include "../src/common/encode.h"
+
+// Encode types
+#define ENCODE_TYPE_BASE64 ((int)encodeBase64)
diff --git a/src/common/encode.c b/src/common/encode.c
new file mode 100644
index 000000000..1933fb524
--- /dev/null
+++ b/src/common/encode.c
@@ -0,0 +1,102 @@
+/***********************************************************************************************************************************
+Binary to String Encode/Decode
+***********************************************************************************************************************************/
+#include