72 unsigned char *csrc = (
unsigned char *)
VARDATA_ANY(src);
101 for (p = str; *p; p++)
150 #define EX_MSG(arg) \ 151 ereport(NOTICE, (errmsg( \ 152 "pgp_decrypt: unexpected %s: expected %d got %d", \ 153 CppAsString(arg), ex->arg, ctx->arg))) 155 #define EX_CHECK(arg) do { \ 156 if (ex->arg >= 0 && ex->arg != ctx->arg) EX_MSG(arg); \ 186 if (strcmp(key,
"cipher-algo") == 0)
188 else if (strcmp(key,
"disable-mdc") == 0)
190 else if (strcmp(key,
"sess-key") == 0)
192 else if (strcmp(key,
"s2k-mode") == 0)
194 else if (strcmp(key,
"s2k-count") == 0)
196 else if (strcmp(key,
"s2k-digest-algo") == 0)
198 else if (strcmp(key,
"s2k-cipher-algo") == 0)
200 else if (strcmp(key,
"compress-algo") == 0)
202 else if (strcmp(key,
"compress-level") == 0)
204 else if (strcmp(key,
"convert-crlf") == 0)
206 else if (strcmp(key,
"unicode-mode") == 0)
213 else if (ex != NULL && strcmp(key,
"debug") == 0)
214 ex->
debug = atoi(val);
215 else if (ex != NULL && strcmp(key,
"expect-cipher-algo") == 0)
220 else if (ex != NULL && strcmp(key,
"expect-disable-mdc") == 0)
225 else if (ex != NULL && strcmp(key,
"expect-sess-key") == 0)
230 else if (ex != NULL && strcmp(key,
"expect-s2k-mode") == 0)
235 else if (ex != NULL && strcmp(key,
"expect-s2k-count") == 0)
240 else if (ex != NULL && strcmp(key,
"expect-s2k-digest-algo") == 0)
245 else if (ex != NULL && strcmp(key,
"expect-s2k-cipher-algo") == 0)
250 else if (ex != NULL && strcmp(key,
"expect-compress-algo") == 0)
255 else if (ex != NULL && strcmp(key,
"expect-unicode-mode") == 0)
275 while (*p && (*p ==
' ' || *p ==
'\t' || *p ==
'\n'))
280 if (*p ==
'=' || *p ==
',')
283 while (*p && !(*p ==
' ' || *p ==
'\t' || *p ==
'\n' 284 || *p ==
'=' || *p ==
','))
288 *res_len = p - *res_p;
291 while (*p && (*p ==
' ' || *p ==
'\t' || *p ==
'\n'))
305 char *res =
palloc(len + 1);
307 for (i = 0; i < len; i++)
310 if (c >=
'A' && c <=
'Z')
333 p =
getword(p, &key, &key_len);
336 p =
getword(p, &val, &val_len);
339 else if (*p++ !=
',')
342 if (*key == 0 || *val == 0 || val_len == 0)
348 res =
set_arg(ctx, key, val, ex);
371 if (err == 0 && args != NULL)
397 text *tmp_data = NULL;
404 if (tmp_data == data)
456 res = (
bytea *) restmp;
545 res = (
bytea *) restmp;
548 if (need_text && got_unicode)
769 char ***p_keys,
char ***p_values)
783 if (nkdims > 1 || nkdims != nvdims)
785 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
786 errmsg(
"wrong number of array subscripts")));
791 TEXTOID, -1,
false,
'i',
792 &key_datums, &key_nulls, &key_count);
795 TEXTOID, -1,
false,
'i',
796 &val_datums, &val_nulls, &val_count);
798 if (key_count != val_count)
800 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
801 errmsg(
"mismatched array dimensions")));
803 keys = (
char **)
palloc(
sizeof(
char *) * key_count);
804 values = (
char **)
palloc(
sizeof(
char *) * val_count);
806 for (i = 0; i < key_count; i++)
813 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
814 errmsg(
"null value not allowed for header key")));
820 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
821 errmsg(
"header key must not contain non-ASCII characters")));
824 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
825 errmsg(
"header key must not contain \": \"")));
828 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
829 errmsg(
"header key must not contain newlines")));
835 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
836 errmsg(
"null value not allowed for header value")));
842 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
843 errmsg(
"header value must not contain non-ASCII characters")));
846 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
847 errmsg(
"header value must not contain newlines")));
884 num_headers, keys, values);
953 elog(
ERROR,
"return type must be a row type");
Datum pgp_key_id_w(PG_FUNCTION_ARGS)
Datum pg_armor(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(pgp_sym_encrypt_bytea)
MBuf * mbuf_create(int len)
static char * downcase_convert(const uint8 *s, int len)
void px_THROW_ERROR(int err)
#define PXE_ARGUMENT_ERROR
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
int pgp_get_cipher_code(const char *name)
int pgp_get_unicode_mode(PGP_Context *ctx)
int pgp_set_s2k_cipher_algo(PGP_Context *ctx, const char *name)
int pgp_set_pubkey(PGP_Context *ctx, MBuf *keypkt, const uint8 *key, int key_len, int pubtype)
Datum pgp_pub_encrypt_text(PG_FUNCTION_ARGS)
Datum pgp_sym_encrypt_bytea(PG_FUNCTION_ARGS)
int pgp_set_s2k_digest_algo(PGP_Context *ctx, const char *name)
int pgp_set_s2k_mode(PGP_Context *ctx, int mode)
#define SRF_IS_FIRSTCALL()
static void clear_and_pfree(text *p)
Datum pgp_pub_decrypt_text(PG_FUNCTION_ARGS)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static text * convert_charset(text *src, int cset_from, int cset_to)
int errcode(int sqlerrcode)
int mbuf_free(MBuf *mbuf)
Datum pg_dearmor(PG_FUNCTION_ARGS)
int pgp_get_keyid(MBuf *pgp_data, char *dst)
int pgp_get_digest_code(const char *name)
unsigned char * pg_do_encoding_conversion(unsigned char *src, int len, int src_encoding, int dest_encoding)
#define SRF_PERCALL_SETUP()
static void fill_expect(struct debug_expect *ex, int text_mode)
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
#define PG_GETARG_TEXT_PP(n)
Datum pgp_pub_decrypt_bytea(PG_FUNCTION_ARGS)
#define SRF_RETURN_NEXT(_funcctx, _result)
int pgp_set_sess_key(PGP_Context *ctx, int use)
static void check_expect(PGP_Context *ctx, struct debug_expect *ex)
#define PG_GETARG_ARRAYTYPE_P(n)
void pfree(void *pointer)
#define IS_HIGHBIT_SET(ch)
static text * convert_from_utf8(text *src)
Datum pgp_pub_encrypt_bytea(PG_FUNCTION_ARGS)
int pgp_set_compress_level(PGP_Context *ctx, int level)
int pgp_armor_decode(const uint8 *src, int len, StringInfo dst)
Datum pgp_sym_encrypt_text(PG_FUNCTION_ARGS)
void pgp_armor_encode(const uint8 *src, unsigned len, StringInfo dst, int num_headers, char **keys, char **values)
Datum pgp_sym_decrypt_text(PG_FUNCTION_ARGS)
AttInMetadata * attinmeta
int pgp_set_symkey(PGP_Context *ctx, const uint8 *key, int len)
void px_set_debug_handler(void(*handler)(const char *))
#define ereport(elevel, rest)
static bool string_is_ascii(const char *str)
int pgp_set_convert_crlf(PGP_Context *ctx, int doit)
int pgp_init(PGP_Context **ctx_p)
void initStringInfo(StringInfo str)
int mbuf_append(MBuf *dst, const uint8 *buf, int len)
#define TextDatumGetCString(d)
int GetDatabaseEncoding(void)
int pgp_set_unicode_mode(PGP_Context *ctx, int mode)
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Datum pgp_armor_headers(PG_FUNCTION_ARGS)
int pgp_decrypt(PGP_Context *ctx, MBuf *msrc, MBuf *mdst)
int pgp_extract_armor_headers(const uint8 *src, unsigned len, int *nheaders, char ***keys, char ***values)
int pgp_set_cipher_algo(PGP_Context *ctx, const char *name)
int pgp_disable_mdc(PGP_Context *ctx, int disable)
#define PG_RETURN_TEXT_P(x)
text * cstring_to_text(const char *s)
int pgp_encrypt(PGP_Context *ctx, MBuf *src, MBuf *dst)
static char * getword(char *p, char **res_p, int *res_len)
static void show_debug(const char *msg)
MemoryContext multi_call_memory_ctx
Datum pgp_sym_decrypt_bytea(PG_FUNCTION_ARGS)
#define PG_GETARG_BYTEA_PP(n)
static int parse_args(PGP_Context *ctx, uint8 *args, int arg_len, struct debug_expect *ex)
#define PG_FREE_IF_COPY(ptr, n)
#define HeapTupleGetDatum(tuple)
static int parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array, char ***p_keys, char ***p_values)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
int pgp_set_s2k_count(PGP_Context *ctx, int count)
static Datum values[MAXATTR]
#define VARSIZE_ANY_EXHDR(PTR)
int errmsg(const char *fmt,...)
MBuf * mbuf_create_from_data(uint8 *data, int len)
static bytea * decrypt_internal(int is_pubenc, int need_text, text *data, text *key, text *keypsw, text *args)
int pgp_set_text_mode(PGP_Context *ctx, int mode)
static MBuf * create_mbuf_from_vardata(text *data)
#define SET_VARSIZE(PTR, len)
static bytea * encrypt_internal(int is_pubenc, int is_text, text *data, text *key, text *args)
static int set_arg(PGP_Context *ctx, char *key, char *val, struct debug_expect *ex)
int pgp_free(PGP_Context *ctx)
static text * convert_to_utf8(text *src)
char * pg_any_to_server(const char *s, int len, int encoding)
void px_memset(void *ptr, int c, size_t len)
int pgp_set_compress_algo(PGP_Context *ctx, int algo)
int mbuf_steal_data(MBuf *mbuf, uint8 **data_p)
#define SRF_RETURN_DONE(_funcctx)
static void init_work(PGP_Context **ctx_p, int is_text, text *args, struct debug_expect *ex)
#define SRF_FIRSTCALL_INIT()