From ff36d718a997d24db9ac0e49042a99d5f5fad7a2 Mon Sep 17 00:00:00 2001
From: Kaz Kyheku <kaz@kylheku.com>
Date: Tue, 17 Mar 2020 22:25:39 -0700
Subject: Support base64url encoding.

* filter.c (tobase64url_k, frombase64url_k): New keyword
symbols variables.
(base64_stream_enc_impl): New static function, derived from
base64_stream_enc.
(base64_stream_enc): Now a wrapper for base64_stream_enc_impl.
(base64url_stream_enc, base64url_encode): New functions.
(base64_stream_dec_impl): New static function, derived from
base64_stream_dec.
(base64-stream_dec): Now a wrapper for base64_stream_dec_impl.
(get_base64_url_char, b64url_code): New static functions.
(base64url_stream_dec, base64_url_decode,
base64url_decode_buf): New functions.
(filter_init): Intern new keyword symbols, initializing the
corresponding variables, register new :frombase64url
and :tobase64url filters and intrinsic functions
base64url-stream-enc, base64url-stream-dec, base64url-encode,
base64url-decode and base64url-decode-buf.

* filter.h (base64url_stream_enc, base64url_stream_dec,
base64url_encode, base64url_decode, base64url_decode_buf):
Declared.

* txr.1: Documented.
---
 txr.1 | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 84 insertions(+), 2 deletions(-)

(limited to 'txr.1')

diff --git a/txr.1 b/txr.1
index 39f555b3..9dd959e8 100644
--- a/txr.1
+++ b/txr.1
@@ -9454,10 +9454,27 @@ reserved set, encodes to
 .codn %2B .
 
 .coIP :frombase64
-Decode from the Base64 encoding described in RFC 4648.
+Decode from the Base 64 encoding described in RFC 4648, section 5.
 
 .coIP :tobase64
-Encodes to the RFC 4648 Base64 encoding.
+Encode to the Base 64 encoding described in RFC 4648, section 5.
+
+.coIP :frombase64url
+Decode from the Base64 encoding described in RFC 4648, section 6.
+This uses the URL and filename safe alphabet, in which the
+.code +
+(plus) and
+.code /
+(slash) characters used in regular Base 64 are respectively replaced with
+.code -
+(minus) and
+.code _
+(underscore).
+
+.coIP :tobase64url
+Encode to the Base 64 encoding described in RFC 4648, section 6.  See
+.code :frombase64url
+above.
 
 .coIP :tonumber
 Converts strings to numbers. Strings that contain a period,
@@ -62902,6 +62919,7 @@ function converts the UTF-8 representation of
 or the contents of
 .metn buf ,
 to Base64 and returns that representation as a string.
+The Base64 encoding is described in RFC 4648, section 5.
 
 The second argument must either be a character string, or
 a buffer object.
@@ -62971,6 +62989,7 @@ The
 and
 .code base64-stream-dec
 perform, respectively, bulk Base64 encoding and decoding between streams.
+This format is described in RFC 4648, section 5.
 
 The
 .meta in
@@ -63040,6 +63059,69 @@ the
 .code base64-stream-dec
 function returns the number of bytes decoded.
 
+.coNP Functions @, base64url-encode @ base64url-decode and @ base64url-decode-buf
+.synb
+.mets (base64url-encode >> [ string | << buf ] <> [ column-width ])
+.mets (base64url-decode < string)
+.mets (base64url-decode-buf < string)
+.syne
+.desc
+The
+.codn base64url-encode ,
+.code base64url-decode
+and
+.code base64url-decode-buf
+functions conform, in nearly every respect, to the descriptions of,
+respectively,
+.codn base64-encode ,
+.code base64-decode
+and
+.codn base64-decode-buf .
+The difference is that these functions use the encoding described in
+section 6 of RFC 4648, rather than section 5. This means that, in the
+encoding alphabet, instead of the symbols
+.code +
+(plus)
+and
+.code /
+(slash)
+the symbols
+.code -
+(minus)
+and
+.code _
+(underline) are used.
+
+.coNP Functions @ base64url-stream-enc and @ base64url-stream-dec
+.synb
+.mets (base64url-stream-enc < out < in >> [ nbytes <> [ column-width ]])
+.mets (base64url-stream-dec < out << in )
+.syne
+.desc
+The
+.code base64url-stream-enc
+and
+.code base64url-stream-dec
+functions conform, in nearly every respect, to the descriptions of,
+respectively,
+.code base64-stream-enc
+and
+.codn base64-stream-dec .
+The difference is that these functions use the encoding described in
+section 6 of RFC 4648, rather than section 5. This means that, in the
+encoding alphabet, instead of the symbols
+.code +
+(plus)
+and
+.code /
+(slash)
+the symbols
+.code -
+(minus)
+and
+.code _
+(underline) are used.
+
 .SS* Filter Module
 The filter module provides a trie (pronounced "try") data structure,
 which is suitable for representing dictionaries for efficient filtering.
-- 
cgit v1.2.3