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);
}
int(* config_get)(WT_EXTENSION_API *wt_api, WT_SESSION *session, WT_CONFIG_ARG *config, const char *key, WT_CONFIG_ITEM *value)
Return the value of a configuration key.
Definition wiredtiger_ext.h:184
const char *(* strerror)(WT_EXTENSION_API *, WT_SESSION *session, int error)
Return information about an error as a string.
Definition wiredtiger_ext.h:100
int(* err_printf)(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *fmt,...)
Insert an error message into the WiredTiger error stream.
Definition wiredtiger_ext.h:76
int wiredtiger_extension_init(WT_CONNECTION *connection, WT_CONFIG_ARG *config)
Entry point to an extension, called when the extension is loaded.
struct WT_CONFIG_ARG WT_CONFIG_ARG
A configuration object passed to some extension interfaces.
Definition wiredtiger.in:4204
The interface implemented by applications to provide custom encryption.
Definition wiredtiger.in:4558
Table of WiredTiger extension methods.
Definition wiredtiger_ext.h:58
The configuration information returned by the WiredTiger configuration parsing functions in the WT_EX...
Definition wiredtiger.in:3827
const char * str
The value of a configuration string.
Definition wiredtiger.in:3838
size_t len
The number of bytes in the value referenced by str.
Definition wiredtiger.in:3841
A connection to a WiredTiger database.
Definition wiredtiger.in:2106
int add_encryptor(WT_CONNECTION *connection, const char *name, WT_ENCRYPTOR *encryptor, const char *config)
Add an encryption function.
WT_EXTENSION_API * get_extension_api(WT_CONNECTION *wt_conn)
Return a reference to the WiredTiger extension functions.
All data operations are performed in the context of a WT_SESSION.
Definition wiredtiger.in:822