72 unsigned char *csrc = (
unsigned char *)
VARDATA_ANY(src);
137 #define EX_MSG(arg) \ 138 ereport(NOTICE, (errmsg( \ 139 "pgp_decrypt: unexpected %s: expected %d got %d", \ 140 CppAsString(arg), ex->arg, ctx->arg))) 142 #define EX_CHECK(arg) do { \ 143 if (ex->arg >= 0 && ex->arg != ctx->arg) EX_MSG(arg); \ 173 if (strcmp(key,
"cipher-algo") == 0)
175 else if (strcmp(key,
"disable-mdc") == 0)
177 else if (strcmp(key,
"sess-key") == 0)
179 else if (strcmp(key,
"s2k-mode") == 0)
181 else if (strcmp(key,
"s2k-count") == 0)
183 else if (strcmp(key,
"s2k-digest-algo") == 0)
185 else if (strcmp(key,
"s2k-cipher-algo") == 0)
187 else if (strcmp(key,
"compress-algo") == 0)
189 else if (strcmp(key,
"compress-level") == 0)
191 else if (strcmp(key,
"convert-crlf") == 0)
193 else if (strcmp(key,
"unicode-mode") == 0)
200 else if (ex != NULL && strcmp(key,
"debug") == 0)
201 ex->
debug = atoi(val);
202 else if (ex != NULL && strcmp(key,
"expect-cipher-algo") == 0)
207 else if (ex != NULL && strcmp(key,
"expect-disable-mdc") == 0)
212 else if (ex != NULL && strcmp(key,
"expect-sess-key") == 0)
217 else if (ex != NULL && strcmp(key,
"expect-s2k-mode") == 0)
222 else if (ex != NULL && strcmp(key,
"expect-s2k-count") == 0)
227 else if (ex != NULL && strcmp(key,
"expect-s2k-digest-algo") == 0)
232 else if (ex != NULL && strcmp(key,
"expect-s2k-cipher-algo") == 0)
237 else if (ex != NULL && strcmp(key,
"expect-compress-algo") == 0)
242 else if (ex != NULL && strcmp(key,
"expect-unicode-mode") == 0)
262 while (*p && (*p ==
' ' || *p ==
'\t' || *p ==
'\n'))
267 if (*p ==
'=' || *p ==
',')
270 while (*p && !(*p ==
' ' || *p ==
'\t' || *p ==
'\n' 271 || *p ==
'=' || *p ==
','))
275 *res_len = p - *res_p;
278 while (*p && (*p ==
' ' || *p ==
'\t' || *p ==
'\n'))
292 char *res =
palloc(len + 1);
294 for (i = 0; i < len; i++)
297 if (c >=
'A' && c <=
'Z')
320 p =
getword(p, &key, &key_len);
323 p =
getword(p, &val, &val_len);
326 else if (*p++ !=
',')
329 if (*key == 0 || *val == 0 || val_len == 0)
335 res =
set_arg(ctx, key, val, ex);
358 if (err == 0 && args != NULL)
384 text *tmp_data = NULL;
391 if (tmp_data == data)
443 res = (
bytea *) restmp;
532 res = (
bytea *) restmp;
535 if (need_text && got_unicode)
756 char ***p_keys,
char ***p_values)
770 if (nkdims > 1 || nkdims != nvdims)
772 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
773 errmsg(
"wrong number of array subscripts")));
778 TEXTOID, -1,
false, TYPALIGN_INT,
779 &key_datums, &key_nulls, &key_count);
782 TEXTOID, -1,
false, TYPALIGN_INT,
783 &val_datums, &val_nulls, &val_count);
785 if (key_count != val_count)
787 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
788 errmsg(
"mismatched array dimensions")));
790 keys = (
char **)
palloc(
sizeof(
char *) * key_count);
791 values = (
char **)
palloc(
sizeof(
char *) * val_count);
793 for (i = 0; i < key_count; i++)
800 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
801 errmsg(
"null value not allowed for header key")));
807 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
808 errmsg(
"header key must not contain non-ASCII characters")));
811 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
812 errmsg(
"header key must not contain \": \"")));
815 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
816 errmsg(
"header key must not contain newlines")));
822 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
823 errmsg(
"null value not allowed for header value")));
829 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
830 errmsg(
"header value must not contain non-ASCII characters")));
833 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
834 errmsg(
"header value must not contain newlines")));
871 num_headers, keys, values);
940 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()
bool pg_is_ascii(const char *str)
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)
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 *))
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)
#define ereport(elevel,...)
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()