72 unsigned char *csrc = (
unsigned char *)
VARDATA_ANY(src);
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)
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'))
297 if (
c >=
'A' &&
c <=
'Z')
326 else if (*p++ !=
',')
329 if (*
key == 0 || *
val == 0 || val_len == 0)
384 text *tmp_data = NULL;
391 if (tmp_data ==
data)
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")));
780 if (key_count != val_count)
782 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
783 errmsg(
"mismatched array dimensions")));
785 keys = (
char **)
palloc(
sizeof(
char *) * key_count);
788 for (
i = 0;
i < key_count;
i++)
795 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
796 errmsg(
"null value not allowed for header key")));
802 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
803 errmsg(
"header key must not contain non-ASCII characters")));
806 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
807 errmsg(
"header key must not contain \": \"")));
810 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
811 errmsg(
"header key must not contain newlines")));
817 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
818 errmsg(
"null value not allowed for header value")));
824 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
825 errmsg(
"header value must not contain non-ASCII characters")));
828 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
829 errmsg(
"header value must not contain newlines")));
866 num_headers, keys,
values);
935 elog(
ERROR,
"return type must be a row type");
#define PG_GETARG_ARRAYTYPE_P(n)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
static Datum values[MAXATTR]
#define TextDatumGetCString(d)
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void err(int eval, const char *fmt,...)
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_GETARG_BYTEA_PP(n)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_TEXT_P(x)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define SRF_RETURN_DONE(_funcctx)
if(TABLE==NULL||TABLE_index==NULL)
int mbuf_free(MBuf *mbuf)
int mbuf_append(MBuf *dst, const uint8 *buf, int len)
MBuf * mbuf_create_from_data(uint8 *data, int len)
int mbuf_steal_data(MBuf *mbuf, uint8 **data_p)
MBuf * mbuf_create(int len)
int GetDatabaseEncoding(void)
char * pg_any_to_server(const char *s, int len, int encoding)
unsigned char * pg_do_encoding_conversion(unsigned char *src, int len, int src_encoding, int dest_encoding)
void pfree(void *pointer)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
int pgp_extract_armor_headers(const uint8 *src, unsigned len, int *nheaders, char ***keys, char ***values)
int pgp_armor_decode(const uint8 *src, int len, StringInfo dst)
void pgp_armor_encode(const uint8 *src, unsigned len, StringInfo dst, int num_headers, char **keys, char **values)
int pgp_decrypt(PGP_Context *ctx, MBuf *msrc, MBuf *mdst)
int pgp_encrypt(PGP_Context *ctx, MBuf *src, MBuf *dst)
int pgp_get_keyid(MBuf *pgp_data, char *dst)
static MBuf * create_mbuf_from_vardata(text *data)
static text * convert_to_utf8(text *src)
static text * convert_charset(text *src, int cset_from, int cset_to)
static void fill_expect(struct debug_expect *ex, int text_mode)
Datum pgp_pub_decrypt_bytea(PG_FUNCTION_ARGS)
static char * getword(char *p, char **res_p, int *res_len)
Datum pgp_sym_decrypt_text(PG_FUNCTION_ARGS)
Datum pgp_sym_encrypt_bytea(PG_FUNCTION_ARGS)
Datum pg_armor(PG_FUNCTION_ARGS)
Datum pg_dearmor(PG_FUNCTION_ARGS)
Datum pgp_pub_encrypt_text(PG_FUNCTION_ARGS)
static text * convert_from_utf8(text *src)
static void init_work(PGP_Context **ctx_p, int is_text, text *args, struct debug_expect *ex)
static void check_expect(PGP_Context *ctx, struct debug_expect *ex)
Datum pgp_key_id_w(PG_FUNCTION_ARGS)
static bytea * encrypt_internal(int is_pubenc, int is_text, text *data, text *key, text *args)
Datum pgp_sym_decrypt_bytea(PG_FUNCTION_ARGS)
static void show_debug(const char *msg)
static int parse_args(PGP_Context *ctx, uint8 *args, int arg_len, struct debug_expect *ex)
Datum pgp_sym_encrypt_text(PG_FUNCTION_ARGS)
Datum pgp_armor_headers(PG_FUNCTION_ARGS)
Datum pgp_pub_decrypt_text(PG_FUNCTION_ARGS)
static int parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array, char ***p_keys, char ***p_values)
static bytea * decrypt_internal(int is_pubenc, int need_text, text *data, text *key, text *keypsw, text *args)
PG_FUNCTION_INFO_V1(pgp_sym_encrypt_bytea)
static char * downcase_convert(const uint8 *s, int len)
static int set_arg(PGP_Context *ctx, char *key, char *val, struct debug_expect *ex)
static void clear_and_pfree(text *p)
Datum pgp_pub_encrypt_bytea(PG_FUNCTION_ARGS)
int pgp_set_pubkey(PGP_Context *ctx, MBuf *keypkt, const uint8 *key, int key_len, int pubtype)
int pgp_disable_mdc(PGP_Context *ctx, int disable)
int pgp_get_cipher_code(const char *name)
int pgp_init(PGP_Context **ctx_p)
int pgp_set_text_mode(PGP_Context *ctx, int mode)
int pgp_set_s2k_digest_algo(PGP_Context *ctx, const char *name)
int pgp_set_s2k_mode(PGP_Context *ctx, int mode)
int pgp_get_digest_code(const char *name)
int pgp_set_symkey(PGP_Context *ctx, const uint8 *key, int len)
int pgp_set_s2k_cipher_algo(PGP_Context *ctx, const char *name)
int pgp_set_compress_algo(PGP_Context *ctx, int algo)
int pgp_get_unicode_mode(PGP_Context *ctx)
int pgp_set_cipher_algo(PGP_Context *ctx, const char *name)
int pgp_set_convert_crlf(PGP_Context *ctx, int doit)
int pgp_set_unicode_mode(PGP_Context *ctx, int mode)
int pgp_free(PGP_Context *ctx)
int pgp_set_s2k_count(PGP_Context *ctx, int count)
int pgp_set_sess_key(PGP_Context *ctx, int use)
int pgp_set_compress_level(PGP_Context *ctx, int level)
void px_THROW_ERROR(int err)
void px_set_debug_handler(void(*handler)(const char *))
void px_memset(void *ptr, int c, size_t len)
#define PXE_ARGUMENT_ERROR
bool pg_is_ascii(const char *str)
void initStringInfo(StringInfo str)
AttInMetadata * attinmeta
MemoryContext multi_call_memory_ctx
#define SET_VARSIZE(PTR, len)
#define VARSIZE_ANY_EXHDR(PTR)
text * cstring_to_text(const char *s)