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;
wt_api, session,
"nop encryption: %s: %s", msg, wt_api->
strerror(wt_api, NULL, err));
return (err);
}
static int
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 *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
{
NOP_ENCRYPTOR *nop_encryptor = (NOP_ENCRYPTOR *)encryptor;
(void)session;
++nop_encryptor->nop_calls;
*expansion_constantp = 0;
return (0);
}
static int
{
const NOP_ENCRYPTOR *orig;
NOP_ENCRYPTOR *new;
int ret;
orig = (const NOP_ENCRYPTOR *)encryptor;
wt_api = orig->wt_api;
if ((new = calloc(1, sizeof(*new))) == NULL)
return (errno);
*new = *orig;
ret = wt_api->
config_get(wt_api, session, encrypt_config,
"keyid", &keyid);
if (ret != 0)
ret = wt_api->
config_get(wt_api, session, encrypt_config,
"secretkey", &secretkey);
if (ret != 0)
if (keyid.
len != 0 && secretkey.
len != 0) {
ret = nop_error(
new, NULL, EINVAL, "nop_customize: keys specified with both keyid= and secretkey=");
goto err;
}
if (keyid.
len == 0 && secretkey.
len == 0)
(void)keyid;
return (0);
err:
free(new);
return (ret);
}
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.customize = nop_customize;
nop_encryptor->encryptor.terminate = nop_terminate;
0)
return (0);
free(nop_encryptor);
return (ret);
}