4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
17 * Cjdns style base32 encoding
20 /** Returned by ws_base32_encode() if the input is not valid base32. */
21 #define Base32_BAD_INPUT -1
22 /** Returned by ws_base32_encode() if the output buffer is too small. */
23 #define Base32_TOO_BIG -2
25 int ws_base32_decode(uint8_t* output
, const uint32_t outputLength
,
26 const uint8_t* in
, const uint32_t inputLength
)
28 uint32_t outIndex
= 0;
32 static const uint8_t* kChars
= (uint8_t*) "0123456789bcdfghjklmnpqrstuvwxyz";
33 while (inIndex
< inputLength
) {
34 work
|= ((unsigned) in
[inIndex
++]) << bits
;
37 if (outIndex
>= outputLength
) {
38 return Base32_TOO_BIG
;
40 output
[outIndex
++] = kChars
[work
& 31];
46 if (outIndex
>= outputLength
) {
47 return Base32_TOO_BIG
;
49 output
[outIndex
++] = kChars
[work
& 31];
51 if (outIndex
< outputLength
) {
52 output
[outIndex
] = '\0';
58 * Editor modelines - https://www.wireshark.org/tools/modelines.html
66 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
67 * :indentSize=8:tabSize=8:noTabs=false: