| | @@ -1260,3 +1260,42 @@ |
| 1260 | 1260 | descriptor was put back without it. |
| 1261 | 1261 | |
| 1262 | 1262 | Met in rnet, after a review of its STARTTLS (2026-10-22). |
| 1263 | + |
| 1264 | +## Base64 in `Str` |
| 1265 | + |
| 1266 | +Library growth that breaks no program: three procedures in `Str.raz`, |
| 1267 | +beside `hexVal` and `toHex`, of base64 as RFC 4648 (4) has it: its |
| 1268 | +alphabet, `A` to `Z`, `a` to `z`, `0` to `9`, `+` and `/`, and `=` to |
| 1269 | +pad the last group to four. |
| 1270 | + |
| 1271 | + (* The bytes base64 makes of n bytes: 4 for each 3, or part of 3. *) |
| 1272 | + proc base64Size*(n: INT): INT; |
| 1273 | + |
| 1274 | + (* s in base64 into out, which holds base64Size(LEN(s)) bytes at |
| 1275 | + least: the bytes written. *) |
| 1276 | + proc base64*(s, out: []U8): INT; |
| 1277 | + |
| 1278 | + (* s, base64, decoded into out, which holds LEN(s) div 4 * 3 bytes at |
| 1279 | + least: the bytes written; false if s isn't base64, its length |
| 1280 | + not a multiple of 4, a byte outside the alphabet, or padding |
| 1281 | + anywhere but at the end. *) |
| 1282 | + proc unbase64*(s, out: []U8): (INT, BOOL); |
| 1283 | + |
| 1284 | +The caller gives the room, as `Fmt` and the rest of `Str` have it, so |
| 1285 | +nothing is allocated. Decoding is strict: line breaks and missing |
| 1286 | +padding, which MIME and some programs allow, are the caller's to take |
| 1287 | +out or put back first. |
| 1288 | + |
| 1289 | +Programs each carry their own copy meanwhile: rnet's `Ws`, for the |
| 1290 | +WebSocket handshake's accept key, and `Smtp`, for AUTH PLAIN, the same |
| 1291 | +twenty lines twice in one library; flojo, for the terminal's clipboard |
| 1292 | +(OSC 52), its own fifteen. HTTP's Basic authentication and data URLs |
| 1293 | +want it as well, and want decoding too, which none of those copies |
| 1294 | +does. |
| 1295 | + |
| 1296 | +Left out: base64url (RFC 4648, 5), for JWTs, which is the same with |
| 1297 | +`-` and `_` and usually no padding; a flag, or a second pair of |
| 1298 | +procedures, if a program needs it. |
| 1299 | + |
| 1300 | +Met in rnet, whose `Smtp` copied `Ws`'s (2026-10-22); listed in |
| 1301 | +`~/r/RAZ-GAPS.md` before that, from rnet and flojo. |