summaryrefslogtreecommitdiff
path: root/sys/man/2
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2021-07-03 20:03:17 +0000
committerOri Bernstein <ori@eigenstate.org>2021-07-03 20:03:17 +0000
commite934530ee4512f033952e4efa80a80058607b741 (patch)
tree2bde95220e1d5e26000286a7f04b93431d8121c8 /sys/man/2
parentc848ca62673689df20e7fef74d1d5180f37fcea6 (diff)
libc: add encode(2) variants for custom alphabets
There are a number of alphabets in common use for base32 and base64 encoding, such as url-safe encodings. This adds support for passing a function to encode into arbitary alphabets.
Diffstat (limited to 'sys/man/2')
-rw-r--r--sys/man/2/encode38
1 files changed, 38 insertions, 0 deletions
diff --git a/sys/man/2/encode b/sys/man/2/encode
index db7944945..3827e7a6e 100644
--- a/sys/man/2/encode
+++ b/sys/man/2/encode
@@ -1,6 +1,7 @@
.TH ENCODE 2
.SH NAME
dec64, enc64, dec32, enc32, dec16, enc16, \
+dec64x, enc64x, dec32x, enc32x, \
dec64chr, enc64chr, dec32chr, enc32chr, dec16chr, enc16chr, \
encodefmt \- encoding byte arrays as strings
.SH SYNOPSIS
@@ -12,15 +13,27 @@ encodefmt \- encoding byte arrays as strings
int dec64(uchar *out, int lim, char *in, int n)
.PP
.B
+int dec64x(uchar *out, int lim, char *in, int n, int (*map)(int))
+.PP
+.B
int enc64(char *out, int lim, uchar *in, int n)
.PP
.B
+int enc64x(char *out, int lim, uchar *in, int n, int (*map)(int))
+.PP
+.B
int dec32(uchar *out, int lim, char *in, int n)
.PP
.B
+int dec32x(uchar *out, int lim, char *in, int n, int (*map)(int))
+.PP
+.B
int enc32(char *out, int lim, uchar *in, int n)
.PP
.B
+int enc32x(char *out, int lim, uchar *in, int n, int (*map)(int))
+.PP
+.B
int dec16(uchar *out, int lim, char *in, int n)
.PP
.B
@@ -83,6 +96,31 @@ and
encode a symbol of the alphabet given a value.
if the value is out of range then zero is returned.
.PP
+The
+.I enc64x
+and
+.I enc32x
+variants are identical to the above, except that they take a
+function mapping from an arbitrary index in the alphabet to
+the encoded character.
+For example, in the following 32-character alphabet,
+.EX
+.I ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
+.EE
+the chr function would map the value
+.I 3
+to the character
+.IR D .
+
+The
+.I dec64x
+and
+.I dec32x
+variants are similar to the above, however the function passed
+maps from a character within the alphabet to the index within
+the alphabet.
+
+.PP
.I Encodefmt
can be used with
.IR fmtinstall (2)