Shows the basic framework for building an encryptor as a plug in library.
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <wiredtiger.h>
#include <wiredtiger_ext.h>
typedef struct {
unsigned long nop_calls;
} NOP_ENCRYPTOR;
static int
nop_error(
NOP_ENCRYPTOR *encryptor,
WT_SESSION *session,
int err,
const char *msg)
{
wt_api = encryptor->wt_api;
"nop encryption: %s: %s", msg, wt_api->
strerror(wt_api, NULL, err));
return (err);
}
static int
uint8_t *src, size_t src_len,
uint8_t *dst, size_t dst_len,
size_t *result_lenp)
{
NOP_ENCRYPTOR *nop_encryptor = (NOP_ENCRYPTOR *)encryptor;
(void)session;
++nop_encryptor->nop_calls;
if (dst_len < src_len)
return (nop_error(nop_encryptor, session,
ENOMEM, "encrypt buffer not big enough"));
memcpy(dst, src, src_len);
*result_lenp = src_len;
return (0);
}
static int
uint8_t *src, size_t src_len,
uint8_t *dst, size_t dst_len,
size_t *result_lenp)
{
NOP_ENCRYPTOR *nop_encryptor = (NOP_ENCRYPTOR *)encryptor;
(void)session;
(void)src_len;
++nop_encryptor->nop_calls;
memcpy(dst, src, dst_len);
*result_lenp = dst_len;
return (0);
}
static int
size_t *expansion_constantp)
{
NOP_ENCRYPTOR *nop_encryptor = (NOP_ENCRYPTOR *)encryptor;
(void)session;
++nop_encryptor->nop_calls;
*expansion_constantp = 0;
return (0);
}
static int
{
NOP_ENCRYPTOR *nop_encryptor = (NOP_ENCRYPTOR *)encryptor;
(void)session;
++nop_encryptor->nop_calls;
free(encryptor);
return (0);
}
int
{
NOP_ENCRYPTOR *nop_encryptor;
int ret;
(void)config;
if ((nop_encryptor = calloc(1, sizeof(NOP_ENCRYPTOR))) == NULL)
return (errno);
nop_encryptor->encryptor.encrypt = nop_encrypt;
nop_encryptor->encryptor.decrypt = nop_decrypt;
nop_encryptor->encryptor.sizing = nop_sizing;
nop_encryptor->encryptor.terminate = nop_terminate;
connection,
"nop", (
WT_ENCRYPTOR *)nop_encryptor, NULL)) == 0)
return (0);
free(nop_encryptor);
return (ret);
}