65 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
66 errmsg(
"unrecognized encoding: \"%s\"", namebuf)));
79 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
80 errmsg(
"result of encoding conversion is too large")));
88 elog(
FATAL,
"overflow - encode estimate too small");
113 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
114 errmsg(
"unrecognized encoding: \"%s\"", namebuf)));
127 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
128 errmsg(
"result of decoding conversion is too large")));
136 elog(
FATAL,
"overflow - decode estimate too small");
152"000102030405060708090a0b0c0d0e0f"
153"101112131415161718191a1b1c1d1e1f"
154"202122232425262728292a2b2c2d2e2f"
155"303132333435363738393a3b3c3d3e3f"
156"404142434445464748494a4b4c4d4e4f"
157"505152535455565758595a5b5c5d5e5f"
158"606162636465666768696a6b6c6d6e6f"
159"707172737475767778797a7b7c7d7e7f"
160"808182838485868788898a8b8c8d8e8f"
161"909192939495969798999a9b9c9d9e9f"
162"a0a1a2a3a4a5a6a7a8a9aaabacadaeaf"
163"b0b1b2b3b4b5b6b7b8b9babbbcbdbebf"
164"c0c1c2c3c4c5c6c7c8c9cacbcccdcecf"
165"d0d1d2d3d4d5d6d7d8d9dadbdcdddedf"
166"e0e1e2e3e4e5e6e7e8e9eaebecedeeef"
167"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
170 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
171 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
172 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
173 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
174 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
175 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
176 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
177 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
183 const char *end = src +
len;
187 unsigned char usrc = *((
const unsigned char *) src);
189 memcpy(dst, &
hextbl[2 * usrc], 2);
199 unsigned char c = (
unsigned char) *cp;
230 if (*s ==
' ' || *s ==
'\n' || *s ==
'\t' || *s ==
'\r')
237 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
238 errmsg(
"invalid hexadecimal digit: \"%.*s\"",
243 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
244 errmsg(
"invalid hexadecimal data: odd number of digits")));
247 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
248 errmsg(
"invalid hexadecimal digit: \"%.*s\"",
251 *p++ = (v1 << 4) | v2;
260 return (
uint64) srclen << 1;
266 return (
uint64) srclen >> 1;
274"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
277 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
278 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
279 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
280 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
281 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
282 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
283 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
284 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
302 buf |= (
unsigned char) *s << (pos << 3);
327 *p++ = (pos == 0) ?
_base64[(
buf >> 6) & 0x3f] :
'=';
337 const char *srcend = src +
len,
350 if (
c ==
' ' ||
c ==
'\t' ||
c ==
'\n' ||
c ==
'\r')
364 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
365 errmsg(
"unexpected \"=\" while decoding base64 sequence")));
372 if (
c > 0 &&
c < 127)
376 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
377 errmsg(
"invalid symbol \"%.*s\" found while decoding base64 sequence",
385 *p++ = (
buf >> 16) & 255;
386 if (end == 0 || end > 1)
387 *p++ = (
buf >> 8) & 255;
388 if (end == 0 || end > 2)
397 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
398 errmsg(
"invalid base64 end sequence"),
399 errhint(
"Input data is missing padding, is truncated, or is otherwise corrupted.")));
409 return ((
uint64) srclen + 2) / 3 * 4 + (
uint64) srclen / (76 * 3 / 4);
415 return ((
uint64) srclen * 3) >> 2;
432#define VAL(CH) ((CH) - '0')
433#define DIG(VAL) ((VAL) + '0')
438 const char *end = src + srclen;
444 unsigned char c = (
unsigned char) *src;
450 rp[2] =
DIG((
c >> 3) & 7);
477 const char *end = src + srclen;
485 else if (src + 3 < end &&
486 (src[1] >=
'0' && src[1] <=
'3') &&
487 (src[2] >=
'0' && src[2] <=
'7') &&
488 (src[3] >=
'0' && src[3] <=
'7'))
496 *rp++ =
val +
VAL(src[3]);
499 else if (src + 1 < end &&
512 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
513 errmsg(
"invalid input syntax for type %s",
"bytea")));
525 const char *end = src + srclen;
532 else if (*src ==
'\\')
546 const char *end = src + srclen;
553 else if (src + 3 < end &&
554 (src[1] >=
'0' && src[1] <=
'3') &&
555 (src[2] >=
'0' && src[2] <=
'7') &&
556 (src[3] >=
'0' && src[3] <=
'7'))
563 else if (src + 1 < end &&
577 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
578 errmsg(
"invalid input syntax for type %s",
"bytea")));
618 NULL, NULL, NULL, NULL
#define TextDatumGetCString(d)
#define IS_HIGHBIT_SET(ch)
static void PGresult * res
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
static uint64 pg_base64_decode(const char *src, size_t len, char *dst)
static const struct @22 enclist[]
static bool get_hex(const char *cp, char *out)
static uint64 hex_dec_len(const char *src, size_t srclen)
static const struct pg_encoding * pg_find_encoding(const char *name)
static uint64 pg_base64_encode(const char *src, size_t len, char *dst)
static uint64 esc_encode(const char *src, size_t srclen, char *dst)
static uint64 hex_enc_len(const char *src, size_t srclen)
Datum binary_decode(PG_FUNCTION_ARGS)
static const char hextbl[512]
uint64 hex_decode_safe(const char *src, size_t len, char *dst, Node *escontext)
uint64 hex_encode(const char *src, size_t len, char *dst)
static uint64 esc_enc_len(const char *src, size_t srclen)
static uint64 pg_base64_enc_len(const char *src, size_t srclen)
static const char _base64[]
static uint64 esc_decode(const char *src, size_t srclen, char *dst)
static uint64 esc_dec_len(const char *src, size_t srclen)
Datum binary_encode(PG_FUNCTION_ARGS)
uint64 hex_decode(const char *src, size_t len, char *dst)
static const int8 b64lookup[128]
static const int8 hexlookup[128]
static uint64 pg_base64_dec_len(const char *src, size_t srclen)
#define PG_GETARG_BYTEA_PP(n)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_DATUM(n)
#define PG_RETURN_TEXT_P(x)
int pg_mblen(const char *mbstr)
int pg_strcasecmp(const char *s1, const char *s2)
uint64(* encode_len)(const char *data, size_t dlen)
uint64(* decode_len)(const char *data, size_t dlen)
uint64(* decode)(const char *data, size_t dlen, char *res)
uint64(* encode)(const char *data, size_t dlen, char *res)
#define SET_VARSIZE(PTR, len)
#define VARSIZE_ANY_EXHDR(PTR)