Add standard Base64 encode/decode alongside b64url #35

Closed
opened 2026-07-18 21:08:48 +02:00 by michael · 1 comment
Owner

Goal

Add standard Base64 encode/decode (RFC 4648) to daw-lua-common,
alongside the existing b64url_encode/b64url_decode.

Context

base64.lua currently only implements Base64url (for JWT). It shells
out to openssl base64 via a temp file written with io.open /
io.popen.

daw-modul-smtp needs standard Base64 (with +, /, = padding) for
SMTP AUTH LOGIN and MIME attachment encoding (RFC 2045 / RFC 5321).
Two reasons it currently uses its own in-module implementation instead
of daw.common.base64:

  • Base64url is not byte-compatible with standard Base64 (different
    alphabet, no padding) -- using it for SMTP would produce invalid
    output.
  • The temp-file/openssl-pipe approach means sensitive data (SMTP
    credentials encoded for AUTH LOGIN) briefly touches disk. Fine for
    JWT payloads, not desirable for passwords.

Acceptance Criteria

  • M.b64_encode(s) / M.b64_decode(s) added to base64.lua,
    standard alphabet + padding, in-memory (no temp file, no
    io.popen)
  • Works under Lua 5.1 and 5.4
  • Existing b64url_encode/b64url_decode unchanged
  • Tested with daw-modul-smtp's use cases (short strings for AUTH,
    binary attachment content)

Notes

Once available, daw-modul-smtp will drop its own encode.lua in
favor of daw.common.base64.b64_encode/b64_decode.

## Goal Add standard Base64 encode/decode (RFC 4648) to `daw-lua-common`, alongside the existing `b64url_encode`/`b64url_decode`. ## Context `base64.lua` currently only implements Base64url (for JWT). It shells out to `openssl base64` via a temp file written with `io.open` / `io.popen`. `daw-modul-smtp` needs standard Base64 (with `+`, `/`, `=` padding) for SMTP AUTH LOGIN and MIME attachment encoding (RFC 2045 / RFC 5321). Two reasons it currently uses its own in-module implementation instead of `daw.common.base64`: - Base64url is not byte-compatible with standard Base64 (different alphabet, no padding) -- using it for SMTP would produce invalid output. - The temp-file/`openssl`-pipe approach means sensitive data (SMTP credentials encoded for AUTH LOGIN) briefly touches disk. Fine for JWT payloads, not desirable for passwords. ## Acceptance Criteria - [ ] `M.b64_encode(s)` / `M.b64_decode(s)` added to `base64.lua`, standard alphabet + padding, in-memory (no temp file, no `io.popen`) - [ ] Works under Lua 5.1 and 5.4 - [ ] Existing `b64url_encode`/`b64url_decode` unchanged - [ ] Tested with `daw-modul-smtp`'s use cases (short strings for AUTH, binary attachment content) ## Notes Once available, `daw-modul-smtp` will drop its own `encode.lua` in favor of `daw.common.base64.b64_encode`/`b64_decode`.
Author
Owner

b64_encode/b64_decode added to base64.lua, RFC 4648, pure Lua (arithmetic only, no bit ops -- identical behavior on 5.1 and 5.4). Covered in test_base64.lua.

b64_encode/b64_decode added to base64.lua, RFC 4648, pure Lua (arithmetic only, no bit ops -- identical behavior on 5.1 and 5.4). Covered in test_base64.lua.
michael 2026-07-19 17:55:03 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-lua-common#35
No description provided.