summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorPierre Téchoueyres <pierre.techoueyres@free.fr>2019-05-21 23:00:13 +0200
committerEli Zaretskii <eliz@gnu.org>2019-06-08 10:49:35 +0300
commit7541b06872ba134bfaa51b1aca7755a617fff807 (patch)
tree0190a36f96e0b37f1ea7f97e6b89975a155436af /doc
parentfaf10bd8eb3272880b774fe220fa9916ed1f00c0 (diff)
downloademacs-7541b06872ba134bfaa51b1aca7755a617fff807.tar.gz
Add support for base64url variant of base-64 encoding/decoding
Implement the RFC4648 variant of base64 encoding used by URLs. * doc/lispref/text.texi (base64url-encode-region, base64url-encode-string): Document new functions. (base64-decode-region, base64-decode-string): Document new optional parameter 'base64url' used to use url variant when decoding data. * src/fns.c (base64url-encode-region, base64url-encode-region): New functions to manage url variant. (base64-decode-region, base64-decode-string): Add optional parameter to indicate use of url-variant. (base64_encode_region_1, base64_encode_string_1): Internal functions with extracted code from 'base64_encode_region' and 'base64_encode_string' and optional parameters to manage padding and url variant. (base64-encode-region, base64-encode-string) : Use base64_encode_region_1 and base64_encode_string_1. (base64-encode-1): Add parameters to manage padding and url variant. (base64-decode-1): Add parameter to manage url variant. * test/src/fns-tests.el (fns-tests--with-region): New helper macro to test region variant of base64 encode / decode functions. (fns-tests--string-repeat): Helper function used in base64 tests. (fns-tests-base64-encode-region, fns-tests-base64-encode-string): Tests for standard base64 function. (fns-test-base64url-encode-region, fns-test-base64url-encode-string): Tests for url variant. (fns-tests-base64-decode-string): Tests for decoding part.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/text.texi42
1 files changed, 39 insertions, 3 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 278bc3c2680..3e0cf4c06f6 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -4541,7 +4541,7 @@ Internet informational document describing a standard. RFCs are
usually written by technical experts acting on their own initiative,
and are traditionally written in a pragmatic, experience-driven
manner.
-}2045. This section describes the functions for
+}2045 and also in RFC4648. This section describes the functions for
converting to and from this code.
@deffn Command base64-encode-region beg end &optional no-line-break
@@ -4558,6 +4558,22 @@ text, to avoid overlong lines. However, if the optional argument
the output is just one long line.
@end deffn
+@deffn Command base64url-encode-region beg end &optional no-pad
+This function converts the region from @var{beg} to @var{end} into base
+64 code. It returns the length of the encoded text. An error is
+signaled if a character in the region is multibyte, i.e., in a
+multibyte buffer the region must contain only characters from the
+charsets @code{ascii}, @code{eight-bit-control} and
+@code{eight-bit-graphic}.
+
+Contrary to the function @code{base64-encode-region}, this function
+doesnt inserts newline characters into the encoded text, so the output
+is just one long line.
+
+If the optional argument @var{no-pad} is non-@code{nil} then padding
+(@code{=}) isn't generated.
+@end deffn
+
@defun base64-encode-string string &optional no-line-break
This function converts the string @var{string} into base 64 code. It
returns a string containing the encoded text. As for
@@ -4570,20 +4586,40 @@ text, to avoid overlong lines. However, if the optional argument
the result string is just one long line.
@end defun
-@deffn Command base64-decode-region beg end
+@defun base64url-encode-string string &optional no-pad
+This function converts the string @var{string} into base 64 url code
+(see RFC4648). It returns a string containing the encoded text. As
+for @code{base64url-encode-region}, an error is signaled if a
+character in the string is multibyte.
+
+Contrary to @code{base64-encode-string}, this function doesnt inserts
+newline characters into the encoded text, so the result string is just
+one long line.
+
+If the optional argument @var{no-pad} is non-@code{nil} then padding
+(@code{=}) isn't generated.
+@end defun
+
+@deffn Command base64-decode-region beg end &optional base64url
This function converts the region from @var{beg} to @var{end} from base
64 code into the corresponding decoded text. It returns the length of
the decoded text.
The decoding functions ignore newline characters in the encoded text.
+
+If optional argument @var{base64url} is is non-@code{nil} then padding
+become optionnal and url variant is used (see RFC4648).
@end deffn
-@defun base64-decode-string string
+@defun base64-decode-string string &optional base64url
This function converts the string @var{string} from base 64 code into
the corresponding decoded text. It returns a unibyte string containing the
decoded text.
The decoding functions ignore newline characters in the encoded text.
+
+If optional argument @var{base64url} is is non-@code{nil} then padding
+become optionnal and url variant is used (see RFC4648).
@end defun
@node Checksum/Hash