Re: encode/decode support for base64url

From: Florents Tselai <florents(dot)tselai(at)gmail(dot)com>
To: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
Cc: Aleksander Alekseev <aleksander(at)tigerdata(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Cary Huang <cary(dot)huang(at)highgo(dot)ca>, Daniel Gustafsson <daniel(at)yesql(dot)se>, Przemysław Sztoch <przemyslaw(at)sztoch(dot)pl>
Subject: Re: encode/decode support for base64url
Date: 2025-07-11 08:26:50
Message-ID: CA+v5N41Qs5Zpe6G+-VtiK=gLfHgzfgJij0tXHWuMXLfyHjDOYQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jul 10, 2025 at 11:55 PM David E. Wheeler <david(at)justatheory(dot)com>
wrote:

> On Jul 10, 2025, at 16:38, Florents Tselai <florents(dot)tselai(at)gmail(dot)com>
> wrote:
>
> > Why isn’t this sufficient?
> >
> > static uint64
> > pg_base64_encode_internal(const char *src, size_t len, char *dst, bool
> url)
> > {
> > const char *alphabet = url ? _base64url : _base64;
>
> Ah, it is. I hadn’t got that far. I was tripped up to see this in your
> patch:
>
> ```patch
> +static uint64
> +pg_base64url_encode(const char *src, size_t len, char *dst)
> +{
> + uint64 encoded_len;
> + if (len == 0)
> + return 0;
> +
> + encoded_len = pg_base64_encode(src, len, dst);
> +
> + /* Convert Base64 to Base64URL */
> + for (uint64 i = 0; i < encoded_len; i++) {
> + if (dst[i] == '+')
> + dst[i] = '-';
> + else if (dst[i] == '/')
> + dst[i] = '_';
> + }
> +
> + /* Trim '=' padding */
> + while (encoded_len > 0 && dst[encoded_len - 1] == '=')
> + encoded_len--;
> +
> + return encoded_len;
> +}
> ```
>
> I didn’t realize it was a set of patches for stuff you did and then later
> undid. Could you flatten the patch into just what’s changed at the end?
>

Attached

Attachment Content-Type Size
v4-0001-Add-base64url.patch application/octet-stream 13.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Yura Sokolov 2025-07-11 08:35:44 Re: Optimize shared LWLock acquisition for high-core-count systems
Previous Message Amit Langote 2025-07-11 08:16:43 track needed attributes in plan nodes for executor use