Re: encode/decode support for base64url

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: Florents Tselai <florents(dot)tselai(at)gmail(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-12 19:40:16
Message-ID: 5C6EBFD1-A9BC-4325-A48E-6F7F7F994150@justatheory.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Jul 11, 2025, at 04:26, Florents Tselai <florents(dot)tselai(at)gmail(dot)com> wrote:

> Attached

Thank you! This looks great. The attached revision makes a a couple of minor changes:

* Change the line wrap of the docs to be more like the rest of func.sgml
* Remove an unnecessary nested if statement
* Removed `==` from one of the test comments
* Ran pgindent to create the attached patch

A few other brief comments, entirely stylistic:

* I kind of expected pg_base64url_encode to appear immediate after pg_base64_encode. In other words, to see the two uses of pg_base64_encode_internal adjacent to each other. I think that’s more typical of the project standard. Same for the functions that call pg_base64_decode_internal.

* There are a few places where variable definition has been changed without changing the meaning, for example:

- const char *srcend = src + len,
- *s = src;
+ const char *srcend = src + len;
+ const char *s = src;

Even if this is desirable, it might make sense to defer pure formatting changes to a separate patch.

* You define return variables in functions like pg_base64url_enc_len rather than just returning the outcome of an expression. The latter is what I see in pg_base64_enc_len, so I think would be more consistent. Io other words:

```patch
--- a/src/backend/utils/adt/encode.c
+++ b/src/backend/utils/adt/encode.c
@@ -470,8 +470,6 @@ pg_base64_dec_len(const char *src, size_t srclen)
static uint64
pg_base64url_enc_len(const char *src, size_t srclen)
{
- uint64 result;
-
/*
* Base64 encoding converts 3 bytes into 4 characters Formula: ceil(srclen
* / 3) * 4
@@ -479,10 +477,8 @@ pg_base64url_enc_len(const char *src, size_t srclen)
* Unlike standard base64, base64url doesn't use padding characters when
* the input length is not divisible by 3
*/
- result = (srclen + 2) / 3 * 4; /* ceiling division by 3, then multiply by
+ return (srclen + 2) / 3 * 4; /* ceiling division by 3, then multiply by
* 4 */
-
- return result;
}

static uint64
```

I suspect these are the sorts of things a committer would tweak/adjust before committing, just thinking about getting ahead of that. I think it’s ready.

Best,

David

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joel Jacobson 2025-07-12 22:35:21 Optimize LISTEN/NOTIFY
Previous Message Daniel Gustafsson 2025-07-12 19:39:30 Re: Changing the state of data checksums in a running cluster